PDA

View Full Version : All In One Beginner Guide



NKN
05-04-2012, 12:29 AM
Welcome, this is my fourth tutorial, and it includes all you need to know as a beginner to start making your scripts.
This isn't going to be the best guide you will ever see, I just hope it can help. Feedback appreciated.


Contents

Introduction
Procedures and Functions
Color Finding
Option Choosing
Inventory Commands
Repeat the script
Antiban
All together now
Conclusion



Introduction
Hey guys. I've been scripting for a few months now, and decided to try my hand at a all in one tutorial. This guide is for the complete beginner, so advanced scripters probably won't gather much from this. I hope by the end of this, you don't just copy/paste, but actually create your own from scratch.


Procedures and Functions
Alright, when I first started, I was confused here, I didn't really understand what the difference was. I'm going to try to explain it now.

First off, variable types:
Integer ~ A whole number
String ~ One or more letters/numbers/characters.
Tpoint ~ A point on the screen.
TBox ~ It takes two points, and makes a box, using X1,Y1,X2,Y2, as the corners of the box.
Boolean ~ Can only be True or False
TPointArray ~ An Array of Tpoint, so multiple Tpoints in one Variable
Array of -Variable here- ~ An Array of the variable you choose.
2D arrays ~ An Array of an Array. (Confusing, I know)

Now that we got that out of the way, on to procedures!


procedure Mine;
var
Mined : Integer;
s : String;
begin
//Code here
end;


Let's take a breakdown!
Procedure Mine;
This is the name of the procedure, and it's how you call it, which we will learn at the end of this chapter.
var
Mined : Integer;
s : String;
Var stands for Variables, so this is where you declare local variables, or variables that can only be edited inside that procedure.

If you use it at the top of your script, you can use that variable throughout the whole script.

begin
end;
This tells you what the procedure is doing, basicly.

On to Functions!
They are just like procedures, except they return a variable. Need an example?

Function returnString:String;
begin
Result := 'Here is the result, or the variable returnString equals!';
end;


After you name it, you put :-Variablehere-, and then inside the script, use Result := to declare what it equals!

So you could do something like this:

Writeln(returnString);

That would return:
Here is the result, or the variable returnString equals!'
Get it?
You can place that with a Integer, Boolean, and anything else. It's most commonly seen as a Boolean, though.

Time to go semi-advanced with this.


procedure ReturnString(s:String);
begin
Writeln(s);
end;

You didn't declare s after the name, because you declared it IN the name! You can do this for Functions also.

So, you would do this to call it!

ReturnString('Here is the String');

Then s equals 'Here is the String'!

That sums it up for Functions and Procedures!


Color Finding
I perfer to use ACA to find colors. It seems much more accurate than FindColorTolerance.

This below is for working on a bank. It can be used for ANYTHING. Just got to be creative. :D

Here it is:
We'll be using AutoColorAid to find the colors.
The link can be found here. (http://villavu.com/forum/showthread.php?t=26944)
Alright. This is what how you need to set it up.
Go to Client -> Find RS
http://i49.tinypic.com/2d7iry9.png

After you clicked two, click on the booths, click about three different booths, about 7 - 10 times each in different places, to get a good reading. Click "Mark Best Color" and if mostly only those are colored red, you did it! If say, the ground is lit, redo it with less points.
This is my final picture:http://i39.tinypic.com/35mii61.png

The color: That's the color you'll be needed. The first and second number I circled, we'll get to that in a minute.

How to find the bank
You got your info on the Autocolor, time to put it into code.

function FindBankTeller(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box,SearchArea : TBox;
begin
if not LoggedIn then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.03,0.78);
SearchArea := IntToBox((MSCX - 200),(MSCY - 100),(MSCX),(MSCY + 150));
SMART_DrawBoxEx(True,SearchArea,clPurple);
FindColorsSpiralTolerance(MSCX,MSCY,TPA,2313821,MS CX -200,MSCY - 100 ,MSCX,MSCY + 150,9);
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));
SMART_DrawBoxEx(False,Box,clYellow);
MMouse(MP.x,MP.y,4,4);
if(WaitUpText('ank',750))then
begin
While(InvCount > 15) do
begin
x := MP.x; y := MP.y;
Result := True
SMART_ClearCanvas;
Mouse(x,y,0,0,True);
WaitFunc(@BankScreen, 10 + Random(15), 10000);
Deposit(2,28,True);
Writeln('Depotsitied');
Antiban;
end;
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2,0.2);
end;

I'm not going to go over all of it, but I'll go over the parts you need to know.

SetColorSpeed2Modifyers: The first number should be the red circled number, and the second the green.

SearchArea: is defined as a Tbox, or three points. I used MSCX and MSCY to start the box, and them again to mark the end. The first two is the first corner of the box, the second is the last. MSCX/Y is Main Screen Center, then plus or minus X/y To make a box.

SMART_DrawBoxEx: This draws the box on screen do you know what you're looking at. Set the first variable to True if you want it to clear the screen, or false to keep it there. Second variable is the name of the Tbox, third is the color (cl"ColorName").

FindSpiralTolerance: You use MSCX,MSCY as the first two, then TPA, then the color, then where it searches, this is where painting the box comes in handy, so you know where it's looking. Those four that should usually be MSX1, MSY1,ect, should be the same thing you put in the box! The tolerance is off to the right of the AutoColorAid program(ACA). It's right under Main color. The - is not a minus sign, tolerance is always positive!

WaitFunc: This waits for the BankScreen, which is @BankScreen. It waits 10 seconds, checking every 10 milliseconds, plus random 15.

The rest you should be able to gauge what it does, and how to work it!


How to use it

You call it in a function like this if(-NameOfFunction-(x,y)) then //The (x,y) has to be after the name for it to work, that's where it saves the location to.
begin
//blah blah blah, remember, the banking is done IN the color finding function, so this is AFTERWARDS
end;

Choosing Options

Alright, time to choose some options!

To get the mouse over it, you use this:

Mouse(x,y,4,4,mouseRight);

This will move the mouse to x,y, with a randomness of 4, and then right click it. You can also use mouseLeft, if you just want it to skip right click, and just click it, which can then ignore the next step.

You then use something like
WaitOption('String to look for',3000);

In the String to look for, it's looking for one of the options, so if you wanted it to say mine, you could use 'Mine' or 'ine' It has to capitalized correctly.
It then waits for a maximum of 3 seconds, because it counts in milliseconds.

You could use this for many different things.

Now, if you perfer to just LeftClick, I would do this:
Mouse(x,y,4,4,3);
WaitUpText('Uptext',5000);


It would move mouse, with randomness of 4, and then with the 3, it just moves it, and doesn't click.

WaitUpText looks for the Uptext, or the text in the top left corner of the screen when you hover your mouse over it. 'Uptext' is what you're looking for, which needs to be capitalized correctly. It waits a maximum of 5 seconds.
Then you could do.

Mouse(x,y,4,4,3);
if(WaitUpText('Uptext',5000)) then
Mouse(x,y,0,0,mouseLeft);

Which then clicks if it finds the uptext correctly!

Inventory Commands

It's nice to know these, so you know when to break loops and things.


var
Inventory:Integer;
begin
Inventory := InvCount
if(Inventory > 20) then
bank;
end;



WaitInvMinCount

This procedure waits for the specified amount of items in the inventory. You'll see how to use it later.

DropAllExcept

Drops everything in inventory except which item slots.


GetSystemTime

Not really an inventory command, but oh well. When called, it gets the current time, simple. You'll see how I use it later, also.

Just a small part of the guide, you can find more in the Inventory section of SRL.


Repeating Script

To repeat the script, you add all your functions in a mainloop:

procedure Mainloop;
begin
WalkToOre;
MineOre;
WalkToBank;
Bank;
end;

Something along the lines of that, with more advanced ones being obviously safer.

To use it, go to your final begin..end


begin
SetupSRL
repeat
Mainloop;
until(AllPlayersInactive);
end;

This just repeats the script until all the players are inactive.

Antiban

Antiban exists to keep us safe, so here's a quick runthrough.

procedure Antiban;
begin
FindNormalRandoms;
case Random(80) of
0: RandomRClick;
2: PickUpMouse;
3: RandomMovement;
4: BoredHuman;
5: ExamineInv;
7: SetAngle(SRL_ANGLE_HIGH);
8: Wait(750 + random(750));
end;
end;
This just does different things, at about a 1/10 chance of it happening. It also checks for randoms.


All together now

Alright! Let's make us a script!
Here's the skeleton:

program new;
{$DEFINE SMART}
{$i srl/srl.simba}
{$i srl/srl/misc/paintsmart.simba}
procedure DeclarePlayers;
begin
HowManyPlayers := 1; // This is set to the total amount of players (more on multiplayer later ;)), for now, just keep it set as 1
NumberOfPlayers(HowManyPlayers); // This is a procedure in SRL which sets up player arrays (also, more on that later), this will always be the same
CurrentPlayer := 0; // This is the player to start with; the first player will always be 0 (you'll find out when you learn all about arrays)

Players[0].Name := ''; // Username
Players[0].Pass := ''; // Password
Players[0].Nick := ''; // 3-4 lowercase letters from username; used for random event detection
Players[0].Active := True; // Set to true if you want to use Player 0
Players[0].Pin := ''; // Leave blank if the player doesn't have a bank pin
Players[0].BoxRewards := ['Xp', 'mote', 'ostume', 'oins', 'aphire', 'ssence'];
end;


begin
// These 4 lines HAVE to be set BEFORE you call SetupSRL;
Smart_Server := 26;
Smart_Members := False;
Smart_Signed := True;
Smart_SuperDetail := False;

ClearDebug;
SetupSRL;
DeclarePlayers;
LoginPlayer;
end.

Save that as Default script.
(File > Save As Default)

Alright, click run, and log in.

We're going to be making a power chopper for Lumbridge.

Start at a Willow tree, hatchet in first slot in inventory, or equipped.

Lets see if you can do it without help, to see if you understood!

Here is what I got:

program Powerchopper;
{$DEFINE SMART}
{$i srl/srl.simba}
{$i srl/srl/misc/paintsmart.simba}
procedure DeclarePlayers;
begin
HowManyPlayers := 1; // This is set to the total amount of players (more on multiplayer later ;)), for now, just keep it set as 1
NumberOfPlayers(HowManyPlayers); // This is a procedure in SRL which sets up player arrays (also, more on that later), this will always be the same
CurrentPlayer := 0; // This is the player to start with; the first player will always be 0 (you'll find out when you learn all about arrays)

Players[0].Name := ''; // Username
Players[0].Pass := ''; // Password
Players[0].Nick := ''; // 3-4 lowercase letters from username; used for random event detection
Players[0].Active := True; // Set to true if you want to use Player 0
Players[0].Pin := ''; // Leave blank if the player doesn't have a bank pin
Players[0].BoxRewards := ['Xp', 'mote', 'ostume', 'oins', 'aphire', 'ssence'];
end;
procedure Antiban;
begin
FindNormalRandoms;
case Random(80) of
0: RandomRClick;
2: PickUpMouse;
3: RandomMovement;
4: BoredHuman;
5: ExamineInv;
7: SetAngle(SRL_ANGLE_HIGH);
8: Wait(750 + random(750));
end;
end;
function FindTree(var x, y : Integer) : Boolean;
var
a,HowMany,Time : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box,SearchArea : TBox;
begin
if not LoggedIn then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.70,1.52);
SearchArea := IntToBox((MSCX - 200),(MSCY - 100),(MSCX),(MSCY + 150));
SMART_DrawBoxEx(True,SearchArea,clPurple);
FindColorsSpiralTolerance(MSCX,MSCY,TPA,2635575,MS CX -200,MSCY - 100 ,MSCX,MSCY + 150,2);
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));
SMART_DrawBoxEx(False,Box,clYellow);
MMouse(MP.x,MP.y,4,4);
if(WaitUpText('hop',750))then//Waits for Chop
begin
While(InvCount < 28) do
begin
x := MP.x; y := MP.y;
Result := True
SMART_ClearCanvas;
Mouse(x,y,0,0,True);
Time := GetSystemTime + 5000;
While(Time > GetSystemTime) do
begin
HowMany := InvCount
if(WaitInvMinCount((HowMany + 1),30000)) then //If you got a log, waits 30 seconds for it
begin
Writeln('Got logs');
Writeln('So far so good');
Time := GetSystemTime + 5000;//Resets time
Continue; //Returns to top of the loop it's called in, so While(Time > GetSystemTime);
end else
Exit; //Exits procedure
end;
Antiban;
end;
if(InvCount = 28) then DropAllExcept([1]); //Drops everything
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2,0.2);
end;
procedure Mainloop;
var
x,y:Integer;
begin
FindTree(x,y);
Antiban;
end;
begin
// These 4 lines HAVE to be set BEFORE you call SetupSRL;
Smart_Server := 26;
Smart_Members := False;
Smart_Signed := True;
Smart_SuperDetail := False;

ClearDebug;
SetupSRL;
DeclarePlayers;
LoginPlayer;
repeat
Mainloop;
until(AllPlayersInactive);
end.

A little buggy, but works pretty good! It powerchops, then drops.


Conclusion

If your reading this, than thanks for reading! I would love feedback/things to improve on! Until next time, ~NKN

b_lone
05-04-2012, 12:46 AM
Yay for scripting tutorial! I've read about 2 and a half scripting tutorials up until now..and I still don't know when to use var, boolean, etc. >.<

NKN
05-04-2012, 12:47 AM
Alright, thanks. :P

Imanoobbot
05-04-2012, 12:52 AM
Cool guide :) I enjoyed it alot. Maybe you should add a TPA section in it as it is really needed and lots of people dont understand them.

NKN
05-04-2012, 12:53 AM
I'll think about it. Should absolute beginners be learning what TPA's are at the start? xD

Striken
05-05-2012, 04:19 AM
Good tutorial for the rookies :)
I learned from tutorials and they really help a lot if you're dedicated

Motis25
05-07-2012, 06:36 PM
Thank you! You helped me a lot. ;)

Prometheus
05-10-2012, 03:03 AM
Thanks for this! Will help me a lot on my first RS script

doorsftw
05-24-2012, 05:42 PM
really helpful guide and really helped with variables :)

cadet54
05-29-2012, 07:11 PM
This tutorial is pretty good, slowly working my way through all the scripting tutorials and working on my own scripts as I gain more skills, thanks for this.

juliea
06-06-2012, 06:00 PM
bookmarked ty really nice tut.Gonna see if I can learn something with being think in the head and all.