SRL Archive - OSR Beginner Scripting Tutorials

Basic Color Finding


Kik

2007-08-13 13:25:11

Basic Color Finding
By KikWit
Welcome to my tutorial on color finding! I hope that this will help beginning scripters understand how color finding works, and how useful it can be. This tutorial will go over the basics of color finding functions and how to use them in your scripts. I am somewhat of a beginning scripter, so please bear with me!

What is Color Finding?

Color finding is just that - finding colors on the runescape screen and then recording their position. There are many different functions that use color finding, but this tut will only go over the basics. Here we go! I will assume that you understand some basics of scripting, but I will try to explain as much as possible.

First Off, x and y coordinates. For those of you who have taken algebra,you probably know that they are two coordinates that make up a grid on the runescape map. The top left corner is (0,0) and the bottom left corner is approx.(750,500). Correct me if I am wrong - you can find coordinates by opening up a scar window, dragging the crosshairs to RS, and then switching to the RS screen and hitting ctrl+p. This will give you the coordinates of where the mouse is and the color (I will go over this more later), and it will print them into the SCAR debug box.


Variable Index

x - the x coordinate of the color

y - the y coordinate of the color
color - the color you are searching for

xs, ys - the x and y coordinates of the point on the RS screen to start searching for the color (the top left corner)

xe, ye - the x and y coordinates of the point on the RS screen to stop searching for the color (the bottom right corner)

tol - the tolerance of the color to search for. The higher the tolerance, the wider the range of colors it will search for. EX: If you have color 24868961 and you have a tol of 5, it might search for colors 23868961 to 26868961 (I do not know exactly how wide of a range of colors the tolerance searchs for - this is an example). This is only used in the FindColor functions that use the tol variable.


FindColor(x, y, color, xs, ys, xe, ye)

This is the simplest form of color finding there is. It searches for one color with no tolerance and records the color position at x and y.

FindColorSpiral(x, y, color, xs, ys, xe, ye)

This works much like FindColor, except instead of searching from left to right it searches in a spiral. I find it works a tiny bit faster than FindColor, but it is very minimal and will make barely any difference in your script. EDIT: sorry, i was wrong. Spiral works slower, contrary to what i though.

FindColorTolerance(x, y, color, xs, ys, xe, ye, tol)

This is one of the best color finding functions, simply because it has tolerance. Jagex changes their colors slightly every time you log in (and sometimes while you are logged in) to try and fool bots who only search for an exact color. This way, you will most often find a color you are searching for. For those who have never used tolerance, I would say that 4 or 5 is good for a miner - just to ballpark it (in case you had no clue if it should be 1 or 100!).

FindColorSpiralTolerance(x, y, color, xs, ys, xe, ye, tol)

This, again, is just like FindColorTolerance except it searches in a spiral.



Now, for using FindColor in your script! FindColor is most often used with an if() statement. Here's an example.

if(FindColor(x, y, 14215660, 0, 0, 600, 300))then
begin
//What to do if scar finds the color
end

This will search for the color 14215660 from (0,0) to (600,300). As you can see, you leave the x and y to tell SCAR what variables to put the coordinates of the color in. We can use these variables later to tell SCAR where to click a mouse. Now lets look at how we can use this in a more functional script.


if(FindColor(x, y, 2324021, 0, 0, 600, 300))then
begin
Mouse(x, y, 1, 1, true); //Will move and left-click on (x,y) with a randomness of 1 pixel
Wait(3500); //waits 3500 milliseconds (3.5 seconds)
end

This script could be part of an extremely basic power miner. It searches for the an iron ore color and then clicks on it. It will then wait 3500 ms. This could also be put into a repeat…until loop (check out 'Loops by Pancakes' for a great loops tutorial).

The same idea can be applied for a script with tolerance.

if(FindColorSpiralTolerance(x, y, 2324621, 0, 0, 600, 300, 5))then //The 5 is tolerance
begin
//Put what you want it to do here
end

Here's an entire script for a simple powerminer that mines and drops (no antiban), to give you an idea.

program New;
{.include SRL\SRL.scar}
const
TimetoWait = 2500;

var x, y: integer;

//Mines Iron Ore until Inv is full
procedure MineOre;
begin
repeat
if(FindColorTolerance(x, y, 2503507, 0, 0, 700, 500, 4))then
begin
Mouse(x, y, 0, 0, true);
Wait(TimetoWait-200);
end
Wait(200);
until(InvFull)
end;

//Main Loop//
begin
repeat
MineOre;
DropTo(2,28);
until(false);
end.

WARNING - DO NOT SEARCH FOR COLORS EVERY SECOND. Whenever you search for a color, it has to slow down your script, so if you are searching for colors constantly, RS will lag. Here's an example of a bad script. If it does not find the color, it will keep on searching and searching until it finds it.

Bad, Laggy Script

repeat
if(FindColor(x, y, 203920, 0, 0, 500, 400))then
begin
Mouse(x, y, 0, 0, true);
wait(2000);
end
until(false)

Here is a much better example. In this one, it waits one fifth of a second between searches for color, decreasing lag.

Good, Less Laggy Script

repeat
if(FindColor(x, y, 203920, 0, 0, 500, 400))then
begin
Mouse(x, y, 0, 0, true);
wait(1800);
end
wait(200);
until(false)

This comes to an end with my tutorial. I hope this helps you with your scripting because I know that it would have helped me. Please leave comments/concerns, or any errors I have made (please do!).

Thanks for reading! :D

Please post Feedback and Comments!!!

lordsaturn

2007-08-14 23:34:07

Very detailed. Good for beginners.

CodyTheBaddie

2007-09-26 23:18:39

From: lordsaturn
Very detailed. Good for beginners.


Agree'd.

li_HAM1

2007-10-02 00:51:21

thankyou finally makes total sense

migaeler1

2007-12-23 10:28:48

good color TUT for beginners.

MasterOfStuff

2008-01-17 13:33:05

I never knew what the tolerance was for the color finding. Makes it easier now to write basic procedures.

xKYLESTEGALx

2008-02-02 16:03:44

Wow, best color finding script i have seen yet. You did a very good job!

-xKYLESTEGALx

bullzeye95

2008-02-02 17:01:18

FindColor is actually faster than FindColorSpiral ;)'

And good tutorial.

gamer 5

2008-02-02 17:32:42

I guess it will help the noobs, because scripting is bascially finding colors and cliking them. :)

Mariuswbz

2008-02-06 15:01:59

Nice tut.

I really love your tuts.

DeSnob

2008-03-30 07:56:48

i finally know how to use color finding to click on aubury or w/e and tele to mines :)

john smith

2008-03-30 20:00:47

thanks, i never could figure out what to call the color before, the numbers or whatever, this helps sooo much

The Mayor

2008-04-04 04:31:26

Very nice tut! Helped so much Thankyou!

2pacfan

2008-04-24 12:55:06

Ty vm helped me a lot:)

lemonfuzz

2008-05-23 22:50:24

program New;
{.include SRL\SRL.scar}
const
TimetoWait = 2500;

//Mines Iron Ore until Inv is full
procedure MineOre;
begin
repeat
if(FindColorTolerance(x, y, 725784, 0, 0, 790, 560, 4))then
begin
Mouse(x, y, 0, 0, true);
Wait(TimetoWait-200);
end
Wait(200);
until(InvFull)
end;

//Main Loop//
begin
repeat
MineOre;
DropTo(2,28);
until(false);
end.

After I run this I get this…
Line 10: [Error] (12664:23): Unknown identifier 'x' in script

edit:nvm fixed it I needed

var
x, y : Integer;

markmccain

2008-05-24 03:14:12

Really good script. I have been trying to write my own and this tutorial was huge help. its an easy concept but without a tutorial i don't know i would have been able to figure it out.

nickrules

2008-06-01 09:52:22

thanks, this helped a lot

Griff

2008-06-03 21:58:00

I've been useing the procedure 'Mouse' in my sciprt for quite some time. It has all of a suddne stopped working… Anyone know why?

shynie

2008-10-28 12:02:26

Woah, thanks for this! This really helped me get my script up and running ^_^

+rep

kitchenrange

2008-10-28 12:16:07

It came a couple of days late for me, but I just wanted to show my appreciation anyway. It takes time to make tutorials.

h4jgyvis

2012-07-10 13:15:16

From: Kik
Basic Color Finding
By KikWit
WARNING - DO NOT SEARCH FOR COLORS EVERY SECOND. Whenever you search for a color, it has to slow down your script, so if you are searching for colors constantly, RS will lag. Here's an example of a bad script. If it does not find the color, it will keep on searching and searching until it finds it.

Bad, Laggy Script

repeat
if(FindColor(x, y, 203920, 0, 0, 500, 400))then
begin
Mouse(x, y, 0, 0, true);
wait(2000);
end
until(false)

Here is a much better example. In this one, it waits one fifth of a second between searches for color, decreasing lag.

Good, Less Laggy Script

repeat
if(FindColor(x, y, 203920, 0, 0, 500, 400))then
begin
Mouse(x, y, 0, 0, true);
wait(1800);
end
wait(200);
until(false)


Hello,

First of all, thank you for taking the time to write this helpful tutorial.

I'm very new to SRL and I have a question. I can see how constantly clicking would make RS lag, and how constantly searching for a color would make your computer lag, but how does searching make RS lag?

Thanks!

speedster

2012-10-16 22:03:30

For anyone else reading look in to : CountColorTolerance , it's quite helpful :)

Sin

2012-10-16 22:05:40

From: h4jgyvis
Hello,

First of all, thank you for taking the time to write this helpful tutorial.

I'm very new to SRL and I have a question. I can see how constantly clicking would make RS lag, and how constantly searching for a color would make your computer lag, but how does searching make RS lag?

Thanks!


Your computer shovels more resources towards Simba, and less to Runescape.