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.
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.
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.
Here's an entire script for a simple powerminer that mines and drops (no antiban), to give you an idea.
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
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
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!!!
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
endThis 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
endHere'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!!!