mat_de_b
09-04-2007, 08:34 PM
Mats PowerCutter Tutorial
This is an SRL 4 and Scar Divi 3.11 Tutorial so make sure you have both of them before starting
1. First Things First
With the tinyiest bit of prior knowledge everyone should know
// "//" starts a comment and everything after that wont be compiled
program PowerCutter; // The program name... Can't contain spaces
{.include srl/srl.scar} // This line includes SRL (Very useful :D)
const // This declares a constanst value
TreeColor = 2706759; // This value can't change all script
var // This declares a changing value
x,y:integer; // These are number values that can change DidItWork:boolean; // This is a variable boolean of True or False
TheWord:string; // This is a string of letters that can change
procedure DoThatStuff; // This is your first procedure Anything inbetween
begin // the begin and end is part of this procedure
end; // and can be called by typing DoThatStuff;
begin // This begins the main loop
SetupSRL; // This is needed at the start of SRL scripts
DoThatStuff; // This calls the procedure DoThatStuff;
end. // This ends the mainloop and scipt
2. Our First Procedure
We are now going to write a procedure to Cut a tree.
procedure Cut;
begin
if(FindObj(x,y,'ree',TreeColor,15))then
begin
Mouse(x,y,5,5,True);
Writeln('Cutting Tree');
wait(1000+random(1000));
end;
end;
That probably looks confusing so ill go through it bit by bit
1. An if()then statement
Everything after the if and before the then should be put in brackets ( LIKE HERE ) this is what the if is testing after the if everything you want to be done if the if is true must be put inside a begin and end
Example:
if(TheWorldIsRound)then
begin
KeepSailing;
TellTheWorld;
end;
2. FindObj(XCoord,YCoord,UpText,Color,Tolerance)
This function is used to find an object on the main RS screen.
The XCoord and YCoord should be stored to variables (normally X and Y), this is the location of the object thats found
The UpText is the text that is found in the top left corner when one mouses over an object. This value is a string such as 'ree' of Tree (strings must be in quotation marks). As a convention the capital letter is left off so for Mine it would be 'ine'...
The Color is basically the color you want it to find on the screen, use the color picker on Scar to find it
The Tolerance this is how leanient scar is with finding the color, for a tree we need to keep it quite low as there are lots of colors about, so 15 is what we will use... The Tolerance Finder by Abyssal in SRL 4 is very useful for this.
3. Mouse or MMouse
The function Mouse is "Mouse(XCoord,YCoord,XRandom,YRandom,LeftClick)"
The function MMouse is "MMouse(XCoord,YCoord,XRandom,YRandom)"
Move mouse (MMouse) will move the mouse to the position stated by XCoord and YCoord, with a random of Xrandom and YRandom (Randoms are needed to decrease detectability).
Mouse will do the same as MMouse but will either left click (True) or right click (False) depending on what the LeftClick boolean is set to
Example: Mouse(100,100,10,10,True);
4. Writeln(String)
Writeln will print whatever you write as an output to debug box at the bottom of scar, because it is a string it must be in 'quotes'...
Example: Writeln('Hello there would how is ones day?');
5. Wait(WaitTime)
This function will wait for however long the WaitTime is set to in milliseconds. Randoms are used in waits to decrease detectability again, a random is written Random(Number) and will result with any number less that the Number you say.
Example: Wait(1000+random(1000)) This will wait a maximum of 1999 and a
minimum of 1000
3.Improving our procedure
That procedure we made was good, i mean it'll get he job done... but its not really what we are looking for. We are now going to employ some failsafes and a repeat to get a quicker and better procedure
procedure Cut;
var C:integer;
begin
if(FindObj(x,y,'ree',TreeColor,15))then
begin
Mouse(x,y,5,5,True);
Writeln('Walking to Tree');
Flag;
Writeln('Cutting Tree');
C := InvCount;
repeat
wait(100);
if not(LoggedIn)then
Exit;
until(InvCount > C);
Writeln('Tree Cut');
end;
end;;
Lets talk about the new stuff then
1. Flag
Flag is a function that will check for a Flag on the minimap and will keep waiting until it disappears (i.e you've stopped walking)
2. C:= InvCount;
InvCount is an SRL function that counts the amount of items in your inventory and returns the value, so here i am setting C to equal the amount of items in your inventory.
3. repeat...until()
This will repeat anything inside until the part in brackets is true
Example
C:= 0 This will keep adding 1 to C until it is equal to 5
repeat
C:= C+1;
until(C=5);
4. if not(LoggedIn)then Exit;
This is a very important statement! It says that if you are not logged in (negative if statement) It will exit the current procedure. This stops your script getting stuck in an endless loop.
5. until(InvCount > C);
This means that the wait will repeat until either you become logged out, or your inventory count increase (i.e you get a log).
4. Debug Lesson
Here are some quick lessons in debugging, here is our entire script so far but with a few simple errors in it
program PowerCutter;
{.include srl/srl.scar}
const
TreeColor = 2706759;
procedure Cut;
var C:integer;
begin
if(FindObj(x,y,'ree',TreeColor,15))then
begin
Mouse(x,y,5,5,True);
Writeln('Walking to Tree');
Flag;
Writeln('Cutting Tree');
C = InvCount;
repeat
wait(100);
if not(LoggedIn)then
Exit;
until(InvCount > C);
end;
end;
begin
SetupSRL;
Cut;
end.
If this is compiled in scar these errors would appear
Line 11: [Error] (12242:12): Unknown identifier 'x' in script
Line 12: [Error] (12243:14): Unknown identifier 'y' in script
Line 18: [Error] (12249:3): Assignment expected in script
1. Unknown Identifier
This means that a variable or constant has not been declared. It can be fixed by placing:
var
x,y:integer;
at the top of our script, declaring those two constants.
2. Assignment expected
This is here because a colon ( : )is missing from an equation
Example: C = C+5 must instead be C:= C+5
However this rule does not apply if the equation is in brackets
Example: Until(C = 5)
5. Our FIRST EVER DTM OMFG :D
A DTM is a set of colors relevant to each other... it sounds complicated but its not really. The First thing we do is open Scar, target the RS window and then go to Tools -> DTM Editor...
You will now see:
http://img521.imageshack.us/img521/8869/dtmwindowih2.png
Your first click should be in the middle of the log, and have a tolerance of 255, this means that it could be any color
http://img57.imageshack.us/img57/6269/dtmwindowclick1zd3.jpg
You then want to choose 5 or 6 Points that are black on the outside of the log, the color you are looking for is 65536 as this color never changes
http://img515.imageshack.us/img515/9864/dtmwindowclick2zp0.jpg
After this you want to go to File -> DTM to Text and then close the DTM Editor and copy what is in the debug box into your script so you get something like this
procedure Drop;
var Logs:integer;
begin
Logs := DTMFromString('78DA637462626078C28002AAE3AC18FE036 94' +
'620FE0F048C1E40353719D000231209A4AD806AEE1050630C 54F3' +
'9A809A004CF760A87101AA7947408D0D50CD47FC6A00AFAD0 E3F');
end;
Congratulations on your first DTM :eek:
6. Our 2nd Procedure[: Dropping/U]
SRL contains lots of dropping functions, for instance you could skip this chapter and just use DropAll; but as this is a tutorial and we are hear to learn i will teach...
Now that we've declared our DTM we now ahve to learn how to use it so
procedure Drop;
var Logs:integer;
begin
Logs := DTMFromString('78DA637462626078C28002AAE3AC18FE036 94' +
'620FE0F048C1E40353719D000231209A4AD806AEE1050630C 54F3' +
'9A809A004CF760A87101AA7947408D0D50CD47FC6A00AFAD0 E3F');
if(FindDTM(Logs,x,y,MIX1,MIY1,MIX2,MIY2))then
begin
Mouse(x,y,5,5,False);
if(ClickOption('rop',2))then
begin
wait(1000+random(500));
Writeln('Dropped');
end else
begin
ArrangeInv;
end;
end else
begin
ArrangeInv;
end;
end;
1. FindDTM(DTMName,XVar,YVar,TopX,TopY,BottomX,Bottom Y)
DTMName is where we put the name of our DTM... Logs.
The XVar is were we want the XCoord to be stored to
The YVar is the same as XVar but the Y Coord
The TopX+Y are the Coords of the top corner of the search box
The BottomX+Y are the coords of the bottom corner of the search box
2. ClickOption(OptionText,Place)
The Option text is the text that appears after a right click without the capital i.e for Drop its 'rop'
The Place is either 1 For main screeen, 2 For inventory, 3 for chat screen
3. end else
end else, means that if the above statement was not true it will do the else statement
Example
if(EarthIsRound)then
begin
KeepSailing;
end else
begin
StopSailing;
end;
4.ArrangeInv
As SRL is only in BETA form they got the inventory Coords wrong and it doesnt find the last 4 items in your inventory, so i put in ArrangeInv to rearrange your inventory so that they can be dropped.
[U]7. The MainLoop
Currently our mainloop will cut one then drop one and then end so we need to change this
begin
SetupSRL;
repeat
repeat
if not(LoggedIn)then
Exit;
Cut;
until(InvFull)
repeat
if not(LoggedIn)then
Exit;
Drop;
until(FindDTM(Logs,x,y,MIX1,MIY1,MIX2,MIY2));
until(False)
end.
1. FAILSAFES
We have once again added a LoggedIn check, so that now if we log out the script wont keep trying ot work...
2. until(InvFull)
Makes this statement repeat until you have a full inventory
3. until no(FindDTM(Logs,x,y,MIX1,MIY1,MIX2,MIY2));
This means that it will keep dropping until it can no longer find the log DTM
Congratulations You've made your first power cutter....
Though i wouldn't use iit because it has no antirandoms or PlayerArray... but with all this knowledge i think you could start your own script? Give it a goe
This is an SRL 4 and Scar Divi 3.11 Tutorial so make sure you have both of them before starting
1. First Things First
With the tinyiest bit of prior knowledge everyone should know
// "//" starts a comment and everything after that wont be compiled
program PowerCutter; // The program name... Can't contain spaces
{.include srl/srl.scar} // This line includes SRL (Very useful :D)
const // This declares a constanst value
TreeColor = 2706759; // This value can't change all script
var // This declares a changing value
x,y:integer; // These are number values that can change DidItWork:boolean; // This is a variable boolean of True or False
TheWord:string; // This is a string of letters that can change
procedure DoThatStuff; // This is your first procedure Anything inbetween
begin // the begin and end is part of this procedure
end; // and can be called by typing DoThatStuff;
begin // This begins the main loop
SetupSRL; // This is needed at the start of SRL scripts
DoThatStuff; // This calls the procedure DoThatStuff;
end. // This ends the mainloop and scipt
2. Our First Procedure
We are now going to write a procedure to Cut a tree.
procedure Cut;
begin
if(FindObj(x,y,'ree',TreeColor,15))then
begin
Mouse(x,y,5,5,True);
Writeln('Cutting Tree');
wait(1000+random(1000));
end;
end;
That probably looks confusing so ill go through it bit by bit
1. An if()then statement
Everything after the if and before the then should be put in brackets ( LIKE HERE ) this is what the if is testing after the if everything you want to be done if the if is true must be put inside a begin and end
Example:
if(TheWorldIsRound)then
begin
KeepSailing;
TellTheWorld;
end;
2. FindObj(XCoord,YCoord,UpText,Color,Tolerance)
This function is used to find an object on the main RS screen.
The XCoord and YCoord should be stored to variables (normally X and Y), this is the location of the object thats found
The UpText is the text that is found in the top left corner when one mouses over an object. This value is a string such as 'ree' of Tree (strings must be in quotation marks). As a convention the capital letter is left off so for Mine it would be 'ine'...
The Color is basically the color you want it to find on the screen, use the color picker on Scar to find it
The Tolerance this is how leanient scar is with finding the color, for a tree we need to keep it quite low as there are lots of colors about, so 15 is what we will use... The Tolerance Finder by Abyssal in SRL 4 is very useful for this.
3. Mouse or MMouse
The function Mouse is "Mouse(XCoord,YCoord,XRandom,YRandom,LeftClick)"
The function MMouse is "MMouse(XCoord,YCoord,XRandom,YRandom)"
Move mouse (MMouse) will move the mouse to the position stated by XCoord and YCoord, with a random of Xrandom and YRandom (Randoms are needed to decrease detectability).
Mouse will do the same as MMouse but will either left click (True) or right click (False) depending on what the LeftClick boolean is set to
Example: Mouse(100,100,10,10,True);
4. Writeln(String)
Writeln will print whatever you write as an output to debug box at the bottom of scar, because it is a string it must be in 'quotes'...
Example: Writeln('Hello there would how is ones day?');
5. Wait(WaitTime)
This function will wait for however long the WaitTime is set to in milliseconds. Randoms are used in waits to decrease detectability again, a random is written Random(Number) and will result with any number less that the Number you say.
Example: Wait(1000+random(1000)) This will wait a maximum of 1999 and a
minimum of 1000
3.Improving our procedure
That procedure we made was good, i mean it'll get he job done... but its not really what we are looking for. We are now going to employ some failsafes and a repeat to get a quicker and better procedure
procedure Cut;
var C:integer;
begin
if(FindObj(x,y,'ree',TreeColor,15))then
begin
Mouse(x,y,5,5,True);
Writeln('Walking to Tree');
Flag;
Writeln('Cutting Tree');
C := InvCount;
repeat
wait(100);
if not(LoggedIn)then
Exit;
until(InvCount > C);
Writeln('Tree Cut');
end;
end;;
Lets talk about the new stuff then
1. Flag
Flag is a function that will check for a Flag on the minimap and will keep waiting until it disappears (i.e you've stopped walking)
2. C:= InvCount;
InvCount is an SRL function that counts the amount of items in your inventory and returns the value, so here i am setting C to equal the amount of items in your inventory.
3. repeat...until()
This will repeat anything inside until the part in brackets is true
Example
C:= 0 This will keep adding 1 to C until it is equal to 5
repeat
C:= C+1;
until(C=5);
4. if not(LoggedIn)then Exit;
This is a very important statement! It says that if you are not logged in (negative if statement) It will exit the current procedure. This stops your script getting stuck in an endless loop.
5. until(InvCount > C);
This means that the wait will repeat until either you become logged out, or your inventory count increase (i.e you get a log).
4. Debug Lesson
Here are some quick lessons in debugging, here is our entire script so far but with a few simple errors in it
program PowerCutter;
{.include srl/srl.scar}
const
TreeColor = 2706759;
procedure Cut;
var C:integer;
begin
if(FindObj(x,y,'ree',TreeColor,15))then
begin
Mouse(x,y,5,5,True);
Writeln('Walking to Tree');
Flag;
Writeln('Cutting Tree');
C = InvCount;
repeat
wait(100);
if not(LoggedIn)then
Exit;
until(InvCount > C);
end;
end;
begin
SetupSRL;
Cut;
end.
If this is compiled in scar these errors would appear
Line 11: [Error] (12242:12): Unknown identifier 'x' in script
Line 12: [Error] (12243:14): Unknown identifier 'y' in script
Line 18: [Error] (12249:3): Assignment expected in script
1. Unknown Identifier
This means that a variable or constant has not been declared. It can be fixed by placing:
var
x,y:integer;
at the top of our script, declaring those two constants.
2. Assignment expected
This is here because a colon ( : )is missing from an equation
Example: C = C+5 must instead be C:= C+5
However this rule does not apply if the equation is in brackets
Example: Until(C = 5)
5. Our FIRST EVER DTM OMFG :D
A DTM is a set of colors relevant to each other... it sounds complicated but its not really. The First thing we do is open Scar, target the RS window and then go to Tools -> DTM Editor...
You will now see:
http://img521.imageshack.us/img521/8869/dtmwindowih2.png
Your first click should be in the middle of the log, and have a tolerance of 255, this means that it could be any color
http://img57.imageshack.us/img57/6269/dtmwindowclick1zd3.jpg
You then want to choose 5 or 6 Points that are black on the outside of the log, the color you are looking for is 65536 as this color never changes
http://img515.imageshack.us/img515/9864/dtmwindowclick2zp0.jpg
After this you want to go to File -> DTM to Text and then close the DTM Editor and copy what is in the debug box into your script so you get something like this
procedure Drop;
var Logs:integer;
begin
Logs := DTMFromString('78DA637462626078C28002AAE3AC18FE036 94' +
'620FE0F048C1E40353719D000231209A4AD806AEE1050630C 54F3' +
'9A809A004CF760A87101AA7947408D0D50CD47FC6A00AFAD0 E3F');
end;
Congratulations on your first DTM :eek:
6. Our 2nd Procedure[: Dropping/U]
SRL contains lots of dropping functions, for instance you could skip this chapter and just use DropAll; but as this is a tutorial and we are hear to learn i will teach...
Now that we've declared our DTM we now ahve to learn how to use it so
procedure Drop;
var Logs:integer;
begin
Logs := DTMFromString('78DA637462626078C28002AAE3AC18FE036 94' +
'620FE0F048C1E40353719D000231209A4AD806AEE1050630C 54F3' +
'9A809A004CF760A87101AA7947408D0D50CD47FC6A00AFAD0 E3F');
if(FindDTM(Logs,x,y,MIX1,MIY1,MIX2,MIY2))then
begin
Mouse(x,y,5,5,False);
if(ClickOption('rop',2))then
begin
wait(1000+random(500));
Writeln('Dropped');
end else
begin
ArrangeInv;
end;
end else
begin
ArrangeInv;
end;
end;
1. FindDTM(DTMName,XVar,YVar,TopX,TopY,BottomX,Bottom Y)
DTMName is where we put the name of our DTM... Logs.
The XVar is were we want the XCoord to be stored to
The YVar is the same as XVar but the Y Coord
The TopX+Y are the Coords of the top corner of the search box
The BottomX+Y are the coords of the bottom corner of the search box
2. ClickOption(OptionText,Place)
The Option text is the text that appears after a right click without the capital i.e for Drop its 'rop'
The Place is either 1 For main screeen, 2 For inventory, 3 for chat screen
3. end else
end else, means that if the above statement was not true it will do the else statement
Example
if(EarthIsRound)then
begin
KeepSailing;
end else
begin
StopSailing;
end;
4.ArrangeInv
As SRL is only in BETA form they got the inventory Coords wrong and it doesnt find the last 4 items in your inventory, so i put in ArrangeInv to rearrange your inventory so that they can be dropped.
[U]7. The MainLoop
Currently our mainloop will cut one then drop one and then end so we need to change this
begin
SetupSRL;
repeat
repeat
if not(LoggedIn)then
Exit;
Cut;
until(InvFull)
repeat
if not(LoggedIn)then
Exit;
Drop;
until(FindDTM(Logs,x,y,MIX1,MIY1,MIX2,MIY2));
until(False)
end.
1. FAILSAFES
We have once again added a LoggedIn check, so that now if we log out the script wont keep trying ot work...
2. until(InvFull)
Makes this statement repeat until you have a full inventory
3. until no(FindDTM(Logs,x,y,MIX1,MIY1,MIX2,MIY2));
This means that it will keep dropping until it can no longer find the log DTM
Congratulations You've made your first power cutter....
Though i wouldn't use iit because it has no antirandoms or PlayerArray... but with all this knowledge i think you could start your own script? Give it a goe