PART II
SCRIPTING WITH SRL
This is where the fun begins! I will teach you how to design you first script by using SRL commands and my own scripting techniques.
The first thing that you have to do whenever you are making an SRL script is to include it and use the command SetupSRL in your main loop. Like this:
[/SCAR]
SCAR Code:
Program New;
{.include SRL/SRL.scar} // this must be typed exact
begin
SetupSRL; // must be the first thing called in your mainloop
end.
I believe that the easiest script to start with is a basic powerchopper that will cut trees and drop the logs. We obviously have to begin with basic color finding techniques in order to detect the tree. First I have to give you the run down on the FindColor functions:
SCAR Code:
Procedure FindTree;
var
x,y: Integer;
begin
if(FindColor(x,y,YourColor,msx1,msy1,msx2,msy2))then // Basic FindColor function
begin
MMouse(x,y,3,3); // Moves the mouse to the color with 3 pixel randomness vertical & horizontal
end;
end;
Now for the explanation... the x and y are the variables that will store the coordinate of the color, if found. YourColor should be changed to the color you will pick from the tree. msx1, msy1, msx2, & msy2 are the constants for the mainscreen coordinates noted by the ms for mainscreen. These coords can be anything you want, ranging from manual numbers to other constants and variables. To get a better understanding of these coords I will show you a picture of what they represent:
SCAR Code:
(msx1,msy1)
|-----------------|
| |
| |
| |
| |
|_________________|
(msx2,msy2)
The (msx1,msy1) is the coord of the top left corner of the box and (msx2,msy2) is the bottom corner coordinate. SCAR will preform the search for that color within that box specified by the mainscreen coords.
So you understand the basic FindColor function, now you need to know how to use it in order to accurately find your tree and chop it down. A vital function that is used in just about every script is IsUpText. This function will check the upper left corner of the screen for the text of the object, in this case a tree.
SCAR Code:
Procedure ClickTree;
var
x,y: Integer;
begin
if(FindColor(x,y,YourColor,msx1,msy1,msx2,msy2))then // Basic FindColor function
begin
MMouse(x,y,3,3); // Moves the mouse to the color with 3 pixel randomness vertical & horizontal
if(IsUpText('ree'))then // Looks for the 'ree' in Tree
begin
GetMousePos(x,y); // Gets the coords of the current mouse position
Mouse(x,y,0,0,True); // Left clicks the tree (False for right click)
end;
end;
end;
So we have the script search for the color, and if found it will move the mouse to the tree, check if it is a tree, and if it is a tree it will left click it. This procedure is a good start, but it is going to need more work. What happens if the colors shift in the game (happens very often) and it can't find the color anymore? That would suck wouldnt it? That is why we have the function FindColorTolerance.
Swapping out the basic FindColor with FindColorTolerance will give your procedure the ability to work even after logouts.
SCAR Code:
Procedure ClickTree;
var
x,y: Integer;
begin
if(FindColorTolerance(x,y,YourColor,msx1,msy1,msx2,msy2,3))then // Finds the color with a tolerance of 3
begin
MMouse(x,y,3,3); // Moves the mouse to the color with 3 pixel randomness vertical & horizontal
if(IsUpText('ree'))then // Looks for the 'ree' in Tree
begin
GetMousePos(x,y); // Gets the coords of the current mouse position
Mouse(x,y,0,0,True); // Left clicks the tree (False for right click)
end;
end;
end;
I find that it is easier to incorporate the procedure into the main loop if we convert it into a function that returns true or false. This is where functions become very useful.
SCAR Code:
Function ClickTree: Boolean;
var
x,y: Integer;
begin
if(FindColorTolerance(x,y,YourColor,msx1,msy1,msx2,msy2,3))then // Finds the color with a tolerance of 3
begin
MMouse(x,y,3,3); // Moves the mouse to the color with 3 pixel randomness vertical & horizontal
if(IsUpText('ree'))then // Looks for the 'ree' in Tree
begin
GetMousePos(x,y); // Gets the coords of the current mouse position
Mouse(x,y,0,0,True); // Left clicks the tree (False for right click)
Result := True; // It clicked the tree successfully
Exit; // Exits out of the procedure because it was successful
end else
Result := False; // It wasnt a tree =(
end;
end;
To make this function useful I will put it into the mainloop like so:
SCAR Code:
program PowerChopper;
{.include SRL/SRL.scar}
const
YourColor = 0; //Change the 0 to whatever your color is
Function ClickTree: Boolean;
var
x,y: Integer;
begin
if(FindColorTolerance(x,y,YourColor,msx1,msy1,msx2,msy2,3))then
begin
MMouse(x,y,3,3);
if(IsUpText('ree'))then
begin
GetMousePos(x,y);
Mouse(x,y,0,0,True);
Result := True;
Exit;
end else
Result := False;
end;
end;
begin
SetupSRL; // Always have to have this!
repeat
Wait(500 + random(500));
until(ClickTree = True); // Repeats waiting until it clicks the tree
end.
ANTI-RANDOMS
Anti-Randoms are extremely important if you want your script to run for more than 10 minutes. With the current SRL the only two functions that you will need to cover your randoms will be FTWait and FindNormalRandoms. You should call your random checks during every Loop and after every click. These are explanations of the randoms procedures:
SCAR Code:
{*******************************************************************************
procedure FTWait(Time: Integer);
By: WT-Fakawi
Description: Performs Wait and FindTalk. Time is multiple of 250 msec, so FTWait(4)
waits approx 1 sec and performs 4 FindTalks;
*******************************************************************************}
{*******************************************************************************
function FindNormalRandoms: Boolean;
by: The SRL Developers Team!... all time sexiness by Mutant
Description: Calls the 'normal' random checks.
*******************************************************************************}
Now I will add anti-randoms to the appropriate areas of our script:
SCAR Code:
program PowerChopper;
{.include SRL/SRL.scar}
const
YourColor = 0;
Function ClickTree: Boolean;
var
x,y: Integer;
begin
if(FindColorTolerance(x,y,YourColor,msx1,msy1,msx2,msy2,3))then
begin
MMouse(x,y,3,3);
if(IsUpText('ree'))then
begin
GetMousePos(x,y);
Mouse(x,y,0,0,True);
FTWait(2); // FTWait should be after EVERY click
FindNormalRandoms; // Checks for all randoms
Result := True;
Exit;
end else
Result := False;
end;
end;
begin
SetupSRL;
repeat
FTWait(2); // Checks for randoms until the tree is clicked
FindNormalRandoms;
until(ClickTree = True);
end.
FAILSAFES
Failsafes make up the backbone of the script. When you make a script you need to think of every possible thing that could go wrong in every procedure. With this mentality you are able to create methods so that WHEN these things do happen, the script will correct it and get back on path. The most basic failsafe would be:
SCAR Code:
if(not(LoggedIn))then
Exit;
This should be the very first thing in every procedure and function that you make. If you fail to do this and lets say for example during your tree finding function, your character fails at solving a random and is teleported to the lumbrige basement...after it doesnt find the tree and you get automatically logged off it will just sit there continuing the search for the tree forever. This failsafe will exit the procedure when you are logged off.
Another very effective failsafe is for loops. It implements timing how long the loop lasts and if it lasts too long it will break from it. This failsafe uses two functions, MarkTime and TimeFromMark. To use these you need to declare a variable to hold the time (an integer). We will use these failsafes in our script like so:
SCAR Code:
program PowerChopper;
{.include SRL/SRL.scar}
var WaitTime: Integer; // <-- The timing variable
const
YourColor = 0;
Function ClickTree: Boolean;
var
x,y: Integer;
begin
if(not(LoggedIn))then
Exit;
if(FindColorTolerance(x,y,YourColor,msx1,msy1,msx2,msy2,3))then
begin
MMouse(x,y,3,3);
if(IsUpText('ree'))then
begin
GetMousePos(x,y);
Mouse(x,y,0,0,True);
FTWait(2);
FindNormalRandoms;
Result := True;
Exit;
end else
Result := False;
end;
end;
begin
SetupSRL;
MarkTime(WaitTime); // Starts timing with the waittime variable
repeat
if(TimeFromMark(WaitTime) > 20000)then // Logs out if it takes longer than 20 sec
begin
Writeln('Tree finding timed out');
Logout;
end;
FTWait(2);
FindNormalRandoms;
until(ClickTree = True);
end.
Now that Anti-randoms and Failsafes have been explained, we can move on to the rest of the script. So far we have the script search for the tree and click it, now we need to adjust the mainloop so that it will repeat chopping until our inventory is full. Time between clicks must be randomized so that you will not get banned. The function InvFull will detect when our inventory is full. Our script should look like so:
SCAR Code:
program PowerChopper;
{.include SRL/SRL.scar}
var WaitTime,LoadTime: Integer; // Load timer is there now as well
const
YourColor = 0;
Function ClickTree: Boolean;
var
x,y: Integer;
begin
if(not(LoggedIn))then
Exit;
if(FindColorTolerance(x,y,YourColor,msx1,msy1,msx2,msy2,3))then
begin
MMouse(x,y,3,3);
if(IsUpText('ree'))then
begin
GetMousePos(x,y);
Mouse(x,y,0,0,True);
FTWait(2);
FindNormalRandoms;
Result := True;
Exit;
end else
Result := False;
end;
end;
begin
SetupSRL;
MarkTime(LoadTime);
repeat
if(TimeFromMark(LoadTime) > 300000)then // Exits the loop after 5 min
begin
Writeln('Load time timed out');
Break;
end;
FTWait(8);
Wait(Random(4000)); // Waiting between clicks
FindNormalRandoms;
MarkTime(WaitTime);
repeat
if(TimeFromMark(WaitTime) > 20000)then
begin
Writeln('Tree finding timed out');
Logout;
end;
FTWait(2);
FindNormalRandoms;
until(ClickTree = True);
until(InvFull); // Stops when inventory is full
end.
Notice that I added another repeat loop in order for it to continue clicking the tree until the inventory is full. I also added another failsafe to the new loop, by making a load timer that wil break the loop if it surpasses 5 minutes.
Now we need to make a dropping procedure. The simplest way to do this is to use DropToPostion.
SCAR Code:
Procedure Drop;
begin
if(not(LoggedIn))then
Exit;
begin
DropToPosition(2,28); // Drops from slot 2 to 28
end;
end;
MORE TO COME!!!
- Multiplayer
- Progress Reports