Kyle Undefined
02-21-2012, 11:15 PM
Hello there, my name is Kyle, and today I'm going to walk you through making your very own script! How cool is that!?! Today, we are going to learn how to make an Arrow Shafter, it’s pretty simple and takes no time at all to make!
Now, I will try to make this as easy to follow as possible, and if I don’t, let me know and I’ll try to keep it updated. Dark red text with "#" in front of it are section heads, blue text with "||" in front of it are sub sections.
So, in this tutorial I will explain how to:
# Setup a script base
# Locating and chopping a tree
--|| Using ACA to produce autocolor
--|| Writing the code to find the tree
--|| Writing the code to chop the tree
# Finding and Fletching the logs in the inventory
Let’s begin shall we?
# Setting up a script base
Before I write a script, I like to setup a base so that way I know what I've done or need to do. My base for this script would look similar to this:
program ArrowShafter;
//{$DEFINE SMART}
{$i srl/srl.simba}
{$IFDEF SMART}
{$i srl/srl/misc/paintsmart.simba}
{$ENDIF}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := ''; // Username
Pass := ''; // Password
Active := True; // Set to true if you want to use Player 0
end;
end;
procedure Antiban;
begin
if(not(LoggedIn))then Exit;
begin
case Random(100) of
10: RandomRClick;
30: PickUpMouse;
50: RandomMovement;
70: BoredHuman;
89: ExamineInv;
end;
end;
end;
// Find Tree
// Chop Tree
// Find and Fletch Logs
procedure MainLoop;
begin
end;
begin
{$IFDEF SMART}
Smart_Server := 0;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ENDIF}
SetupSRL();
ClearDebug();
DeclarePlayers();
LoginPlayer();
MainLoop();
end.
This is just an example, but it shows exactly what this script is going to do. Notice how I commented out SMART at the top? I do that so I can write and test the script without it first. Most of you have probably never seen the DEFINE code, and it comes in handy. What I'm doing for the paintsmart.simba file is only including it if SMART is being used, this makes it easier to disable SMART and not having the script error out. I do the same thing at the beginning of the script at the bottom.
The DeclarePlayers procedure is pretty straight forward, this will hold the information for the RS account you are going to be using. I put comments for the functions/procedures that I will need to write in order to make this script function.
# Locating and chopping a tree
This is probably one of the most important parts of this script, because without finding trees, the script won't be able to run! There are several ways to find trees on RS, and some are better than others. I will show you my favorite way of finding objects on the screen, that way is called TPAs. Now, before you say that these are too advanced for you, they're really not and are pretty simple once you understand how to use them. Don't worry, I'll walk you through the entire process :)
|| Using ACA to produce autocolor
First off you'll need a program called ACA or Auto Color Aid. You can find that program here (http://villavu.com/forum/showthread.php?t=26944). Load up RS in the browser and login, then, open up the ACA program. This is what it will look like:
http://i.imgur.com/D5ssh.png
Now, up at the top next to File, there is a menu item called Client. Click on that and then hover over the Client Window item, then select Find RS (You can also hit F2 to get the RS screen to show).
http://i.imgur.com/Ciiyb.png
And this is what your ACA will look like after:
http://i.imgur.com/WiKaB.png
Now comes the important part of this tool, finding the right colors for the trees so we can find them with the script. Make sure you set ACA to use CTS2, which can be set at the bottom right hand side of the program like so:
http://i.imgur.com/279e0.png
Now you have to click on the trunk of the trees to collect colors, doing so will allow us to find the Best Color to use in our script. After you have a list of colors, it's time to clear out all the duplicates, this is how my color list looks now (Note, I chose a lot of points just to fill up the bar):
http://i.imgur.com/B60sR.png
To delete the duplicates, right click on any color and select Delete Duplicates:
http://i.imgur.com/SQmQ0.png
And this is how my color list looks now:
http://i.imgur.com/y4SvC.png
All you have to do is select Mark best color and then see what parts of the screen are marked, anything that has a matching color point with the filled in Hue/Sat/Tolerance will be painted:
http://i.imgur.com/07eEC.png
Note: If too much of the screen is painted, right click on the color list and clear all of the colors. Then try selecting fewer colors that seem unique, I had to do that since I mass clicked everywhere earlier.
See how most of the paint is only on the trees we want? That's the goal. You'll also see that the color we should look for is 2766655 with a Hue of 0.12, Sat of 0.12, and a Tol of 4. This will come into use for our tree finding code in our script :) So far we have written our script base, and gotten the autocolor from ACA, next part is writing the code to find the tree!
|| Writing the code to find the tree
This is where the TPA's come into play, they're really not that hard to learn or use and are really reliable :) I'll walk you through how to create them step by step.
First you'll want to create the function base:
function FindTree(var x, y : Integer) : Boolean;
begin
end;
See how I used a var x, y : Integer parameter? With this function, you will pass in two variables and they will get returned if the tree is found. Also, the Boolean at the end means that the function will return either True or False depending if the tree is found. Now it's time to add some variables that will be used throughout the script.
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
end;
Here's a break down of the variables:
a : Integer - this is basically self explanatory, it's an Integer type and will be used in our loop section
TPA : TPointArray; - this is an array of the TPoint type, each TPoint has an x/y Integer variable that can be set
ATPA : T2DPointArray; - this is an array of the TPointArray, I know, it's very confusing. The "2D" means it's a two dimentional array.
MP : TPoint; - this is a variable that is set to the TPoint type, I named it MP for Middle Point, you'll see why later
tmpCTS : Integer; - this is a variable that will hold what the current CTS (Color Tolerance Speed) value is before we altar it
Box : TBox; - this is a TBox variable, each TBox has an X1, Y1, X2, Y2 variable that can be set
Next we go into the function, we need to add the code that changes the CTS, and the CTS Modifiers (Hue/Sat).
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
end;
See there, we check to see if the user is Logged In, if not, there is no reason to continue with the function so we Exit. We also set the tmpCTS variable to the current CTS so we can put it back when we are finished with the function. Next we set the CTS to 2, which is what we used in the ACA program to find the correct colors. Followed by the setting of the Hue/Sat variables, which was also found using the ACA program. Now it's time to search for the color!
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2766655, MSX1, MSY1, MSX2, MSY2, 4);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
end;
FindColorsSpiralTolerance will search for a color in the area you tell it to, spiraling in an outer motion and returning all the points where it was found and add them to the TPA variable we pass in.
The SortTPAFrom code will sort the TPA from a given point, and here we are telling it to sort it by the center of the screen (MSCX, MSCY) which is where the player is. We do this so it looks closer to the character.
Then we set the ATPA to the TPAtoATPAEx function. What this does is split the TPA into boxes with the h/w specified. This helps manage all the points that was found.
Now it's time to loop through the ATPA and check if there is infact a tree contained in them.
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2766655, MSX1, MSY1, MSX2, MSY2, 4);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
Box := IntToBox((MP.X - 20), (MP.Y - 20), (MP.X + 20), (MP.Y + 20));
end;
end;
This is easy, we are looping through the ATPA by using the High function, that returns the last count index of an array. Once we get into the loop, we set the MP variable to the MiddleTPA. What this does is takes the ATPA variable, and uses the array index which is set by the "a" variable from the loop, and finds the middle of the box based on how the points are laid out.
Then we set the Box variable to the MP.X/Y that was just set, but MP.X/Y is just a point so we add/subtract from them to create a box.
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2766655, MSX1, MSY1, MSX2, MSY2, 4);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
Box := IntToBox((MP.X - 20), (MP.Y - 20), (MP.X + 20), (MP.Y + 20));
{$IFDEF SMART}
SMART_DrawBoxEx(True, Box, clYellow);
{$ENDIF}
MMouse(MP.X, MP.Y, 4, 4);
if(WaitUptext('Tree', 750))then
begin
x := MP.X; y := MP.Y;
Result := True;
{$IFDEF SMART}
SMART_ClearCanvas;
{$ENDIF}
Break;
end;
end;
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
Now comes the fun part!
I check to see if the user is using SMART, and if so, draw a yellow line around the Box that I set earlier. Next, I move the mouse to the MP with a randomization of 4 for both points.
I call WaitUpText to wait for 750 miliseconds and to check if the UpText contains "Tree". If it does, then I set the X/Y variables that are passed in to the MP.X/Y coordinates. You could also add a Wait(750); before this line and use IsUpText instead, but this way combines both into one line.
Followed by setting the Result of the function to True, meaning it found the tree. Note, functions have a default setting of False. I then clear the box that I drew on the SMART screen, if SMART is being used of course, and then Break from the loop. Breaking just exits the loop, since the tree was found, it makes no sense to keep looking for it.
I then reset the CTS to the tmpCTS variable that I set earlier in the script, and set the Hue/Sat back to 0.2 which is default.
See, that wasn't so bad! That was a very simple break down of a TPA finding function, they can be much more advanced.
This is how the script will look after adding this function to it.
program ArrowShafter;
//{$DEFINE SMART}
{$i srl/srl.simba}
{$IFDEF SMART}
{$i srl/srl/misc/paintsmart.simba}
{$ENDIF}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := ''; // Username
Pass := ''; // Password
Active := True; // Set to true if you want to use Player 0
end;
end;
procedure Antiban;
begin
if(not(LoggedIn))then Exit;
begin
case Random(100) of
10: RandomRClick;
30: PickUpMouse;
50: RandomMovement;
70: BoredHuman;
89: ExamineInv;
end;
end;
end;
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2766655, MSX1, MSY1, MSX2, MSY2, 4);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
Box := IntToBox((MP.X - 20), (MP.Y - 20), (MP.X + 20), (MP.Y + 20));
{$IFDEF SMART}
SMART_DrawBoxEx(True, Box, clYellow);
{$ENDIF}
MMouse(MP.X, MP.Y, 4, 4);
if(WaitUptext('Tree', 750))then
begin
x := MP.X; y := MP.Y;
Result := True;
{$IFDEF SMART}
SMART_ClearCanvas;
{$ENDIF}
Break;
end;
end;
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
// Chop Tree
// Find and Fletch Logs
procedure MainLoop;
begin
end;
begin
{$IFDEF SMART}
Smart_Server := 0;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ENDIF}
SetupSRL();
ClearDebug();
DeclarePlayers();
LoginPlayer();
MainLoop();
end.
|| Writing the code to chop the tree
Now that you've written the code to find the tree, now it's time to actually chop it down!
So we will start off with our procedure base:
procedure ChopTree();
begin
end;
This procedure won't take any paramaters, it will just run the code that's contained. We will need to add some variables:
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
end;
The x/y variables are for the FindTree function we wrote earlier, and the Box variable will be used later on. Now it's time for the procedure setup:
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
MakeCompass('N');
Box := IntToBox(MSCX - 10, MSCY - 25, MSCX + 15, MSCY + 15);
end;
We make sure we are Logged In first, then we make the compass face North. After that, we set the Box variable to a box around the character. We will want to repeat this code until either the inventory is full, or there are no trees to be found:
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
MakeCompass('N');
Box := IntToBox(MSCX - 10, MSCY - 25, MSCX + 15, MSCY + 15);
repeat
until(InvFull or (not FindTree(x, y)));
end;
Then, we want to make sure that during this repeat, we want to check to see if we are in a random:
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
MakeCompass('N');
Box := IntToBox(MSCX - 10, MSCY - 25, MSCX + 15, MSCY + 15);
repeat
if(not(FindNormalRandoms))then
begin
end;
until(InvFull or (not FindTree(x, y)));
end;
Now we want to look for a tree to chop down, and then wait while we are chopping:
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
Box := IntToBox(MSCX - 10, MSCY - 25, MSCX + 15, MSCY + 15);
repeat
if(not(FindNormalRandoms))then
begin
if(FindTree(x, y))then
begin
Wait(RandomRange(150, 250));
Mouse(x, y, 2, 2, mouse_Left);
Wait(RandomRange(100, 300));
while(Animating(Box, 750, 30))do
begin
AntiBan;
Wait(RandomRange(100, 300));
end;
end else
Exit;
end;
until(InvFull or (not FindTree(x, y)));
end;
I know that looks like a lot, but I'll break it down for you. First we check if a tree was found, and if so, we want to click on it. The RandomRange wait is so the wait times aren't static and is random between the two numbers. Next is Mouse, which we pass in the x/y coordinates where the tree was found.
Next comes the cool part. We need to wait until we are done chopping before finding a tree again. Animating is a function in SRL that will handle it for us basically. See the Box variable? That's where this is going to be used. The function checks for movement inside of that box, the 500 number being passed in is how long we want to check for the movement. The last number is how much movement we want to look for, if the movement is less than the number we passed in, then the character is not moving.
While the character is moving (chopping), we want to do the AntiBan procedure and wait. Finally, if a Tree isn't found, we exit the procedure. This is how the script will look when we are done adding this procedure to it:
program ArrowShafter;
//{$DEFINE SMART}
{$i srl/srl.simba}
{$IFDEF SMART}
{$i srl/srl/misc/paintsmart.simba}
{$ENDIF}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := ''; // Username
Pass := ''; // Password
Active := True; // Set to true if you want to use Player 0
end;
end;
procedure Antiban;
begin
if(not(LoggedIn))then Exit;
begin
case Random(100) of
10: RandomRClick;
30: PickUpMouse;
50: RandomMovement;
70: BoredHuman;
89: ExamineInv;
end;
end;
end;
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2766655, MSX1, MSY1, MSX2, MSY2, 4);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
Box := IntToBox((MP.X - 20), (MP.Y - 20), (MP.X + 20), (MP.Y + 20));
{$IFDEF SMART}
SMART_DrawBoxEx(True, Box, clYellow);
{$ENDIF}
MMouse(MP.X, MP.Y, 4, 4);
if(WaitUptext('Tree', 750))then
begin
x := MP.X; y := MP.Y;
Result := True;
{$IFDEF SMART}
SMART_ClearCanvas;
{$ENDIF}
Break;
end;
end;
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
Box := IntToBox(MSCX - 10, MSCY - 25, MSCX + 15, MSCY + 15);
repeat
if(not(FindNormalRandoms))then
begin
if(FindTree(x, y))then
begin
Wait(RandomRange(150, 250));
Mouse(x, y, 2, 2, mouse_Left);
Wait(RandomRange(100, 300));
while(Animating(Box, 750, 30))do
begin
AntiBan;
Wait(RandomRange(100, 300));
end;
end else
Exit;
end;
until(InvFull or (not FindTree(x, y)));
end;
// Find and Fletch Logs
procedure MainLoop;
begin
end;
begin
{$IFDEF SMART}
Smart_Server := 0;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ENDIF}
SetupSRL();
ClearDebug();
DeclarePlayers();
LoginPlayer();
MainLoop();
end.
# Finding and Fletching the logs in the inventory
Now that we have logs, we need to find them. There are multiple ways of finding them, you could use DTMs, Bitmaps, TPA's, and a more advanced technique called Blacklist. I'll show you how to create a DTM and how to find it. They are really simple and fit this job perfectly. so here's how we do it.
First, you can either save an image of Runescape with the the logs visible in a .bmp format, or you can move Simba around near the bottom of the screen. I have dual monitors so I put Runescape on one screen and Simba on the other.
Next, in Simba click on Tools then DTM Editor.
http://i.imgur.com/jWM2q.png
A popup will appear and if you need to load the image you saved, click on Image then Load Client Image.
http://i.imgur.com/APl17.png
Position the logs in the window and zoom if necessary. I always zoom 300% in since it makes it a whole lot easier to make the DTM. Your popup should look something like this:
http://i.imgur.com/GFpsV.png
Then, click somewhere in the middle of the log to set your main point. This is required or your DTM will not work. Then, click on the edge of the log to set sub points, but only on the black outline. I usually do about 3-5 sub points for my DTMs, but you can do however many you want. Your popup should look something like this:
http://i.imgur.com/XCjtB.png
I chose 9 sub points, but you don't need that many. What I like to do now is to test the DTM points and see if they're found on the image. To do that, click on Image and then Show Matching DTM's:
http://i.imgur.com/cZDA6.png
Or you can hit the keyboard shortcut Ctrl + D. Your popup should look somewhat like this:
http://i.imgur.com/dOtr1.png
Notice how all the logs were found? That's what we are wanting! Next, we need to be able to use this DTM, and to do that you need to click on DTM and then on Print DTM:
http://i.imgur.com/6dphh.png
A string will appear in the Simba Debugbox, which is the big white area at the bottom, and it will resemble something like this:
DTM := DTMFromString('m1gAAAHic42JgYDBlgWB7ILYEYm0g1gNiFy B2AGJ1ILYC4meMDAwfgfgpEN8B4vtA/AmI3wLxbSB+B8QfgDjGTRNoKhMRmDjASCRGAACU/QxT');
That's your DTM that you will use in the script. Now it's time to write the procedure to find the DTM of the logs and fletch them. Your procedure base will be a little different for this, but it's easy to understand:
procedure FindAndFletch();
var
DTM, x, y : Integer;
TP : TPoint;
begin
DTM := DTMFromString('m1gAAAHic42JgYDBlgWB7ILYEYm0g1gNiFy B2AGJ1ILYC4meMDAwfgfgpEN8B4vtA/AmI3wLxbSB+B8QfgDjGTRNoKhMRmDjASCRGAACU/QxT');
end;
The variable DTM is an Integer, but why is that? The string is just the data that you chose to make the DTM. The DTMFromString works its magic and transforms that string into a DTM in memory, and assigns a number to that variable. The variable x/y are standard for any Finding function. The TP variable will be used later on. Now we have to find the DTM on RS, and this is how:
procedure FindAndFletch();
var
DTM, x, y : Integer;
TP : TPoint;
begin
DTM := DTMFromString('m1gAAAHic42JgYDBlgWB7ILYEYm0g1gNiFy B2AGJ1ILYC4meMDAwfgfgpEN8B4vtA/AmI3wLxbSB+B8QfgDjGTRNoKhMRmDjASCRGAACU/QxT');
if(FindDTM(DTM, x, y, MIX1, MIY1, MIX2, MIY2))then
begin
Mouse(x, y, 5, 5, mouse_Left);
Wait(RandomRange(750, 900));
end;
FreeDTM(DTM);
end;
Note, always remember to free the DTM you just used out of memory when you're done using it!
If the DTM is found, it left clicks on the log to pull up the options. Now we have to find the right option, you could make a DTM of the right buttons, or you can search for the text which will be easier:
procedure FindAndFletch();
var
DTM, x, y : Integer;
TP : TPoint;
begin
DTM := DTMFromString('m1gAAAHic42JgYDBlgWB7ILYEYm0g1gNiFy B2AGJ1ILYC4meMDAwfgfgpEN8B4vtA/AmI3wLxbSB+B8QfgDjGTRNoKhMRmDjASCRGAACU/QxT');
if(FindDTM(DTM, x, y, MIX1, MIY1, MIX2, MIY2))then
begin
Mouse(x, y, 5, 5, mouse_Left);
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'nife', StatChars, ClickLeft))then
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'et of', StatChars, ClickLeft))then
begin
end;
end;
FreeDTM(DTM);
end;
Now, here's the break down. FindTextTPAEx looks for colored text in the area you give it with the right font. It even has an option for clicking the option, which we will take advantage of! The 2070783 is the number for the color of the text options, and 0 is the tolerance. MCX1/2 and MCY1/2 are the chat box coordinates. TP.X/Y are the TPoint variables that get passed into the function, and you could use regular Integer variables if you want. The text is what you're searching for, and the StatChars is the font that the text is in. ClickLeft is the parameter that tells the function to go ahead and click.
Since the "Knife" option only appears when you first login, just a check to see if it's there, and if it is then add a wait afterwards. This will keep waits down to a minimal when running the script. All we have to do now is setup the waiting while it's fletching, and it's even easier than the animation one for the chopping function.
All we have to do is wait while the inventory count is greater than 1.
procedure FindAndFletch();
var
DTM, x, y : Integer;
TP : TPoint;
begin
DTM := DTMFromString('m1gAAAHic42JgYDBlgWB7ILYEYm0g1gNiFy B2AGJ1ILYC4meMDAwfgfgpEN8B4vtA/AmI3wLxbSB+B8QfgDjGTRNoKhMRmDjASCRGAACU/QxT');
if(FindDTM(DTM, x, y, MIX1, MIY1, MIX2, MIY2))then
begin
Mouse(x, y, 5, 5, mouse_Left);
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'nife', StatChars, ClickLeft))then
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'et of', StatChars, ClickLeft))then
begin
while(InvCount > 1)do
begin
AntiBan;
Wait(RandomRange(250, 500));
end;
end;
end;
FreeDTM(DTM);
end;
So now all the pieces are complete, we just have to assemble the MainLoop procedure and we're off! This is how the script will look so far:
program ArrowShafter;
//{$DEFINE SMART}
{$i srl/srl.simba}
{$IFDEF SMART}
{$i srl/srl/misc/paintsmart.simba}
{$ENDIF}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := ''; // Username
Pass := ''; // Password
Active := True; // Set to true if you want to use Player 0
end;
end;
procedure Antiban;
begin
if(not(LoggedIn))then Exit;
begin
case Random(100) of
10: RandomRClick;
30: PickUpMouse;
50: RandomMovement;
70: BoredHuman;
89: ExamineInv;
end;
end;
end;
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2766655, MSX1, MSY1, MSX2, MSY2, 4);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
Box := IntToBox((MP.X - 20), (MP.Y - 20), (MP.X + 20), (MP.Y + 20));
{$IFDEF SMART}
SMART_DrawBoxEx(True, Box, clYellow);
{$ENDIF}
MMouse(MP.X, MP.Y, 4, 4);
if(WaitUptext('Tree', 750))then
begin
x := MP.X; y := MP.Y;
Result := True;
{$IFDEF SMART}
SMART_ClearCanvas;
{$ENDIF}
Break;
end;
end;
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
Box := IntToBox(MSCX - 10, MSCY - 25, MSCX + 15, MSCY + 15);
repeat
if(not(FindNormalRandoms))then
begin
if(FindTree(x, y))then
begin
Wait(RandomRange(150, 250));
Mouse(x, y, 2, 2, mouse_Left);
Wait(RandomRange(100, 300));
while(Animating(Box, 750, 30))do
begin
AntiBan;
Wait(RandomRange(100, 300));
end;
end else
Exit;
end;
until(InvFull or (not FindTree(x, y)));
end;
procedure FindAndFletch();
var
DTM, x, y : Integer;
TP : TPoint;
begin
DTM := DTMFromString('m1gAAAHic42JgYDBlgWB7ILYEYm0g1gNiFy B2AGJ1ILYC4meMDAwfgfgpEN8B4vtA/AmI3wLxbSB+B8QfgDjGTRNoKhMRmDjASCRGAACU/QxT');
if(FindDTM(DTM, x, y, MIX1, MIY1, MIX2, MIY2))then
begin
Mouse(x, y, 5, 5, mouse_Left);
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'nife', StatChars, ClickLeft))then
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'et of', StatChars, ClickLeft))then
begin
while(InvCount > 1)do
begin
AntiBan;
Wait(RandomRange(250, 500));
end;
end;
end;
FreeDTM(DTM);
end;
procedure MainLoop;
begin
end;
begin
{$IFDEF SMART}
Smart_Server := 0;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ENDIF}
SetupSRL();
ClearDebug();
DeclarePlayers();
LoginPlayer();
MainLoop();
end.
Assembling the MainLoop is going to be very easy. All you have to do is add a repeat of the two functions:
procedure MainLoop;
begin
ClickNorth(SRL_ANGLE_LOW);
repeat
ChopTree();
FindAndFletch();
until(AllPlayersInactive);
end;
The until(AllPlayersInactive); will end the script if all the players are set to inactive. Here is how the script will look once completed.
program ArrowShafter;
{$DEFINE SMART}
{$i srl/srl.simba}
{$IFDEF SMART}
{$i srl/srl/misc/paintsmart.simba}
{$ENDIF}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := ''; // Username
Pass := ''; // Password
Active := True; // Set to true if you want to use Player 0
end;
end;
procedure Antiban;
begin
if(not(LoggedIn))then Exit;
begin
case Random(100) of
10: RandomRClick;
30: PickUpMouse;
50: RandomMovement;
70: BoredHuman;
89: ExamineInv;
end;
end;
end;
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2766655, MSX1, MSY1, MSX2, MSY2, 4);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
Box := IntToBox((MP.X - 20), (MP.Y - 20), (MP.X + 20), (MP.Y + 20));
{$IFDEF SMART}
SMART_DrawBoxEx(True, Box, clYellow);
{$ENDIF}
MMouse(MP.X, MP.Y, 4, 4);
if(WaitUpText('Tree', 750))then
begin
x := MP.X; y := MP.Y;
Result := True;
{$IFDEF SMART}
SMART_ClearCanvas;
{$ENDIF}
Break;
end;
end;
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
Box := IntToBox(MSCX - 10, MSCY - 25, MSCX + 15, MSCY + 15);
repeat
if(not(FindNormalRandoms))then
begin
if(FindTree(x, y))then
begin
Wait(RandomRange(250, 500));
Mouse(x, y, 2, 2, mouse_Left);
Wait(RandomRange(100, 300));
while(Animating(Box, 750, 25))do
begin
AntiBan;
Wait(RandomRange(100, 300));
end;
end else
Exit;
end;
until(InvFull or (not FindTree(x, y)));
end;
procedure FindAndFletch();
var
DTM, x, y : Integer;
TP : TPoint;
begin
DTM := DTMFromString('m1gAAAHic42JgYDBlgWB7ILYEYm0g1gNiFy B2AGJ1ILYC4meMDAwfgfgpEN8B4vtA/AmI3wLxbSB+B8QfgDjGTRNoKhMRmDjASCRGAACU/QxT');
if(FindDTM(DTM, x, y, MIX1, MIY1, MIX2, MIY2))then
begin
Mouse(x, y, 5, 5, mouse_Left);
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'nife', StatChars, ClickLeft))then
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'et of', StatChars, ClickLeft))then
begin
while(InvCount > 1)do
begin
AntiBan;
Wait(RandomRange(250, 500));
end;
end;
end;
FreeDTM(DTM);
end;
procedure MainLoop;
begin
ClickNorth(SRL_ANGLE_LOW);
repeat
ChopTree();
FindAndFletch();
until(AllPlayersInactive);
end;
begin
{$IFDEF SMART}
Smart_Server := 0;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ENDIF}
SetupSRL();
ClearDebug();
DeclarePlayers();
LoginPlayer();
MainLoop();
end.
And there ya have it, you wrote your first script! :D Now, the script you wrote isn't perfect, it still needs some tweaks, but it's a great start and a wonderful learning process! I'll try to keep this updated and working, but don't hold me to that.
Happy scripting!
Now, I will try to make this as easy to follow as possible, and if I don’t, let me know and I’ll try to keep it updated. Dark red text with "#" in front of it are section heads, blue text with "||" in front of it are sub sections.
So, in this tutorial I will explain how to:
# Setup a script base
# Locating and chopping a tree
--|| Using ACA to produce autocolor
--|| Writing the code to find the tree
--|| Writing the code to chop the tree
# Finding and Fletching the logs in the inventory
Let’s begin shall we?
# Setting up a script base
Before I write a script, I like to setup a base so that way I know what I've done or need to do. My base for this script would look similar to this:
program ArrowShafter;
//{$DEFINE SMART}
{$i srl/srl.simba}
{$IFDEF SMART}
{$i srl/srl/misc/paintsmart.simba}
{$ENDIF}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := ''; // Username
Pass := ''; // Password
Active := True; // Set to true if you want to use Player 0
end;
end;
procedure Antiban;
begin
if(not(LoggedIn))then Exit;
begin
case Random(100) of
10: RandomRClick;
30: PickUpMouse;
50: RandomMovement;
70: BoredHuman;
89: ExamineInv;
end;
end;
end;
// Find Tree
// Chop Tree
// Find and Fletch Logs
procedure MainLoop;
begin
end;
begin
{$IFDEF SMART}
Smart_Server := 0;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ENDIF}
SetupSRL();
ClearDebug();
DeclarePlayers();
LoginPlayer();
MainLoop();
end.
This is just an example, but it shows exactly what this script is going to do. Notice how I commented out SMART at the top? I do that so I can write and test the script without it first. Most of you have probably never seen the DEFINE code, and it comes in handy. What I'm doing for the paintsmart.simba file is only including it if SMART is being used, this makes it easier to disable SMART and not having the script error out. I do the same thing at the beginning of the script at the bottom.
The DeclarePlayers procedure is pretty straight forward, this will hold the information for the RS account you are going to be using. I put comments for the functions/procedures that I will need to write in order to make this script function.
# Locating and chopping a tree
This is probably one of the most important parts of this script, because without finding trees, the script won't be able to run! There are several ways to find trees on RS, and some are better than others. I will show you my favorite way of finding objects on the screen, that way is called TPAs. Now, before you say that these are too advanced for you, they're really not and are pretty simple once you understand how to use them. Don't worry, I'll walk you through the entire process :)
|| Using ACA to produce autocolor
First off you'll need a program called ACA or Auto Color Aid. You can find that program here (http://villavu.com/forum/showthread.php?t=26944). Load up RS in the browser and login, then, open up the ACA program. This is what it will look like:
http://i.imgur.com/D5ssh.png
Now, up at the top next to File, there is a menu item called Client. Click on that and then hover over the Client Window item, then select Find RS (You can also hit F2 to get the RS screen to show).
http://i.imgur.com/Ciiyb.png
And this is what your ACA will look like after:
http://i.imgur.com/WiKaB.png
Now comes the important part of this tool, finding the right colors for the trees so we can find them with the script. Make sure you set ACA to use CTS2, which can be set at the bottom right hand side of the program like so:
http://i.imgur.com/279e0.png
Now you have to click on the trunk of the trees to collect colors, doing so will allow us to find the Best Color to use in our script. After you have a list of colors, it's time to clear out all the duplicates, this is how my color list looks now (Note, I chose a lot of points just to fill up the bar):
http://i.imgur.com/B60sR.png
To delete the duplicates, right click on any color and select Delete Duplicates:
http://i.imgur.com/SQmQ0.png
And this is how my color list looks now:
http://i.imgur.com/y4SvC.png
All you have to do is select Mark best color and then see what parts of the screen are marked, anything that has a matching color point with the filled in Hue/Sat/Tolerance will be painted:
http://i.imgur.com/07eEC.png
Note: If too much of the screen is painted, right click on the color list and clear all of the colors. Then try selecting fewer colors that seem unique, I had to do that since I mass clicked everywhere earlier.
See how most of the paint is only on the trees we want? That's the goal. You'll also see that the color we should look for is 2766655 with a Hue of 0.12, Sat of 0.12, and a Tol of 4. This will come into use for our tree finding code in our script :) So far we have written our script base, and gotten the autocolor from ACA, next part is writing the code to find the tree!
|| Writing the code to find the tree
This is where the TPA's come into play, they're really not that hard to learn or use and are really reliable :) I'll walk you through how to create them step by step.
First you'll want to create the function base:
function FindTree(var x, y : Integer) : Boolean;
begin
end;
See how I used a var x, y : Integer parameter? With this function, you will pass in two variables and they will get returned if the tree is found. Also, the Boolean at the end means that the function will return either True or False depending if the tree is found. Now it's time to add some variables that will be used throughout the script.
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
end;
Here's a break down of the variables:
a : Integer - this is basically self explanatory, it's an Integer type and will be used in our loop section
TPA : TPointArray; - this is an array of the TPoint type, each TPoint has an x/y Integer variable that can be set
ATPA : T2DPointArray; - this is an array of the TPointArray, I know, it's very confusing. The "2D" means it's a two dimentional array.
MP : TPoint; - this is a variable that is set to the TPoint type, I named it MP for Middle Point, you'll see why later
tmpCTS : Integer; - this is a variable that will hold what the current CTS (Color Tolerance Speed) value is before we altar it
Box : TBox; - this is a TBox variable, each TBox has an X1, Y1, X2, Y2 variable that can be set
Next we go into the function, we need to add the code that changes the CTS, and the CTS Modifiers (Hue/Sat).
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
end;
See there, we check to see if the user is Logged In, if not, there is no reason to continue with the function so we Exit. We also set the tmpCTS variable to the current CTS so we can put it back when we are finished with the function. Next we set the CTS to 2, which is what we used in the ACA program to find the correct colors. Followed by the setting of the Hue/Sat variables, which was also found using the ACA program. Now it's time to search for the color!
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2766655, MSX1, MSY1, MSX2, MSY2, 4);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
end;
FindColorsSpiralTolerance will search for a color in the area you tell it to, spiraling in an outer motion and returning all the points where it was found and add them to the TPA variable we pass in.
The SortTPAFrom code will sort the TPA from a given point, and here we are telling it to sort it by the center of the screen (MSCX, MSCY) which is where the player is. We do this so it looks closer to the character.
Then we set the ATPA to the TPAtoATPAEx function. What this does is split the TPA into boxes with the h/w specified. This helps manage all the points that was found.
Now it's time to loop through the ATPA and check if there is infact a tree contained in them.
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2766655, MSX1, MSY1, MSX2, MSY2, 4);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
Box := IntToBox((MP.X - 20), (MP.Y - 20), (MP.X + 20), (MP.Y + 20));
end;
end;
This is easy, we are looping through the ATPA by using the High function, that returns the last count index of an array. Once we get into the loop, we set the MP variable to the MiddleTPA. What this does is takes the ATPA variable, and uses the array index which is set by the "a" variable from the loop, and finds the middle of the box based on how the points are laid out.
Then we set the Box variable to the MP.X/Y that was just set, but MP.X/Y is just a point so we add/subtract from them to create a box.
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2766655, MSX1, MSY1, MSX2, MSY2, 4);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
Box := IntToBox((MP.X - 20), (MP.Y - 20), (MP.X + 20), (MP.Y + 20));
{$IFDEF SMART}
SMART_DrawBoxEx(True, Box, clYellow);
{$ENDIF}
MMouse(MP.X, MP.Y, 4, 4);
if(WaitUptext('Tree', 750))then
begin
x := MP.X; y := MP.Y;
Result := True;
{$IFDEF SMART}
SMART_ClearCanvas;
{$ENDIF}
Break;
end;
end;
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
Now comes the fun part!
I check to see if the user is using SMART, and if so, draw a yellow line around the Box that I set earlier. Next, I move the mouse to the MP with a randomization of 4 for both points.
I call WaitUpText to wait for 750 miliseconds and to check if the UpText contains "Tree". If it does, then I set the X/Y variables that are passed in to the MP.X/Y coordinates. You could also add a Wait(750); before this line and use IsUpText instead, but this way combines both into one line.
Followed by setting the Result of the function to True, meaning it found the tree. Note, functions have a default setting of False. I then clear the box that I drew on the SMART screen, if SMART is being used of course, and then Break from the loop. Breaking just exits the loop, since the tree was found, it makes no sense to keep looking for it.
I then reset the CTS to the tmpCTS variable that I set earlier in the script, and set the Hue/Sat back to 0.2 which is default.
See, that wasn't so bad! That was a very simple break down of a TPA finding function, they can be much more advanced.
This is how the script will look after adding this function to it.
program ArrowShafter;
//{$DEFINE SMART}
{$i srl/srl.simba}
{$IFDEF SMART}
{$i srl/srl/misc/paintsmart.simba}
{$ENDIF}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := ''; // Username
Pass := ''; // Password
Active := True; // Set to true if you want to use Player 0
end;
end;
procedure Antiban;
begin
if(not(LoggedIn))then Exit;
begin
case Random(100) of
10: RandomRClick;
30: PickUpMouse;
50: RandomMovement;
70: BoredHuman;
89: ExamineInv;
end;
end;
end;
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2766655, MSX1, MSY1, MSX2, MSY2, 4);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
Box := IntToBox((MP.X - 20), (MP.Y - 20), (MP.X + 20), (MP.Y + 20));
{$IFDEF SMART}
SMART_DrawBoxEx(True, Box, clYellow);
{$ENDIF}
MMouse(MP.X, MP.Y, 4, 4);
if(WaitUptext('Tree', 750))then
begin
x := MP.X; y := MP.Y;
Result := True;
{$IFDEF SMART}
SMART_ClearCanvas;
{$ENDIF}
Break;
end;
end;
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
// Chop Tree
// Find and Fletch Logs
procedure MainLoop;
begin
end;
begin
{$IFDEF SMART}
Smart_Server := 0;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ENDIF}
SetupSRL();
ClearDebug();
DeclarePlayers();
LoginPlayer();
MainLoop();
end.
|| Writing the code to chop the tree
Now that you've written the code to find the tree, now it's time to actually chop it down!
So we will start off with our procedure base:
procedure ChopTree();
begin
end;
This procedure won't take any paramaters, it will just run the code that's contained. We will need to add some variables:
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
end;
The x/y variables are for the FindTree function we wrote earlier, and the Box variable will be used later on. Now it's time for the procedure setup:
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
MakeCompass('N');
Box := IntToBox(MSCX - 10, MSCY - 25, MSCX + 15, MSCY + 15);
end;
We make sure we are Logged In first, then we make the compass face North. After that, we set the Box variable to a box around the character. We will want to repeat this code until either the inventory is full, or there are no trees to be found:
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
MakeCompass('N');
Box := IntToBox(MSCX - 10, MSCY - 25, MSCX + 15, MSCY + 15);
repeat
until(InvFull or (not FindTree(x, y)));
end;
Then, we want to make sure that during this repeat, we want to check to see if we are in a random:
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
MakeCompass('N');
Box := IntToBox(MSCX - 10, MSCY - 25, MSCX + 15, MSCY + 15);
repeat
if(not(FindNormalRandoms))then
begin
end;
until(InvFull or (not FindTree(x, y)));
end;
Now we want to look for a tree to chop down, and then wait while we are chopping:
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
Box := IntToBox(MSCX - 10, MSCY - 25, MSCX + 15, MSCY + 15);
repeat
if(not(FindNormalRandoms))then
begin
if(FindTree(x, y))then
begin
Wait(RandomRange(150, 250));
Mouse(x, y, 2, 2, mouse_Left);
Wait(RandomRange(100, 300));
while(Animating(Box, 750, 30))do
begin
AntiBan;
Wait(RandomRange(100, 300));
end;
end else
Exit;
end;
until(InvFull or (not FindTree(x, y)));
end;
I know that looks like a lot, but I'll break it down for you. First we check if a tree was found, and if so, we want to click on it. The RandomRange wait is so the wait times aren't static and is random between the two numbers. Next is Mouse, which we pass in the x/y coordinates where the tree was found.
Next comes the cool part. We need to wait until we are done chopping before finding a tree again. Animating is a function in SRL that will handle it for us basically. See the Box variable? That's where this is going to be used. The function checks for movement inside of that box, the 500 number being passed in is how long we want to check for the movement. The last number is how much movement we want to look for, if the movement is less than the number we passed in, then the character is not moving.
While the character is moving (chopping), we want to do the AntiBan procedure and wait. Finally, if a Tree isn't found, we exit the procedure. This is how the script will look when we are done adding this procedure to it:
program ArrowShafter;
//{$DEFINE SMART}
{$i srl/srl.simba}
{$IFDEF SMART}
{$i srl/srl/misc/paintsmart.simba}
{$ENDIF}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := ''; // Username
Pass := ''; // Password
Active := True; // Set to true if you want to use Player 0
end;
end;
procedure Antiban;
begin
if(not(LoggedIn))then Exit;
begin
case Random(100) of
10: RandomRClick;
30: PickUpMouse;
50: RandomMovement;
70: BoredHuman;
89: ExamineInv;
end;
end;
end;
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2766655, MSX1, MSY1, MSX2, MSY2, 4);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
Box := IntToBox((MP.X - 20), (MP.Y - 20), (MP.X + 20), (MP.Y + 20));
{$IFDEF SMART}
SMART_DrawBoxEx(True, Box, clYellow);
{$ENDIF}
MMouse(MP.X, MP.Y, 4, 4);
if(WaitUptext('Tree', 750))then
begin
x := MP.X; y := MP.Y;
Result := True;
{$IFDEF SMART}
SMART_ClearCanvas;
{$ENDIF}
Break;
end;
end;
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
Box := IntToBox(MSCX - 10, MSCY - 25, MSCX + 15, MSCY + 15);
repeat
if(not(FindNormalRandoms))then
begin
if(FindTree(x, y))then
begin
Wait(RandomRange(150, 250));
Mouse(x, y, 2, 2, mouse_Left);
Wait(RandomRange(100, 300));
while(Animating(Box, 750, 30))do
begin
AntiBan;
Wait(RandomRange(100, 300));
end;
end else
Exit;
end;
until(InvFull or (not FindTree(x, y)));
end;
// Find and Fletch Logs
procedure MainLoop;
begin
end;
begin
{$IFDEF SMART}
Smart_Server := 0;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ENDIF}
SetupSRL();
ClearDebug();
DeclarePlayers();
LoginPlayer();
MainLoop();
end.
# Finding and Fletching the logs in the inventory
Now that we have logs, we need to find them. There are multiple ways of finding them, you could use DTMs, Bitmaps, TPA's, and a more advanced technique called Blacklist. I'll show you how to create a DTM and how to find it. They are really simple and fit this job perfectly. so here's how we do it.
First, you can either save an image of Runescape with the the logs visible in a .bmp format, or you can move Simba around near the bottom of the screen. I have dual monitors so I put Runescape on one screen and Simba on the other.
Next, in Simba click on Tools then DTM Editor.
http://i.imgur.com/jWM2q.png
A popup will appear and if you need to load the image you saved, click on Image then Load Client Image.
http://i.imgur.com/APl17.png
Position the logs in the window and zoom if necessary. I always zoom 300% in since it makes it a whole lot easier to make the DTM. Your popup should look something like this:
http://i.imgur.com/GFpsV.png
Then, click somewhere in the middle of the log to set your main point. This is required or your DTM will not work. Then, click on the edge of the log to set sub points, but only on the black outline. I usually do about 3-5 sub points for my DTMs, but you can do however many you want. Your popup should look something like this:
http://i.imgur.com/XCjtB.png
I chose 9 sub points, but you don't need that many. What I like to do now is to test the DTM points and see if they're found on the image. To do that, click on Image and then Show Matching DTM's:
http://i.imgur.com/cZDA6.png
Or you can hit the keyboard shortcut Ctrl + D. Your popup should look somewhat like this:
http://i.imgur.com/dOtr1.png
Notice how all the logs were found? That's what we are wanting! Next, we need to be able to use this DTM, and to do that you need to click on DTM and then on Print DTM:
http://i.imgur.com/6dphh.png
A string will appear in the Simba Debugbox, which is the big white area at the bottom, and it will resemble something like this:
DTM := DTMFromString('m1gAAAHic42JgYDBlgWB7ILYEYm0g1gNiFy B2AGJ1ILYC4meMDAwfgfgpEN8B4vtA/AmI3wLxbSB+B8QfgDjGTRNoKhMRmDjASCRGAACU/QxT');
That's your DTM that you will use in the script. Now it's time to write the procedure to find the DTM of the logs and fletch them. Your procedure base will be a little different for this, but it's easy to understand:
procedure FindAndFletch();
var
DTM, x, y : Integer;
TP : TPoint;
begin
DTM := DTMFromString('m1gAAAHic42JgYDBlgWB7ILYEYm0g1gNiFy B2AGJ1ILYC4meMDAwfgfgpEN8B4vtA/AmI3wLxbSB+B8QfgDjGTRNoKhMRmDjASCRGAACU/QxT');
end;
The variable DTM is an Integer, but why is that? The string is just the data that you chose to make the DTM. The DTMFromString works its magic and transforms that string into a DTM in memory, and assigns a number to that variable. The variable x/y are standard for any Finding function. The TP variable will be used later on. Now we have to find the DTM on RS, and this is how:
procedure FindAndFletch();
var
DTM, x, y : Integer;
TP : TPoint;
begin
DTM := DTMFromString('m1gAAAHic42JgYDBlgWB7ILYEYm0g1gNiFy B2AGJ1ILYC4meMDAwfgfgpEN8B4vtA/AmI3wLxbSB+B8QfgDjGTRNoKhMRmDjASCRGAACU/QxT');
if(FindDTM(DTM, x, y, MIX1, MIY1, MIX2, MIY2))then
begin
Mouse(x, y, 5, 5, mouse_Left);
Wait(RandomRange(750, 900));
end;
FreeDTM(DTM);
end;
Note, always remember to free the DTM you just used out of memory when you're done using it!
If the DTM is found, it left clicks on the log to pull up the options. Now we have to find the right option, you could make a DTM of the right buttons, or you can search for the text which will be easier:
procedure FindAndFletch();
var
DTM, x, y : Integer;
TP : TPoint;
begin
DTM := DTMFromString('m1gAAAHic42JgYDBlgWB7ILYEYm0g1gNiFy B2AGJ1ILYC4meMDAwfgfgpEN8B4vtA/AmI3wLxbSB+B8QfgDjGTRNoKhMRmDjASCRGAACU/QxT');
if(FindDTM(DTM, x, y, MIX1, MIY1, MIX2, MIY2))then
begin
Mouse(x, y, 5, 5, mouse_Left);
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'nife', StatChars, ClickLeft))then
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'et of', StatChars, ClickLeft))then
begin
end;
end;
FreeDTM(DTM);
end;
Now, here's the break down. FindTextTPAEx looks for colored text in the area you give it with the right font. It even has an option for clicking the option, which we will take advantage of! The 2070783 is the number for the color of the text options, and 0 is the tolerance. MCX1/2 and MCY1/2 are the chat box coordinates. TP.X/Y are the TPoint variables that get passed into the function, and you could use regular Integer variables if you want. The text is what you're searching for, and the StatChars is the font that the text is in. ClickLeft is the parameter that tells the function to go ahead and click.
Since the "Knife" option only appears when you first login, just a check to see if it's there, and if it is then add a wait afterwards. This will keep waits down to a minimal when running the script. All we have to do now is setup the waiting while it's fletching, and it's even easier than the animation one for the chopping function.
All we have to do is wait while the inventory count is greater than 1.
procedure FindAndFletch();
var
DTM, x, y : Integer;
TP : TPoint;
begin
DTM := DTMFromString('m1gAAAHic42JgYDBlgWB7ILYEYm0g1gNiFy B2AGJ1ILYC4meMDAwfgfgpEN8B4vtA/AmI3wLxbSB+B8QfgDjGTRNoKhMRmDjASCRGAACU/QxT');
if(FindDTM(DTM, x, y, MIX1, MIY1, MIX2, MIY2))then
begin
Mouse(x, y, 5, 5, mouse_Left);
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'nife', StatChars, ClickLeft))then
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'et of', StatChars, ClickLeft))then
begin
while(InvCount > 1)do
begin
AntiBan;
Wait(RandomRange(250, 500));
end;
end;
end;
FreeDTM(DTM);
end;
So now all the pieces are complete, we just have to assemble the MainLoop procedure and we're off! This is how the script will look so far:
program ArrowShafter;
//{$DEFINE SMART}
{$i srl/srl.simba}
{$IFDEF SMART}
{$i srl/srl/misc/paintsmart.simba}
{$ENDIF}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := ''; // Username
Pass := ''; // Password
Active := True; // Set to true if you want to use Player 0
end;
end;
procedure Antiban;
begin
if(not(LoggedIn))then Exit;
begin
case Random(100) of
10: RandomRClick;
30: PickUpMouse;
50: RandomMovement;
70: BoredHuman;
89: ExamineInv;
end;
end;
end;
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2766655, MSX1, MSY1, MSX2, MSY2, 4);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
Box := IntToBox((MP.X - 20), (MP.Y - 20), (MP.X + 20), (MP.Y + 20));
{$IFDEF SMART}
SMART_DrawBoxEx(True, Box, clYellow);
{$ENDIF}
MMouse(MP.X, MP.Y, 4, 4);
if(WaitUptext('Tree', 750))then
begin
x := MP.X; y := MP.Y;
Result := True;
{$IFDEF SMART}
SMART_ClearCanvas;
{$ENDIF}
Break;
end;
end;
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
Box := IntToBox(MSCX - 10, MSCY - 25, MSCX + 15, MSCY + 15);
repeat
if(not(FindNormalRandoms))then
begin
if(FindTree(x, y))then
begin
Wait(RandomRange(150, 250));
Mouse(x, y, 2, 2, mouse_Left);
Wait(RandomRange(100, 300));
while(Animating(Box, 750, 30))do
begin
AntiBan;
Wait(RandomRange(100, 300));
end;
end else
Exit;
end;
until(InvFull or (not FindTree(x, y)));
end;
procedure FindAndFletch();
var
DTM, x, y : Integer;
TP : TPoint;
begin
DTM := DTMFromString('m1gAAAHic42JgYDBlgWB7ILYEYm0g1gNiFy B2AGJ1ILYC4meMDAwfgfgpEN8B4vtA/AmI3wLxbSB+B8QfgDjGTRNoKhMRmDjASCRGAACU/QxT');
if(FindDTM(DTM, x, y, MIX1, MIY1, MIX2, MIY2))then
begin
Mouse(x, y, 5, 5, mouse_Left);
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'nife', StatChars, ClickLeft))then
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'et of', StatChars, ClickLeft))then
begin
while(InvCount > 1)do
begin
AntiBan;
Wait(RandomRange(250, 500));
end;
end;
end;
FreeDTM(DTM);
end;
procedure MainLoop;
begin
end;
begin
{$IFDEF SMART}
Smart_Server := 0;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ENDIF}
SetupSRL();
ClearDebug();
DeclarePlayers();
LoginPlayer();
MainLoop();
end.
Assembling the MainLoop is going to be very easy. All you have to do is add a repeat of the two functions:
procedure MainLoop;
begin
ClickNorth(SRL_ANGLE_LOW);
repeat
ChopTree();
FindAndFletch();
until(AllPlayersInactive);
end;
The until(AllPlayersInactive); will end the script if all the players are set to inactive. Here is how the script will look once completed.
program ArrowShafter;
{$DEFINE SMART}
{$i srl/srl.simba}
{$IFDEF SMART}
{$i srl/srl/misc/paintsmart.simba}
{$ENDIF}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := ''; // Username
Pass := ''; // Password
Active := True; // Set to true if you want to use Player 0
end;
end;
procedure Antiban;
begin
if(not(LoggedIn))then Exit;
begin
case Random(100) of
10: RandomRClick;
30: PickUpMouse;
50: RandomMovement;
70: BoredHuman;
89: ExamineInv;
end;
end;
end;
function FindTree(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.12, 0.12);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2766655, MSX1, MSY1, MSX2, MSY2, 4);
SortTPAFrom(TPA, Point(MSCX, MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
Box := IntToBox((MP.X - 20), (MP.Y - 20), (MP.X + 20), (MP.Y + 20));
{$IFDEF SMART}
SMART_DrawBoxEx(True, Box, clYellow);
{$ENDIF}
MMouse(MP.X, MP.Y, 4, 4);
if(WaitUpText('Tree', 750))then
begin
x := MP.X; y := MP.Y;
Result := True;
{$IFDEF SMART}
SMART_ClearCanvas;
{$ENDIF}
Break;
end;
end;
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
procedure ChopTree();
var
x, y : Integer;
Box : TBox;
begin
if(not(LoggedIn))then Exit;
Box := IntToBox(MSCX - 10, MSCY - 25, MSCX + 15, MSCY + 15);
repeat
if(not(FindNormalRandoms))then
begin
if(FindTree(x, y))then
begin
Wait(RandomRange(250, 500));
Mouse(x, y, 2, 2, mouse_Left);
Wait(RandomRange(100, 300));
while(Animating(Box, 750, 25))do
begin
AntiBan;
Wait(RandomRange(100, 300));
end;
end else
Exit;
end;
until(InvFull or (not FindTree(x, y)));
end;
procedure FindAndFletch();
var
DTM, x, y : Integer;
TP : TPoint;
begin
DTM := DTMFromString('m1gAAAHic42JgYDBlgWB7ILYEYm0g1gNiFy B2AGJ1ILYC4meMDAwfgfgpEN8B4vtA/AmI3wLxbSB+B8QfgDjGTRNoKhMRmDjASCRGAACU/QxT');
if(FindDTM(DTM, x, y, MIX1, MIY1, MIX2, MIY2))then
begin
Mouse(x, y, 5, 5, mouse_Left);
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'nife', StatChars, ClickLeft))then
Wait(RandomRange(750, 900));
if(FindTextTPAEx(2070783, 0, MCX1, MCY1, MCX2, MCY2, TP.X, TP.Y, 'et of', StatChars, ClickLeft))then
begin
while(InvCount > 1)do
begin
AntiBan;
Wait(RandomRange(250, 500));
end;
end;
end;
FreeDTM(DTM);
end;
procedure MainLoop;
begin
ClickNorth(SRL_ANGLE_LOW);
repeat
ChopTree();
FindAndFletch();
until(AllPlayersInactive);
end;
begin
{$IFDEF SMART}
Smart_Server := 0;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ENDIF}
SetupSRL();
ClearDebug();
DeclarePlayers();
LoginPlayer();
MainLoop();
end.
And there ya have it, you wrote your first script! :D Now, the script you wrote isn't perfect, it still needs some tweaks, but it's a great start and a wonderful learning process! I'll try to keep this updated and working, but don't hold me to that.
Happy scripting!