~~~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:
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:
to this:
SCAR Code:
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:
SCAR Code:
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....
SCAR Code:
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:
SCAR Code:
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:
SCAR Code:
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....
SCAR Code:
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:
SCAR Code:
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:
SCAR Code:
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:
SCAR Code:
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:
SCAR Code:
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:
SCAR Code:
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.