Pure1993
2008-04-30 14:57:48
Attention: The tutorial has been expanded! Take a look ^^.
Hi, welcome to another one of my guides (dunno exactly how many i wrote…).
In this tutorial, you will learn: how to add and subtract Integers to arrays (strings work the same way, but there are better examples for Integers), how to apply that knowledge, and in what it will improve your scripts.
To understand this tutorial, you need to know:
-How to set up basic arrays.
-How the color system in SCAR works.
-The basics about SCAR and SRL in general.
If you have ever used Tarajunky's chicken killer, you might have noticed, that the script is constantly adding colors to its color array. If you think about it for a moment, you will realize how ingenious that really is, because the more colors it searches for, the faster and better are the results. Now, if you want to, feel free to take a short break here and look at his script, but I must warn you, you can get quite dizzy after looking at so much code, if you don't understand most of it (if I am honest, 3 months ago i didn't completely understand a single procedure/function :D ). For those of you who just get lost in that script, just continue reading this tutorial, and it will be explained step by step.
Okay, so let's start from scratch:
First of all, I will go over some definitions:
1) It seraches for one of the colorswith a tolerance on 50.
2) If the color was found, it moves the mouse over it.
3) If the correct text appears, it gets the color of that point.
4) We save the array length to the variable "l".
5) We add 1 Integer to the length of the array named "MyColors".
6) We determine the new Integer to be the color which we found with GetColor.
7) We click on the stairs to climb down.
8) We wait a bit so the screen has time to load.
9) we exit so it doesn't save thousands of colors, one which is working is enough for the first round.
10) The script finishes.
That is how to do it. the next time the script will come across the stair, it will also search for that color, and because it was there the last time, there is a higher percision chance, and better speed.
Just a little warning: don't go over 25 Integers in an array, because then it would slow the pc down again, so I would suggest something like this:
[Expansion]
Okay, all this stuff is the dry theory, based upon a boring example, but you know what? I created something interactive, so you can better understand what is happening. Just copy paste this script, and read the instructions on this tut, if the script doesn't explain itself:
Well, that was my tutorial, it is up to you to understand the rest, good luck. :)
Feel free to rep me if you think this tutorial is worth a rep point :D
By: Pure1993
BTW: If I made mistakes, please correct me.
Hi, welcome to another one of my guides (dunno exactly how many i wrote…).
In this tutorial, you will learn: how to add and subtract Integers to arrays (strings work the same way, but there are better examples for Integers), how to apply that knowledge, and in what it will improve your scripts.
To understand this tutorial, you need to know:
-How to set up basic arrays.
-How the color system in SCAR works.
-The basics about SCAR and SRL in general.
If you have ever used Tarajunky's chicken killer, you might have noticed, that the script is constantly adding colors to its color array. If you think about it for a moment, you will realize how ingenious that really is, because the more colors it searches for, the faster and better are the results. Now, if you want to, feel free to take a short break here and look at his script, but I must warn you, you can get quite dizzy after looking at so much code, if you don't understand most of it (if I am honest, 3 months ago i didn't completely understand a single procedure/function :D ). For those of you who just get lost in that script, just continue reading this tutorial, and it will be explained step by step.
Okay, so let's start from scratch:
program DynamicArrayExplanation;
{.include srl/srl.scar}
begin
end. Now, add the variables which we will need:program DynamicArrayExplanation;
{.include srl/srl.scar}
var
MyColor, x, y, i, l: Integer;
MyColors: Array of Integer[0..2];
ColorPointsTPA: TPointArray;
begin
end. Next, define the already found colors:program DynamicArrayExplanation;
{.include srl/srl.scar}
var
MyColor, x, y, i, l: Integer;
MyColors: Array [0..2] of Integer;
ColorPointsTPA: TPointArray;
begin
MyColors[0]:= 602955;
MyColors[1]:= 268838;
MyColors[2]:= 803683;
end. We need some colors to start out with, otherwise, where should the script know which other colors to pick? Next up, is adding the colorfinding and the "for to do" statement:program DynamicArrayExplanation;
{.include srl/srl.scar}
var
MyColor, x, y, i, l: Integer;
MyColors: Array [0..2] of Integer;
ColorPointsTPA: TPointArray;
begin
MyColors[0]:= 602955;
MyColors[1]:= 268838;
MyColors[2]:= 803683;
x := MSCX;
y := MSCY;
FindColorsSpiralTolerance(x,y,ColorPointsTPA,MyColors[i],MSX1,MSY1,MSX2,MSY2,40);
for i:=0 to high(ColorPointsTPA) do
begin
end;
end.Now, let's make it so that we check if the color points it found, are actually of the item we want:program DynamicArrayExplanation;
{.include srl/srl.scar}
var
MyColor, x, y, i, l: Integer;
MyColors: Array [0..2] of Integer;
ColorPointsTPA: TPointArray;
begin
MyColors[0]:= 602955;
MyColors[1]:= 268838;
MyColors[2]:= 803683;
x := MSCX;
y := MSCY;
FindColorsSpiralTolerance(x,y,ColorPointsTPA,MyColors[i],MSX1,MSY1,MSX2,MSY2,40);
for i:=0 to high(ColorPointsTPA) do
begin
MMouse(ColorPointsTPA[i].x, ColorPointsTPA[i].y, 0, 0);
wait(125);
if GetUpText='limb-' then
begin
end;
end;
end. "limb-" is from "climb-down" from the stairs in Lumbridge. Now I will just add the rest and explain it aftrwards:program DynamicArrayExplanation;
{.include srl/srl.scar}
var
MyColor, x, y, i, l: Integer;
MyColors: Array [0..2] of Integer;
ColorPointsTPA: TPointArray;
begin
MyColors[0]:= 602955;
MyColors[1]:= 268838;
MyColors[2]:= 803683;
x := MSCX;
y := MSCY;
FindColorsSpiralTolerance(x,y,ColorPointsTPA,MyColors[i],MSX1,MSY1,MSX2,MSY2,40);
for i:=0 to high(ColorPointsTPA) do
begin
MMouse(ColorPointsTPA[i].x, ColorPointsTPA[i].y, 0, 0);
wait(125);
if GetUpText='limb-' then
begin
MyColor := GetColor(ColorPointsTPA[i].x, ColorPointsTPA[i].y);
l := GetArrayLength(MyColors);
SetArrayLength(MyColors, l + 1);
MyColors[GetarrayLength(MyColors)-1]:= MyColor;
Mouse(ColorPointsTPA[i].x, ColorPointsTPA[i].y, 0, 0, true);
Wait(1500);
end;
end;
end. For those of you who don't understand this, just relax, sit back, and don't get all worked up on this code, because it is quite easy once you get it explained (or, the way i did it, get worked up over it until you are so tired that you get it while falling asleep, but that is the not as easy way ^^). First of all, I will go over some definitions:
SetArrayLength(arrayname: array; length: Integer): boolean;
{-this one can cut or lengthen your array, depending if the number you put in "length" part is bigger or smaller than the already existing array.}
GetArrayLength(arrayname: array): Integer;
{-this one returns the length of your array, for example if your array ranged from [0] to [4], the length would be 5 (0,1,2,3,4).} Now that you know what each one does, I will explain exactly what happened here:1) It seraches for one of the colorswith a tolerance on 50.
2) If the color was found, it moves the mouse over it.
3) If the correct text appears, it gets the color of that point.
4) We save the array length to the variable "l".
5) We add 1 Integer to the length of the array named "MyColors".
6) We determine the new Integer to be the color which we found with GetColor.
7) We click on the stairs to climb down.
8) We wait a bit so the screen has time to load.
9) we exit so it doesn't save thousands of colors, one which is working is enough for the first round.
10) The script finishes.
That is how to do it. the next time the script will come across the stair, it will also search for that color, and because it was there the last time, there is a higher percision chance, and better speed.
Just a little warning: don't go over 25 Integers in an array, because then it would slow the pc down again, so I would suggest something like this:
if GetArrayLength(MyColors) > 20 then
begin
MyColors[0]:=MyColors[20]
MyColors[1]:=MyColors[19]
MyColors[2]:=MyColors[18]
SetArrayLength(MyColors, 3);
end;the last three will be the best to use, because they were picked the latest, and that way it is likelier that the color changes in rs won't affect it as much, because hte color changes are rather subtle.[Expansion]
Okay, all this stuff is the dry theory, based upon a boring example, but you know what? I created something interactive, so you can better understand what is happening. Just copy paste this script, and read the instructions on this tut, if the script doesn't explain itself:
program New;
{.include srl/srl.scar}
var
x,y,i,l, mycolor: integer;
mycolors: array of Integer;
begin
repeat
wait(250);
if IsMouseButtonDown(true) then
begin
getMousePos(x,y);
mycolor := GetColor(x,y);
Writeln('Got color '+IntToStr(mycolor)+' on '+IntToStr(x)+'|'+IntToStr(y));
i:=getarraylength(mycolors);
setarraylength(mycolors, i + 1);
MyColors[i]:=myColor;
end;
if IsKeyDown('a') then
for l:=0 to high(MyColors) do
begin
Writeln(IntToStr(MyColors[l])+' is color '+IntToStr(l));
end;
if IsKeyDown('s') then
begin
MyColors[0]:=MyColors[GetArrayLength(MyColors)-1];
MyColors[1]:=MyColors[GetArrayLength(MyColors)-2];
MyColors[2]:=MyColors[GetArrayLength(MyColors)-3];
SetArrayLength(myColors, 3);
for i:=0 to 2 do
begin
Writeln('MyColors['+IntToStr(i)+']='+IntToStr(MyColors[i]));
end;
end;
Until false;
end.Okay, so what this does is that whenever you click, it adds one Integer to the array, and fills that one in with the color you clicked on. You can review all those colors by simply typing "a". By Typing "s", the first three colors will be replaced with the last three, and then the array will be cut down to the first three colors ([0], [1] and [2]). In this exmaple, switching the colors has no real use, but in a real script, the colors will be more percise in the color finding. But, because this example is not related to color finding at all, it doesn't matter, but it seemed like a good idea to explain what really is going on there. I hope you enjoyed the first expansion to my tutorial [/Expansion]Well, that was my tutorial, it is up to you to understand the rest, good luck. :)
Feel free to rep me if you think this tutorial is worth a rep point :D
By: Pure1993
BTW: If I made mistakes, please correct me.