PDA

View Full Version : How to Make a Script



Rune Hacker
06-03-2007, 01:26 AM
~~~How to Make a Script~~~

Table of Contents
1. - The basic setup
2. - Including SRL
3. - A procedure's setup
4. - Your first basic script
5. - Including other files from the SRL folder
6. - Constants
7. - A script using a function from the woodcutting.scar file in SRL
8. - Variables
9. - A basic progress report
10. - Scar's setup
11. - Failsafes
12. - Basic Walking


1. - Lets start it off, this is what your scar window is when it loads up:

program New;
begin
end.

for the first line, you can change the New to whatever you want, it wont matter at all in the script for the second and third line, those are the outline of your "main loop". We will talk about this later.

2. - To use the SRL includes in your scripts, change this:

program New;
begin
end.
to this:
program New;
{.include SRL/SRL.scar}
begin
SetupSRL;
end.

now it will setup srl when the script is started and will add MANY fore functions to add, i will talk a little more about this later.

3. - Now, to make a script do soemthing, you will make a procedure and put functions inside the procedure as such:

Procedure BlahBlah;
begin
Writeln('this message will appear in your debug box at the bottom of your scar window');
end;
You can name the procedure whatever you want as long as it isnt being uses already for a procedure in the srl folder or in the script your making already. Something VERY important about procedures is that for each begin you type, there must be an end; for it. ALWAYS remmeber this! Inside this procedure, it will simply type out a message into the debug box. More about procedure in the next step.

4. - Lets start making a script then, here we go....

program FirstScript;
{.include SRL/SRL.scar}

Procedure AnExampleProcedure;
begin
SetRun(True);
Wait(500 + random(500));
GameTab(4);
Writeln('Run is now set on and you are in your inventory gametab');
end;

begin
SetupSRL;
AnExampleProcedure;
end;

Ok, lets break this down so you understand:
First, I named the program FirstScript, since it is an example of a first script.
Then, I made a new procedure, which in this case, will set your run on, click on your inventory gametab, then type out a message in the debug box. SetRun and GameTab are both pre-made fucntions inside the srl folder. SRL helps a load when making scripts because it simplifies your procedures. To find out what procedures are there, go to (most likely) C:\Program Files\SCAR 3.06\includes\SRL\SRL\core. Then in the main loop (the begin and end. at the end of the script), I setup srl and did the procedure. Your script must end with an "end." with a period and all other ends in the script should just end with a semicolon ;.

So now you know how to set up a script, put a procedure in it, how to add srl, and make it work. Next, I will go into a little bit more detail.

5. - So, what if you want to use procedures and stuff in the C:\Program Files\SCAR 3.06\includes\SRL\SRL\skill folder? Simple do this:

program New;
{.include SRL/SRL.scar}
{.include SRL/SRL/skill/Woodcutting.scar}
begin
SetupSRL;
end.

Now you can use procedures and functions from C:\Program Files\SCAR

3.06\includes\SRL\SRL\skill\Woodcutting.scar

6. - What Scar is mostly made for i believe is finding colors on the screen. If you want, you can make something called a Constant by doing this:

program FirstScript;
{.include SRL/SRL.scar}

const
TheTreeColor = 4153432;
TheMessage = 'Message blah blah';

Procedure AnExampleProcedure;
begin
FindColor(x,y,TheTreeColor,MSX1,MSY1,MSX2,MSY2)
Writeln(TheMessage);
end;

begin
SetupSRL;
AnExampleProcedure;
end;

A constant can be named anything you want. If a const equals a word, make sure you add ' ' and also make sure all constants ends with a ; A constant makes changing colors and words MUCH easier since they are at the top of the script, so i suggest you use them to your advantage, but you don't need to.

7. - So lets make a basic script now that uses this SRL woodcutting include....

program FirstScript;
{.include SRL/SRL.scar}
{.include SRL/SRL/skill/Woodcutting.scar}

const
NormalTreeColor = 4153432;

Procedure ChoppingDownTheTree;
begin
repeat
FindColor(x,y,NormalTreeColor,MSX1,MSY1,MSX2,MSY2)
Mouse(x, y, 1, 1, True);
Wait(5000 + random(2000));
until(invcount = 5)
Writeln('You have 5 items in your inventory now, dropping the logs');
DropAllLogs;
end;

begin
SetupSRL;
repeat
ChoppingDownTheTree;
until(false);
end;

In this script, I repeat the find a color, move the mouse to it and left click, and wait until the inventorycount is 5. For the findcolor function, it will look for the color on the mainscreen (the MSX1 and stuff are pre-set numbers in srl for the size of the main screen, so if you wanted, you could do MMX1,MMy1,MMx2,MMY2 for the minimap, MCX1 and stuff for the main chat, and so on). Looking through the SRL folder will help a lot in finding new functions to use and also looking through other peoples scripts will show many cool functions in srl used. Everything inbetween the repeat and until will be repeat and once whatever you tell the until to be, it will break out of that loop and do whatever is next. In this case, once there are 5 items in your inventory, it will type a message in the debug box and drop all the logs, which is a function in the srl woodcutting script and i needed to include that at the top so i could use it. Also, in the main loop at the bottom, i added a repeat and an until(false);" this means it will repeat eveyrthing inbetween the repeat and the until forever.

8. - Ok, a variables is a word/letter that can be ANY value. Here are what the different things they can be, ill tell you more about them later:

Boolean - True or False
Integer - Whole Numbers
String - Words/letters
Extended - Decimal Numbers

Ok, so here is an example of a script using variables:

program UsingVariables;
{.include SRL/SRL.scar}

var
AttemptsTried : Integer;
IsTheColorFound : Boolean;

const
TheTreeColor = 4153432;

Procedure ClickingATree
begin
if(FindColor(x,y,TheTreeColor,MSX1,MSY1,MSX2,MSY2) )then
begin
Mouse(x, y, 1, 1, True);
AttemptsTried := AttemptsTried + 1; //adds 1 to the Attempts value
IsTheColorFound := True; //will be true of the color is found
Wait(100);
FFlag(5);
end else
begin
Writeln('Color not found');
IsTheColorFound := False;
end;
end;

Procedure DidItFindTheColor;
begin
if(IsTheColorFound = True)then
begin
Writeln('Yay, the color was found');
end else
if(IsTheColorFound = False)then
begin
Writeln('Aww, the color wasnt found this time');
end;
end;

begin
SetupSRL;
repeat
ClickingATree;
DidItFindTheColor;
until(false);
end.

So as you can see, I used a boolean value for the IsTheColorFound variable since it resulted in True or False, and for the AttemptsTried variable, it resulted in whole numbers so it is an Integer value. Variables are also used in progress reports a lot to show you the progress of the script is going.

9. - Ok, every script should have a progress report to show how long and well it has been working, and they are very easy to use. Here is an example of a basic progress report:

Procedure ProgressReport;
begin
ClearDebug;
Writeln('//---------- Title Of Script ----------\\');
Writeln('| Ran for '+TimeRunning);
Writeln('| Attempted '+IntToStr(AttemptsTried )+' Times');
Writeln('\\-----------------------------------//');
end;

Progress reports should look neat, tidy, and organized. They show how long the script has been running by using the TimeRunning fucntion from srl, and in this example, AttemptsTried is a variable that your script has been adding up, and using the IntToStr will allow it to be typed (more about this in the Globals.scar file in the srl core folder, and the IntToStr is used ot make the Integer(Int) value to become a String(Str) value so it can be typed as a word). Also, the ClearDebug fucntion will clear the debug box so your debug box wont get too crowded.

10. - Now you see how to use functions from SRL, how to make a basic script, now ill go into how Scar works.

To start, you might want to memorize these key bindings for scar(hold all 3 buttosn down at once):
Play is Ctrl + Alt + R (to play the script)
Pause is Ctrl + Alt + A (to pause the script so you can start from where you left off(not when the script is closed)
Stop is Ctrl + Alt + S (to stop whatever script you are running completely)
Pick Color is Ctrl + Alt + P (to get the color and coords of wherever you click)

To find a color on the screen such as a rock color, a tree color, ect, just hold down Ctrl + Alt + P all at once. The screen will freeze and then you can click somewhere to get the color. The screen will unfreeze once you click. The color and coords will appear in your debug box such as:
Color Picked: 6141021 at (575, 176)
The coords where i clicked (also knows as x,y) are 575,176 in this example and the color i clicked was 6141021.

To get coords, first drag the crosshair icon on scar onto the runescape client. Otherwise you will be getting the coords on your computer instead of on the runescape client.

11. - Now then, to make good scripts, you will want failsafes and backup plans if the first thing doesnt work. Lets look at this procedure:

Procedure UsingAFailsafe;
begin
if(FindColor(x,y,4153432,MSX1,MSY1,MSX2,MSY2))then
begin
Mouse(x, y, 1, 1, True)
end else
begin
Writeln('The color was not found, terminating script');
TerminateScript;
end;
end;

For this example, if it finds the color on the main screen, it will click it, but if its not found, then it will type a message in the debug box and terminate the script. In scripting, you will NEVER EVER EVER want something that can repeat forever, always put in backup options if the first thing doesnt work!

12. - So now you have the basic foundation on how to make a script, lets move on even more into more advanced stuff such as walking

The best way to walk in SRL is probably symbols, clicking, and DTM's. I will go into DTM's later, but for now, ill show you how to find symbols and how to walk by clicking. Here is a simple procedure on how to find the water source symbol:

Procedure FindingTheWaterSymbol;
begin
if(FindSymbol('water'))then
begin
Mouse(x, y, 2, 2, True);
Wait(1000);
FFlag(5);
end else
begin
Writeln('The symbol was not found, using backup click')
Mouse(626, 39, 2, 2, True);
Wait(1000);
FFlag(5);
end;
end;

So in this example, if it finds the water symbol, it will click it, wait 1 second, then wait until the flag on the minimap is gone (more about functions such as FFLag and stuff in your SRL folder). If it doesn't find the symbol though, it will do a "blind click" since its just clicking in the general direction of where the symbol usually is(about how to find coords was stated above).

To find out all the valid symbols to look for, look here: C:\Program Files\SCAR 3.06\includes\SRL\SRL\core\symbols.scar

More To Come~~~~~~~~~~~~~~

Best way to learn i think is looking through the SRL folder and looking through other peoples scripts.

*I have one golden rule I would like everyone to follow while scripting though:
NEVER use anything you dont know, never copy a procedure from another script, always only use what you know. Many people will just copy stuff from other scripts and start ranting about how they cant get something to work since they dont know how it works. You might think "if it works in this script, why wouldn't it work in mine", it is best and safest to make everything by yourself and if you get stuck, you can look in other scripts, but dont just copy and paste from other scripts a lot.

Coming later:
- More detail about functions, procedures, and features of SRL/Scar
- case of statements
- Multi-players
- A little more about the basics of how to walk
- RadialWalk
- Finding Bitmaps
- Finding DTM's

if you have any questions, feel free to message me on msn or aim.

If there is anythign that should be added, please say so and I will.

Rune Hacker
06-03-2007, 01:27 AM
I just typed this up in a couple minutes so it has errors and stuff, I was bored lol. Much more to come when I have the time.

kooldude
06-03-2007, 04:54 AM
Nice tut For Begginers, very good explantions.

Rune Hacker
06-03-2007, 07:49 AM
Ty, i still have a lot mroe to add and improve, but i think this is a good start for like less than 30 min of work lol.

BobboHobbo
06-03-2007, 10:03 AM
Nice guide.

Rune Hacker
06-03-2007, 08:26 PM
Nice guide.
Cool, glad you liked it.

Inf456
06-05-2007, 12:56 AM
Thanks, this is helping me a lot with my first script, a Yew Cutter.

JAD
06-05-2007, 02:02 AM
Even though there are over 5000 different tuts explaining this stuff/the upcoming stuff already, it's still a pretty good tut :p

7. - A scritp using a function from the woodcutting.scar file in SRL

Fix it! :p

Rune Hacker
06-10-2007, 04:07 AM
Even though there are over 5000 different tuts explaining this stuff/the upcoming stuff already, it's still a pretty good tut :p

7. - A scritp using a function from the woodcutting.scar file in SRL

Fix it! :p
I didn't eve nbother to read the other tuts that were out there, I didn;t notice lol.

And im sorry, it was typed up fast and i made a spelling error, PLEASE forgive me all mighty JAD :duh:

JAD
06-10-2007, 04:44 PM
I didn't eve nbother to read the other tuts that were out there, I didn;t notice lol.

And im sorry, it was typed up fast and i made a spelling error, PLEASE forgive me all mighty JAD :duh:

Lol :p Just thought I'd tell you so people don't go into an uncontrollable rage like I did when I saw that spelling error lol :p

RICHO
06-20-2007, 07:33 AM
In number 8 when compiling it says ...

Failed when compiling
Line 5: [Error] (17672:1): Duplicate identifier 'Attempts' in script

whats the problem ?? i treid mine and it didnt work .. i pasted your it said the same thing also .. plz help or fix the problem .. ?

Drake-o
06-20-2007, 08:10 PM
it means you have a procedure or similar with the same name as an actual word used in the "code" (for want of a better word), i think that if you change the name of the variable Attempts to something else, and make sure you then change this in the ClickingATree procedure. I think this should work can someone with more experience with me confirm?

Edited for i am teh noobzor.

bigbadboy2
08-14-2007, 09:16 PM
tyvm guide really helped me to make automine
:D

killer man 007
08-15-2007, 05:49 AM
Good tutorial! Lots of help!

Pancakes
08-15-2007, 06:32 AM
Nice addition Rune Hacker.

This covers pretty much everything, sure, it could be a little better in some parts, as you said... but I'm not critisizing at all.

I was going to make something like this, but this sums it up quite nicely.

dvdcrayola
08-15-2007, 06:49 AM
Very understandable, good tut

could have used it before i learned... :( thats ok, it will help others! ;)

steffo2k7
09-04-2007, 05:41 PM
hi great tut ive just started a script would i be able to like change stuff so it would mine ore and drop it insted of wood eg


program new;
{.include SRL/SRL.scar}
{.include SRL/SRL/skill/mining.scar}

const
normalorecolor = 7303288

Procedure mingingtheore
begin
repeat
FindColor(x,y,Normalorecolor,MSX1,MSY1,MSX2,MSY2)
Mouse(x, y, 1, 1, True);
Wait(5000 + random(2000));
until(invcount = 5)
Writeln('You have 5 items in your inventory now, dropping the ore');
DropAllOre;
end.

begin
SetupSRL;
repeat
mineore;
until(false);
end;

somthin a bit like that

Elmo_Time
09-05-2007, 12:26 AM
nice thread im trying to make my own one now =]

ultima2007
09-09-2007, 07:41 AM
Man I still feel lost lol, I'm getting there I've read a lot of tutorials and flipped through the Pascal computer language
now all I have to do is make myself a script! :)

anthony123123123
09-13-2007, 07:03 PM
i am new so i still odn't rely know what to do

Autiep03
01-19-2008, 07:00 PM
Ty, i still have a lot mroe to add and improve, but i think this is a good start for like less than 30 min of work lol.

Ha! All that in 30 minutes? Impressively thorough.

asdf101
01-20-2008, 03:02 PM
Great tutorial. I thought the walking part very helpful.

Sniper777
01-20-2008, 11:02 PM
pretty good tut! keep up the good work :)

bradfootball33
01-20-2008, 11:23 PM
thank you so much for the help. im getting started right now!

scarsk8r
02-02-2008, 09:06 PM
tyvm guide really helped me to make automine
:D

so does ur script work? if so can u post it on here? or email it to me? i'd greatly appreciate it seeing as how all the premade ones on google never work, and i dont get how to make them based off of these tutorials.

markmccain
05-24-2008, 03:12 AM
this was very useful. I was looking for a great example of the Walk procedure and this really helped. I would have liked if you when a bit more into depth about the walking but it gave me a basic idea.

The Shiz
06-01-2008, 04:06 AM
:duh:
Now, I know what im doing.
Thxs

itSchRis917
06-01-2008, 04:16 AM
02-02-2008, 03:06 PM Nice gravedig mccain

FrostByte
06-09-2008, 04:50 AM
I found this very usefull, thanx.

rontherhino
02-22-2009, 09:59 PM
nice basic tutorial

lysolman00
02-25-2009, 03:47 PM
Thanks! I'm starting to work on my own script. I always thought it would be harder. Now, after all, it doesn't seem that bad. There were some parts not covered but after all this is for the absolute beginner scripter. Thanks again for the well written guide.

blackslinga
05-04-2009, 07:09 AM
Unknown identifier 'x' in script
=$ ?