PDA

View Full Version : The Scar & SRL Tutorial, By Hermpie



ShowerThoughts
05-09-2008, 04:16 PM
The Scar & SRL Tutorial

Notes:
This Tutorial is written by Hermpie.
It could be possible that the code example not compile please make a post about it.
Any comments or 'bugs' are apreciated.
Feel like something is missing? Pm me or post below.

I hope you enjoy and learn much from this tutorial!


Chapters:

1- How to get the newest Scar & SRL.
2- Making an HelloWorld procedure.
3- Variables
4- SRL & Scar Build in Variables(+extra).
5- SRL Basic FindColor Functions & MouseMoving.
- FindColor
- FindColorSpiral
- FindColorSpiralTolerance
- Mouse Moving(included everywhere)
6- really really much more to come!
7-
8-
9-
10-




Chapter 1
{===================================]
How to get the newest Scar & SRL.
[===================================}

The smartest thing is to delete every scar and srl files you have got.
Go to http://freddy1990.com/scar.php to download the newest scar.
Click the download '<current version> Scar' when done downloading install it.
When done installing go to http://subversion.tigris.org/files/documents/15/39559/svn-1.4.5-setup.exe to get subversion.
Download it and install it, wouldn't take that long.

Now this is a little bit harder, now start up scar and if you see:
- a screen 'Getting started with scar'(if you downloaded a new version). Then click 'Show this window next time SCAR is launched' to off
or
- 'this is the first time you run Scar you probably don't got the newest includes or SRL' then click 'NO' The next question is similiar to this click 'No'
or
- Nothing then do nothing.

If you done that.
Go to tools --> Options --> Srl Download(Last, Lowest Tab)--> You see 'Download Type' choose 'Subversion repository' --> click okay.
Then go to File --> Check Out SRl Svn.
Done.

Note: if you can't choose 'Subversion repository' then reinstall Subversion http://subversion.tigris.org/files/documents/15/39559/svn-1.4.5-setup.exe.



Chapter 2
{===================================]
Making an HelloWorld procedure.
[===================================}

Start up Scar
You will see

Program New;
Begin

End.

Program New;//Shows that the program name is 'New' this is really not important, you can also call it Program InMyAssMotherFucker; Note: it needs to be the first non-commented line in the script;

Begin// Begin and end. that is the mainloop scar do's what is between there, will explain more later.
End.

Okay, so we are making an HelloWorld Procedure that is an procedure who writes HelloWorld!.
Most of the time it is smart to think
-'What i am going to make?'// an HelloWorld Writer
-'What kind of procedures and function i am going to make.'// i am going to make an procedure witch writes HelloWorld in the debug box and one for RuneScape.

Okay, lets get started


Program New;
//MainLoop
Begin

End.


Lets change the name!

Program MyfirstScript;
Begin

End.

Now lets add an WriteToDebug Procedure and a WriteToRunescape Procedure

Program MyfirstScript;

Procedure WriteToDeBug;
Begin

End;

Procedure WriteToRunescape;
Begin

End;


//MainLoop
Begin

End.

Okay but if we compile this, nothings happends.
Because we didn't do anything in one of those procedures.
Lets do something!

Program MyfirstScript;

Procedure WriteToDeBug;
Begin
WriteLn('Hello Word!');//this send this line to the debug box (Below)
End;

Procedure WriteToRunescape;
Begin

End;


Begin

End.

Okay, lets compile that. what! it doesn't work what did i do wrong?!
If you look good you see that 'WriteToDeBug;' is not called in the mainloop, and scar does only 'Compiles' the mainloop.
Okay, lets add it to the mainloop.

Program MyfirstScript;

Procedure WriteToDeBug;
Begin
WriteLn('Hello Word!');//this send this line to the debug box (Below)
End;

Procedure WriteToRunescape;
Begin

End;

//MainLoop
Begin
WriteToDeBug;
End.

Okay, awesome! it writes 'Hello World!' to the Debugbox, w8 it is that great :p
Now lets send it keys to runescape.

Program MyfirstScript;

Procedure WriteToDeBug;
Begin
WriteLn('Hello Word!');//this send this line to the debugbox (Below)
End;

Procedure WriteToRunescape;
Begin
TypeSend('Hello Runescape!');
End;

//MainLoop
Begin
WriteToDeBug;
WriteToRunescape;
End.

O Noez error, Because TypeSend is an Function Out Of SRL and you need to include srl before you can use srl Stuff.
Let's add

{.Include SRL/SRL.Scar}

below

Program MyFirstScript;

so

Program MyFirstScript;
{.Include SRL/SRL.Scar}

That Includes SRL
But we have to 'set it up' so we add SetUpSRL; at the first line of the mainloop, because you have to set it up before you can use it ;)

so now we have

Program MyfirstScript;
{.Include SRL/SRL.Scar}

Procedure WriteToDeBug;
Begin
WriteLn('Hello Word!');//this send this line to the debugbox (Below)
End;

Procedure WriteToRunescape;
Begin
TypeSend('Hello Runescape!');
End;

//MainLoop
Begin
SetUpSRL;
WriteToDeBug;
WriteToRunescape;
End.

So this writes to the DebugBox Hello World! and it type's keys.
but you have to set where it types keys to so drag the 'Cross-hair' to runescape and then release the mouse.

Now add Activateclient;
it will put the Client that you cross haired to the top and it will send the keys to there so lets add ActivateClient;

Program MyfirstScript;
{.Include SRL/SRL.Scar}

Procedure WriteToDeBug;
Begin
WriteLn('Hello Word!');//this send this line to the debug box (Below)
End;

Procedure WriteToRunescape;
Begin
TypeSend('Hello Runescape!');
End;

//MainLoop
Begin
SetUpSRL;
Activateclient;
WriteToDeBug;
WriteToRunescape;
End.


Now it writes the message to the debug box and sends the keys to runescape, but now it always sends the same message.
That is boring so we are going to add a Constant where the player can fill in what he wants to type.

Program MyfirstScript;
{.Include SRL/SRL.Scar}

Const
Message1 = 'Hey This Is My InPut';//A text must always be in a string, will be explained below when explaining variables.

Procedure WriteToRunescape;
Begin
TypeSend(Message1);// Scar reads this Typesend('Hey This Is My InPut') because Message1 contains, 'Hey This Is My InPut'.
End;

//MainLoop
Begin
SetUpSRL;
Activateclient;
WriteToRunescape;
End.


Okay, Done you made your own first script!
Good Job!



Chapter 3
{===================================]
Variables
[===================================}

I only going to explain 4 variables Integer(whole Number) String(Text) Boolean(true or false) extended(decimal integer)
Because this are the basics and these are enough for a good script.
Like i said:
- Integer(whole Number)
- String(Text)
- Boolean(true or false)
- extended(decimal integer)

You have global and local variables

Global :

Program MyfirstScript;
{.Include SRL/SRL.Scar}
Var
WholeNumber:Integer;
Text,KindOfPizza:String;
WantAnPizza:Boolean;
DecimalInteger:extended;

Const
Message1 = 'Hey This Is My InPut';

Local :

Procedure WriteToRunescape;
Var
WhatToSay:String;
Begin
WhatToSay:='Pizza i love it!'
TypeSend(WhatToSay);// Scar reads this Typesend('Hey This Is My InPut') because Message1 contains, 'Hey This Is My InPut'.
End;


Global Can be used everywhere in the script.
Local Can only be used in that procedure or function.
examples:
Global:

Program LMAO;
{.Include SRL/SRL.Scar}
Var
WhatToSay:String;//Global Variable

Procedure test1;
Begin
WhatToSay := 'this will not give an error';//because WhatToSay exist(is 'visible')in the whole script
End;

Procedure test2;
Begin
WhatToSay := 'this will not give an error';//because WhatToSay exist(is 'visible')in the whole script
End;

Procedure test3;
Begin
WhatToSay := 'this will not give an error'; //because WhatToSay exist(is 'visible')in the whole script
End;

Begin
SetUpSRL;
test1;// Note That this only Declares WhatToSay as(:=) 'this will not give an error'
test2;// Note That this only Declares WhatToSay as(:=) 'this will not give an error'
test3;// Note That this only Declares WhatToSay as(:=) 'this will not give an error'
End.

Local:

Program LMAO;
{.Include SRL/SRL.Scar}

Procedure test1;
Var
WhatToSay:String;//This will only be seen in this procedure test1,
//so in test2 there will be an error because the variable WhatToSay Does not exist there!
Begin
WhatToSay := 'this will not give an error';// Not and error because WhatToSay:String; is declared in this procedure.
End;

Procedure test2;
Begin
WhatToSay := 'this will not give an error';//Error
End;

Procedure test3;
Begin
WhatToSay := 'this will not give an error';//Error
End;

Begin
SetUpSRL;
test1;
test2;
test3;
End.


Okay Now You Know What Global And Local Variables are; lets make a script using different kinds of variables!



Program LMAO;
{.Include SRL/SRL.Scar}

Procedure UseAllVariables;
Var//Like you see i use an local var for this because Global is useless and it is slower.
HowManyPizza:Integer;//Whole Number like 1
LengthOfPizzaMan:Extended;// Decimal number like 1.75
NameOfPizzaMan:String;// Piece of text like 'Richard'
PizzaIsDislicous:Boolean;//Just a Boolean True Or False.
Begin
//Change those variables a bit to get another 'Progress report'
HowManyPizza := 1;
LengthOfPizzaMan := 1.75;
NameOfPizzaMan := 'Richard';
PizzaIsDislicous := True;

Writeln('');
Writeln(NameOfPizzaMan+' is the pizza dilivery boy.');
Writeln('he is '+ FloatToStr(LengthOfPizzaMan)+'M long.');
Writeln('I Asked for '+IntToStr(HowManyPizza)+' pizza.');
If PizzaIsDislicous Then Writeln('The Boolean was yes the pizza was dilicous!');
Writeln('');
end;

Begin
SetUpSRL;
UseAllVariables;
End.


Integer is just a whole number;
String is a piece of text 'Text' or 1 char 'A'
Boolean is True or false Note that if you do If TheBoolean Then it auto reads If TheBoolean=true Then for false you do If TheBoolean =False Then
Extendend is an decimal number i've to say that i never used it in my thousands lines of script.


Chapter 4
{=======================================]
SRL & Scar Inbuild Variables(+extra's).
[========================================}
I See so many beginners have problem with what do i have to fill in the box what for coords, they don't know!
With Coords and box i mean this:
If FindColorSpiralTolerance(X,Y,TheColor,ThisBoxX1,Th isBoxy1,ThisBoxX2,ThisBoxY2,Tolerance) Then
In Srl are already a few variables with coords in them and you can use them in your script.
you don't have to pick the coords for the place you are searching.

For The MainScreen, The Place where you click the objects etc.
MsX1, MSY1, MSX2, MSy2

For The MiniMap, The Place where you walk etc.
MMX1, MMY1, MMX2, MMy2

For The MainInventory, Just The Inventory but i call it the main inventory because there is an M before it.
MiX1, MiY1, MiX2, Miy2

For The MainChatScreen, The Place where you Talk With Others just the Chat, same reason as above Main because an M Before it.
MCX1, MCY1, McX2, MCy2

If you look good the second letter changes only //So it is easy to use

so for mainScreen The mSx1
so for miniMap The mMx1
So for mainInventory The mIx1
So for mainCHatscreen The mCx1

not that it is always X1, y1, x2, y2 because that is an box i will explain it in the next chapter.

Summary:
MainScreen: MSX1, MSY1, MSX2, MSy2
MiniMap: MMX1, MMY1, MMX2, MMy2
MainInventory: MIX1, MIY1, MIX2, MIy2
MainChatScreen: MCX1, MCY1, MCX2, MCy2

If FindColor(X, Y, TheColor, MSX1, MSY1, MSX2, MSy2) Then//MainScreen


Var X and Y

This Is Much Used:

Var
X, Y:Integer;


Because if you search for a color you use 2 variables to save the coordinates(coords) at

If FindColor(X, Y, TheColor, MSX1, MSY1, MSX2, MSy2) Then// if it is found the coords are set in the X and Y

Then We Click It.

If FindColor(X, Y, TheColor, MSX1, MSY1, MSX2, MSy2) Then// So if the color is found this results true and then it does...
Mouse(X, Y, 3,3,true);//those 3,3 are the random click because else it will always click the same place and that is not human.
//also The last parameter contains Left:boolean; we say ,True); because we want it to left click if not then ,False);


When you are coding in scar you can do ctrl + space and then a box pop up with a the functions availiable with that
letter(s) if you do Findcolor you let the cursor at the r and do ctrl + space you can see all those findcolor,
findcolorspiral,findcolorspiraltolerance and the most important of it you can see the parameters so you know
what to fill in!


Chapter 5
{===============================================]
SRL Basic FindColor Functions & MouseMoving.
[===============================================}

Lets break down FindColor.

function FindColor(var x, y: Integer; color, xs, ys, xe, ye: Integer): Boolean;
Okay that are the parameterers we have to fill in between those '('')'

Var X, Y That Var is a bit advanced but, that will return the coords into the variable X, Y, the coords will be saved in the variable X, Y.
Note: that you can use every variable in the x you can put in Fish and in the other Dog.

FindColor(Fish, Dog,

Remember that the coords get saved in a variable you have to add:

Var
Fish, Dog :Integer;

After X,Y stands:integer because the coords will be a whole number that also is the reason why Fish And Dog are Integers
To The Next One:
Color that is the color you are searching for

xs, ys, xe, ye: Integer

That is the box to search in, in chapter 4 i told you some already Build-in variables with those box coords in them

Summary:
MainScreen: MSX1, MSY1, MSX2, MSy2
MiniMap: MMX1, MMY1, MMX2, MMy2
MainInventory: MIX1, MIY1, MIX2, MIy2
MainChatScreen: MCX1, MCY1, MCX2, MCy2



): Boolean;

So it will return a true or false because of that you can use it like:

If FindColor(Fish, Dog, 234597, MSX1, MSY1, MSX2, MSy2) Then Mouse(Fish, Dog, 3, 3, True);


Lets Break Down Mouse.
procedure Mouse(mousex, mousey, ranx, rany: Integer; left: Boolean);

mousex, mousey

The Coords where the mouse moves to

ranx, rany: Integer;

Randomness added to the x and y so it will not move always to the same place
Note: all those four are an integer;

left: Boolean);

If you put true it will left click and if you put false it will right click.
Note this does not return a boolean because its not an function it is an procedure and procedure can't return stuff.
only if you put and variable inside it but it can never return something directly.

this is bit hard so you can skip this:

Program Example;

Function ReturnANumber:Integer;//This will return a whole number if i set it to return something
Var
X,Y:Integer;
Begin
X:=10;
Y:=40;
Result:=X+Y;
End;

Begin
ClearDebug;//Clears The Debug Below
Writeln('//////////////////////////////');
WriteLn('It Returns The Number '+IntToStr(ReturnANumber));//I do IntToStr Because its an integer and writeln can only use strings
Writeln('//////////////////////////////');
End.


Lets continue:

If FindColor(Fish, Dog, 234597, MSX1, MSY1, MSX2, MSy2) Then Mouse(Fish, Dog, 3, 3, True);
[/scar]
Lets say that it finds that color on the coords 132,431 then Fish contains the X that is 132 and Dog contains 431`
then we do Mouse(Fish, Dog, 3, 3,True); with randomness and wil Letf click some where at those coords(cause randomness)

Lets Not break Down FindColorSpiral, Why?
Because the parameters are the same as FindColor;

function FindColor(var x, y: Integer; color, xs, ys, xe, ye: Integer): Boolean;


function FindColorSpiral(var x, y: Integer; color, xs, ys, xe, ye: Integer): Boolean;


The only difference is that FindColorSpiral Searches in a spiral.(Handy for object finding)

Here is:
function FindColorSpiralTolerance(var x, y: Integer; color, xs, ys, xe, ye: Integer; Tolerance: Integer): Boolean;

This has the same parameters except for the last parameter Tolerance;
You Know that Rs2 his colors always change now we don't want to pick new colors everytime right!
FindColorTolerance and FindColorSpiralTolerance searches both with tolerance, if you search with an tolerance
it can still find it while the colors change.
like the color red 255 with 10 tolerance could had a range from 225 to 270 btw 10 tolerance does NOT mean:

Color:=1039393
tol:=10
color range:=1039383 - 1039403


20 is good for the most colors.

If FindColorSpiralTolerance(Fish,Dog,234597,MSX1, MSY1, MSX2, MSy2, 15) Then Mouse(Fish, Dog, 3, 3,True);//Search in a spiral and with tol

If FindColorTolerance(Fish,Dog,234597,MSX1, MSY1, MSX2, MSy2, 15) Then Mouse(Fish, Dog, 3, 3,True);//Search WITHOUT a spiral and with tol


MouseMoveFunctions;

Mouse(X, Y, 3, 3, True);//i already explained this. x and y are the coords where the mouse moves 3,3 the randomness it can be 5,5 to it can be anything.
MMouse(X, y, 3, 3);// Note no clicking this moves the mouse to the x and y with randomness 3,3

NOTE: DO NEVER USE ANOTHER METHOD Like MoveMouse or MoveMouseSmooth.
SRL functions Are Okay.

ShowerThoughts
05-09-2008, 07:00 PM
Thanks for all the responds!

and glad you all liked it! :)

batnas
05-09-2008, 08:13 PM
Finally it's here..
It looks ok i have not time to look at it now..

\\Batnas

ShowerThoughts
05-10-2008, 08:59 AM
Thanks for trying to read :p

ShowerThoughts
05-10-2008, 11:25 AM
Standards Updated!

Naum
05-10-2008, 11:48 AM
Nice :)

Haven't i seen this part before? :
Program LMAO;
{.Include SRL/SRL.Scar}

Procedure UseAllVariables;
Var//Like you see i use an local var for this because Global is useless and it is slower.
HowManyPizza:Integer;//Whole Number like 1
LengthOfPizzaMan:Extended;// Decimal number like 1.75
NameOfPizzaMan:String;// Piece of text like 'Richard'
PizzaIsDislicous:Boolean;//Just a Boolean True Or False.
Begin
//Change those variables a bit to get another 'Progress report'
HowManyPizza := 1;
LengthOfPizzaMan := 1.75;
NameOfPizzaMan := 'Richard';
PizzaIsDislicous := True;

Writeln('');
Writeln(NameOfPizzaMan+' is the pizza dilivery boy.');
Writeln('he is '+ FloatToStr(LengthOfPizzaMan)+'M long.');
Writeln('I Asked for '+IntToStr(HowManyPizza)+' pizza.');
If PizzaIsDislicous Then Writeln('The Boolean was yes the pizza was dilicous!');
Writeln('');
end;

Begin
SetUpSRL;
UseAllVariables;
End.

GJ REP-- and reporting you for making such spammy posts!















j/k good work

Method
05-10-2008, 04:47 PM
Grammar kills it, spelling kills it, use of derogatory words kills it, need I go on? There's many other tutorials that explain the same things you're trying to, except those ones are easier to read and more informative. I appreciate the effort, but I can't say it's any more help than the others that are in here.

ShowerThoughts
05-10-2008, 04:51 PM
I use another way then I saw in the others and about grammar and spelling you're right ;)

Nava2
05-13-2008, 01:22 AM
Agreed, love you Hermpie, but try using better spelling and grammar. Readability is key.

Nava2

Dracody
05-13-2008, 03:46 AM
Finally its here :p , its cool , you got nice examples, and I dont think in the other tuts they said the difference between a Function and a Procedure :D really nice tut , I guess you will continue adding stuff to improve it way more.:D

ShowerThoughts
05-17-2008, 12:27 PM
Yeah, any more to add? i will add dtm's etc

kor
05-18-2008, 08:52 AM
Nice guide hermpie ;) i think this will help me, after i figured out what script to do :P *bookmarks* ;)

ShowerThoughts
05-18-2008, 08:52 AM
Thanks,if you want Msn Help add me check my siggy.

Richard
05-18-2008, 08:54 AM
Wow! This is a very full tutorial, rep++ for you.

How long must you have spent on this?

NiCbaZ
05-18-2008, 09:09 AM
wow ty !!!!!!



program HermpieCookie;


procedure WriteWord(TheString:string); //bores
var GoodString,RanLetter:string;
i:integer;
begin
for i:=1 to Length(TheString) do
begin
repeat
RanLetter:=chr(random(26)+65);
if random(2)=1 then
RanLetter:=lowercase(RanLetter);
if random(53)=1 then
RanLetter:=' ';
writeln(GoodString+RanLetter);
wait(10);
until RanLetter=TheString[i];
GoodString:=GoodString+ranLetter;
end;
end;



procedure MeowPussyCatBeatsUpOldMen;
var
i: Integer;
begin
for i := 0 to 3 do
begin
case i of
0: Readln('Why is there no cookie?');
1: Readln('Where is the pics?');
2: Writeln('Congratulations! Give yourself a cookie');
3: Writeln('ya now i know how to make a Hello World!');
end;
end;
end;

begin
MeowPussyCatBeatsUpOldMen;
WriteWord('Hello World');
end.

ShowerThoughts
05-18-2008, 10:00 AM
Thanks,COOOOOOOOOOOOOOOKKIEEEEE!!!! HERE I COME!

Why is it so good i thought the grammar + spelling sucked ;)

faster789
05-21-2008, 01:21 AM
yo it dosent work 4 me ...when i open file and do dat change thing from srl-da other thing a big blak box opens up nd dats it

ShowerThoughts
05-21-2008, 01:53 PM
yo it dosent work 4 me ...when i open file and do dat change thing from srl-da other thing a big blak box opens up nd dats it

WHAT THE HELL, this is not the faster me is knowing....

Cerium
07-04-2008, 01:16 AM
Thanks, I learned a lot:)