PDA

View Full Version : Your first, simple script!



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!

YoHoJo
02-21-2012, 11:19 PM
Sweet tutorial! Lots of pictures, and details, and nifty tidbits, the new guys will love it!

[XoL]
02-21-2012, 11:28 PM
Oooh Awesome tutorial :)
Great for newcomers!

illester
02-21-2012, 11:30 PM
Yes!!! more experience, cant wait to release my first script.

poopy2177
02-22-2012, 02:05 AM
wow really good this I never knew
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}

momotron
02-22-2012, 02:27 AM
Gosh this is great! I wish this was around when I started scripting!

fretje12
02-22-2012, 02:32 AM
http://t0.gstatic.com/images?q=tbn:ANd9GcQCr-z16uYy5wCbtYCe5EQPNAXkWOPs_gKK1PMz_Yaixc2XfoU5

DemiseScythe
02-22-2012, 03:22 PM
Nice tutorial, I'll definitely read on the TPA part of it, although your DTM should use inside points ^.^~

Nice

Sin
02-22-2012, 03:29 PM
Your name is Kyle?
Who would've though that???

Er1k
02-22-2012, 04:17 PM
I learned things I never knew! impressive!

The DTM you should rely on the right half though. The graphics still glitch from my experience.

Ghostman
02-23-2012, 02:48 AM
Great tutorial! Thanks for the information, it been a long time since I made a script.

Littellj
03-01-2012, 09:44 AM
This is helping me make my first script :) now to add banking and walking (im skipping the cutting logs and doing yews!) thanks!! made a lot of sense also.
Testing to see if i got it to work.

begginer
03-01-2012, 01:31 PM
All include beginner's guide. Definetly "have to" be sticked.

Nataurs
03-03-2012, 11:18 AM
Great tut dude :)

Semtex
03-05-2012, 10:04 PM
Hi Matie i was wandering what the {$IFDEF SMART} and {$ENDIF} actually do,

begin
{$IFDEF SMART}
Smart_Server := 0;
Smart_Members := True;
Smart_Signed := True;
Smart_SuperDetail := False;
{$ENDIF}
SetupSRL();
ClearDebug();
DeclarePlayers();
LoginPlayer();
MainLoop();
end.

its also at the start of the script
{$IFDEF SMART}
{$i srl/srl/misc/paintsmart.simba}
{$ENDIF}

Whats the difference from normal scripts where it's just
//{$define smart}
{$i srl/srl.simba}
{$i srl/srl/misc/paintsmart.simba}

pulse0
03-06-2012, 03:27 AM
hey i was just wondering if anyone could tell me how to open a .rar file, i am trying to go along with the tutorial but the aca download is a rar file and i dont know how to open it... any help is appreciated

Kyle Undefined
03-06-2012, 03:28 AM
Download 7zip, and right click the .rar file and select extract :)

pulse0
03-06-2012, 03:37 AM
great got it thanks! will post some feedback once i finish reading

Element17
03-13-2012, 03:47 AM
Great Tut really helped me understand TPAs which I have been trying to figure out how to use them to find objects! Repp ++

Invalid
03-13-2012, 03:06 PM
my script compiles and then just executes..

Element17
03-13-2012, 03:38 PM
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;

Is there a difference between this and pixel shift?


*Edit Because I have this
Procedure ChopYew2(); //Took Kyle's Idea and changed it a little
Var
X, Y, LogCounter: Integer;
Box: TBox;
Begin
If(Not(loggedIn))Then Exit;
MarkTime(TooLong);
FindNormalRandoms;
MakeCompass('N');
Box:= IntToBox(MSCX -10, MSCY -25, MSCX +15, MSCY +15);
If(Not(FindNormalRandoms))Then
Begin
If(FindYew(X, Y))Then
Begin
StatsGuise('Found Tree, Chopping')
Wait(RandomRange(150, 250));

Case Random(2) of
0: Mouse(X, Y, 5, 5, True);
1: Begin
Mouse(X, Y, 5, 5, False);
WaitOption('Chop', 500);

Wait(RandomRange(100, 300));
While(Animating(Box, 750, 30))Do
Begin

Flag;
MarkTime(LogCounter);
If (TimeFromMark(Toolong) > 20000) Then
FailSafe('Could not find Tree');
AntiBan;
Wait(RandomRange(100, 300));
StatsGuise('AntiBan and Waiting');
Repeat
If (TimeFromMark(Toolong) > 25000) Then
FailSafe('Could not find Tree');
FindNormalRandoms;
StatsGuise('AntiBan and Waiting');
Antiban;
Wait(100);
Writeln('Log Cut');
Until (Not FindYew(X, Y)) or (InvFull)
End;
End;
End;
End;
End;
End;


Instead of While(Animating(Box, 750, 30))Do


Could you do

Function Mining: Boolean;
var
PBox: TBox;
begin
PBox := IntToBox(245, 130, 285, 195);
Result := (AveragePixelShift(PBox, 250, 500) > 400);
end;


I know its more code and another function but is it possible to use either or interchangeably?

Kyle Undefined
03-13-2012, 06:15 PM
Yes, I use the second method in my scripts. The Animating method was just more simple to explain when I wrote this :p

Element17
03-13-2012, 08:13 PM
Any advantage or disadvantage to either one?

Kyle Undefined
03-13-2012, 08:22 PM
No really, just a preference. I like the second one because I can modify it more easily :)

Element17
03-13-2012, 08:49 PM
Alright ha yeah I can see that. Thanks again for a great tut!

Kyle Undefined
03-13-2012, 08:52 PM
Thank you for reading :) Hope to see some from you in the future. Good luck!

FifthDimension
03-22-2012, 01:19 AM
Going to try this out tomorrow afternoon, hope it works for me, I wish I could write scripts...

cool13bro
03-22-2012, 01:53 AM
Awesome tut, my question is regarding the waituptext. I understand the function of searching for uptext, but I haven't used waituptext. So, lets say I'm waiting for a monster to respawn, would waituptext be an appropriate command to call on?

Kyle Undefined
03-22-2012, 02:23 AM
No, WaitUpText is only for waiting to check the UpText when you mouse over an item/object.

cool13bro
03-22-2012, 02:24 AM
No, WaitUpText is only for waiting to check the UpText when you mouse over an item/object.

I see, what do you recommend for my predicament of checking if a monster has spawned?

Kyle Undefined
03-22-2012, 02:28 AM
Simplest thing to do is have a loop that waits, does antiban, checks for randoms, etc until the monster has spawned. I would also add a timer to exit the loop just in case.

hoopla
03-26-2012, 11:42 PM
This fucking r0x. Thank you very much...Hope you can share more knowledge like this in the future because you have a very direct approach of instruction. Top notch.

Floydy
03-31-2012, 10:04 PM
Great guide, really helped me come to grips with DTM's!

Thanks

Floydy.

mightyz
04-01-2012, 08:39 PM
i guess im the only newcomer who was a bit confused at all of that XD

i've only done the your first rs tree and another tutorial that teaches you how to use simba and how to do loops ect ect

anyone have an easier tut i could do?


edit: i should of probably added i did like half of it before realizing im not sure exactly what i was doing but as i was doing it, it was a fantastic tutorial im just not up to this level of newbie yet

Hunaja
04-04-2012, 11:47 AM
TPA stuff was very helpful, but your DTMs will become inaccurate in the long run since items will change shape even in the inventory :mad:

Kyle Undefined
04-04-2012, 11:49 AM
Yes, but you could even make a TPA for the logs themselves, it's the same concept as the trees ;)

I honestly don't like DTMs.

RightClick
04-04-2012, 12:06 PM
Very nice tut, will probablly help so many new in scripting :) !

Rocker 1414
04-12-2012, 11:42 PM
Great tut! Thanks!

Sassakill
04-13-2012, 04:38 PM
Wow! This tutorial is just amazing! :D
I thank you very, very, very much!

Although some things could use some more explanation.

Joe
04-13-2012, 04:48 PM
Great tut. I was having problems with ACA color being rar as well. Thanks so much!

cause
04-13-2012, 05:08 PM
Very very nice tut man! One thing I noticed is that you didn't use any tolerance for the centre DTM point, I find if you include some then RS updates won't break it as much. But ++rep for sure!

catanado15
04-13-2012, 05:12 PM
man, i want to learn scripting... can u teach me plz ? to start i want make a tanner in AK... turn cowhides into leathers.... can u teach me plz ?

Kyle Undefined
04-13-2012, 05:37 PM
Awesome, glad you enjoy it! :)

catanado15
04-13-2012, 06:04 PM
kyle, can u tell me how to do a AK tanner ? plz, i want to start scripting

Imanoobbot
04-13-2012, 08:03 PM
This is one of my favourite tutorials. AWESOME work mate!!

catanado15
04-13-2012, 09:09 PM
kyle, can u tell me how to do a AK tanner ? plz, i want to start scripting

Kyle Undefined
04-13-2012, 09:18 PM
You have to read the tutorials, there are plenty that will get you going :)

Abu
04-13-2012, 09:29 PM
Love you slip in TPA's into 'your first, simple script' lol! Getting them in the habit early on, very clever ;)

Good guide! :)

catanado15
04-13-2012, 09:30 PM
i've read all of tutorials.... i do all till the anti-bans... i do the anti-bans, but then i don't know how to continue

catanado15
04-14-2012, 10:18 AM
how can i detect and NPC and trade to him ?

Joe
04-14-2012, 02:41 PM
how can i detect and NPC and trade to him ?

you should PM him these questions..

Oxygen
04-14-2012, 02:53 PM
Thanks for this great tutorial! I hope to improve my scripting skills with this!

Prometheus
04-21-2012, 07:09 AM
Niicee tutorial man. Gotta learn how to do these things now :)

Neznam
04-30-2012, 03:50 AM
As someone who has absolutely no scripting experience, I find this very hard to understand. I've read "script down your first rs tree" which was a great read, but I come to this and boy, I'm lost half way through.

What I find confusing is why somethings are used instead of others...
I guess I want to actually UNDERSTAND what each line means instead of being told it does this n that.

Don't get me wrong, Im not saying this is a bad guide at all mate.
Perhaps I need to start even slower xD
Ugh I know, how much dumber can you make it, but unfortunately it's me and not the guide. xD

Sigma
05-09-2012, 04:58 AM
Well, clearly I have a lot of learning to do before I finish going through this tutorial :P

beeb101
05-22-2012, 05:03 PM
with the colour picker, when i click find rs it says found but goes white ;/

help please
thanks

cadet54
05-24-2012, 07:55 PM
This looks awesome I have been through the other tutorial on here about cutting down your first RS tree and that was use full for getting started with procedures, IF statements and other basic stuff, this helps to build on that for me thanks very much.

DRose
05-24-2012, 08:20 PM
This was a really good guide xD Will use this to contribute back to the community asap :) Thanks Kyle :D

Opus
05-24-2012, 08:52 PM
Thank you very much for the great tutorial! It helped me a lot with basic scripting :) (It also shows me I have a looooong way to go, lmfao)

peekaboo123
06-12-2012, 03:52 AM
Hey guys, I tried to generate an item DTM but I can't seem to find the DTM editor in my simba. Do I need to change some settings to show it in my simba?

randy marsh
04-29-2013, 04:46 PM
One of the easiest guides to understand :)

03storic
05-06-2013, 01:25 PM
Hey guys, I tried to generate an item DTM but I can't seem to find the DTM editor in my simba. Do I need to change some settings to show it in my simba?

In Simba goto View then Extensions and enable dtm_editor.sex

It took me a few minutes to work that out too but my current problem is that ClickNorth is an unknown identifier....

rj
05-06-2013, 08:41 PM
In Simba goto View then Extensions and enable dtm_editor.sex

It took me a few minutes to work that out too but my current problem is that ClickNorth is an unknown identifier....

You have to include SRL

Zomg teh pwn
05-28-2013, 06:34 PM
Good guide.

~Zomg

Edit. Found information right under my nose thats how it always goes.