C4 - FindColorSpiral
C5 - FindColorSpiralTolerance
C6 - The FindColors Functions
C7 - Finding Colours In Runescape
C8 - Closing Notes
To skip to the part of the tutorial you wish to read, press F3, and then type in the C number which is found above.
C1 - Introduction
If you have just learned to basics of SCAR scripting, and now want to move onto learning how to create scripts for Runescape, then you are in the right place. In this tutorial I am going to show you how to find colours on your screen using SCAR. I will be showing you how to use functions which are implemented into SCAR. Colour finding may sound simple, but it plays an important role in SCAR, as SCAR is a colour based program. On with the tutorial...
C2 - FindColor
Code:
function FindColor(var X, Y : Integer; Xs, Ys, Xe, Ye : Integer) : Boolean;
You may have already heard of this, as this is as simple as colour finding gets. However, this would be perfect for, for example, finding the green colour on my Start Button, as it never changes:
To get the colour you click on the colour picker:
You will now see a box, and a crosshair appear. It will look something like this:
- Mouse: 0, 0 is the X, Y position of the mouse.
- Color: 0 is the color where the crosshair is
To get the colour, I would just put the crosshair over it, and click.
Now you will see something like this:
Code:
Color Picked: 8910240 at (25, 850)
Appear in the debug box. If you don't know what the debug box is, then:
Now...
- Color Picked: 8910240 is the color where the crosshair was when you clicked.
- at (25, 850) is the X, Y coordinates where the colour was picked.
Now we know the colour, let's do something with it. It's all explained inside the script:
SCAR Code:
program New;
{.include SRL/SRL.scar}
var
X, Y : Integer; //Used for finding colours...and pretty much everything else
procedure MouseToColour;
begin
Mouse(X, Y, 0, 0, True);{ This moves the mouse to where the colour was found, and left clicks
If this was Runescape, then you would do:
MMouse(X, Y, 5, 5); This moves the mouse to where the colour was found, with 5 X, Y randomness
if WaitUpText('oins', '750) then This waits a max of 750MS for uptext "oins" to appear. If it does then
begin If there is more than one function called after "then", you need a begin/end;
GetMousePos(X, Y); Gets the position of the mouse and saves it to X, Y
Mouse(X, Y, 0, 0, True); Lefts clicks X, Y with no randomness...Why? We already had 5 in MMouse
end; end; for the begin 3 lines up}
end;
procedure TryFindColour;
begin
if FindColor(X, Y, 8910240, 0, 0, 180, 863) then //If it finds colour(8910240) at any point in
MouseToColour; //0, 0, 180, 863 it will call the MouseToColour procedure
end;
begin
SetupSRL; //Sets up the almighty SRL for use
TryFindColour; //Calls TryFindColour
end.
FindColor is fine for finding colours on games for which the colours don't change, but on Runescape, they do. For this, we need tolerance!
C3 - FindColorTolerance
Code:
function FindColorTolerance(var X, Y : Integer; Xs, Ys, Xe, Ye, Tol : Integer) : Boolean;
Originally Posted by
Dictionary.net
5: Tolerance is a permissible difference; allowing some freedom to move within limits - Also: allowance, leeway, margin
This is like FindColor, except we can use tolerance. This is declared under the extra parameter of Tol. The higher the tolerance, the more tolerant the function will be - duh! Let's use FindColorTolerance to find the colour of logs in our inventory, on Runescape. There are other, better ways to find items in the inventory, but this is just an example.
So, here are our logs:
As shown above, find the colour using the colour finder. Now we have the number in the debug box:
Let's use FindColorTolerance to find it.
A good tolerance for Runescape is between 15 and 30. I normally use 20 myself, and it works fine.
SCAR Code:
program FCT;
{.include SRL/SRL.scar}
var
X, Y : Integer; //X, Y integer for storing coordinated
function DropLogs : Boolean; //Declare DropLogs as a boolean
begin
if FindLogColour then //Calls FindLogColour - no need to call in main loop
begin //If FindLogColour, then it will begin
MMouse(X, Y, 5, 5); //Moves mouse to where colour was found with 5 X, Y randomness
if WaitUpText('ogs', 600) then //Waits max 600MS for uptext "ogs" to appear
begin //If it does, then it will begin
GetMousePos(X, Y); //Stores where mouse is to X, Y
Mouse(X, Y, 0, 0 False); //Right clicks no randomness - already 5 randomness in MMouse
Result:= WaitOption('rop', 600); //Wait max 600MS for option "rop" to appear. If it does, then Result = True
end;
end;
end;
function FindLogColour : Boolean;
begin
Result:= FindColorTolerance(X, Y, 3167854, MIX1, MIY1, MIX2, MIY2, 20); //If it find the colour in the inventory with 15 randomness, then Result = True
end;
begin
SetupSRL; //Sets up SRL
DropLogs; //Calls DropLogs. No need to call FindLogColour as it is called in DropLogs.
end.