Custom Item, Button, etc. Clicking Using FindColorTolerance
Hello everyone,
I have been wanting to put out a very simple and basic tutorial for anyone who is having trouble click on certain items either on the main screen, in the inventory or wherever else you may want to click.
So, for this tutorial, I am going to use the example of clicking the Combat Tab.
Getting The First Colour
Ok, the first thing that you will want to do is get to the combat tab.
There are a few ways of doing this. You could us the:
Which is what the majority of script writers use, mainly because its a part of the SRL Include. But we are going to make our own version of getting there.
So, what we are going to start off by doing is getting the colour of the swords. To do this, we will need to use the Colour Finder Tool in your Simba Tool Bar.
That looks like this:
Use that on the two swords and you should get a colour. The colour I got was 1215727 (The Gold Colour). Now, if you have something different, don't freak out. Keep your colour and see if it works.
Coordinates
Now, we need to find the Coordinates of the Combat Tab. My little method of figuring it out is by doing this:
1. Click and Drag the Select Client Tool onto the client you are using (Preferably using SMART. That is the only way to get the following to be accurate).
Looks like this:
2. Put your cursor on the BOTTOM RIGHT of the two swords. Should look like this:
3. Now, if you have Simba still open, you should be able to see Coordinates at the bottom left of Simba. Those should look like this:
Now, if you take a look at that, you should be able to notice that the first integer, which is 545, is the X integer. The other number, which is 328, is the Y integer. So, those are the Coordinates of the Bottom Right corner of the Combat Tab.
4. Here is the crazy part. Over my time of scripting, I have noticed that the client window is a bit strange, so you kind of have to play with the coordinates. This is because of the Navigation Bar at the top of the client.
Originally Posted by
The Mayor
it might be useful to say why you subtract 50 from the Y coords. It's because of the NavBar at the top:
*Originally forgot to mention! XP
So, what i usually do is subtract 2 from the X value to get your actual X value that you should use in your script. Then, subtract 53 from your Y value to get your actual Y value that you will use in your script.
So, you should remember these two equations:
Code:
X - 2 = Actual X
Y - 53 = Actual Y
What we will do here is now do the subtraction. We will now take 545 and subtract 2 to get 543. We will then take 328 and subtract 53 to get 275.
Code:
545 - 2 = 543
328 - 53 = 275
These are the Coords we will use in our script. Now, make sure you take note of these. I usually open a notepad and put them in there.
Now, do the same with the Top Left corner of the Combat Tab. The coordinates you should end up getting should be something around 523 and 168.
FindColorTolerance
What we have so far is our colour, bottom right corner coordinates and our top left corner coordinates of our combat tab.
What we will do next is now use our new little friend named FindColorTolerance.
FindColorTolerance is what we will use to find our colour on the two swords and then make it click them.
So, the basics for FindColorTolerance is:
Simba Code:
FindColorTolerance(var x, y: integer; color, xs, ys, xe, ye, tol: integer): boolean
Now, this may look a bit confusing, but have no worries, it is really simple. We will start with our colour. We will want to make it look like this:
Simba Code:
FindColorTolerance(x, y, 1215727, xs, ys, xe, ye, tol: integer)
What i did here was remove a few unnecessary items that were there. We removed the "var" because the variables we are going to use are X and Y. Remember that since they are variables, we will have to declare them at the beginning of the procedure.
So, your script should actually look like this:
Simba Code:
program DeclarePlayers;
{$DEFINE SMART}
{$i srl/srl.simba}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
Players[0].Name := ''; // Username
Players[0].Pass := ''; // Password
Players[0].Nick := ''; // 3-4 lowercase letters from username; used for random event detection
Players[0].Active := True; // Set to true if you want to use Player 0
Players[0].Pin := ''; // Leave blank if the player doesn't have a bank pin
end;
procedure CombatTab;
var
x, y : Integer;
begin
if not LoggedIn then Exit;
FindNormalRandoms;
FindColorTolerance(x, y, 1215727, xs, ys, xe, ye, tol: integer);
end;
begin
ClearDebug;
SetupSRL;
DeclarePlayers;
LoginPlayer;
CombatTab;
end.
Notice the "if not LoggedIn then Exit;" and "FindNormalRandoms" lines? The first one Exits the procedure if you are not logged in. The FindNormalRandoms line checks if the player is in a random event, has the squeal of fortune open, etc.
Back to FindColorTolerance, if you try to compile the script, you get an error. That is because your xs, ys, xe, ye are not actually supposed to be there. What you want to do is replace those with the coordinates that we found earlier. For the xs and ys, we want to put in the second coordinates we found; they are 523 and 168.
We will want to replace the xe and ye with the first coordinates that we found; they are 543 and 257.
Yes, it seems weird but it works.
So, now you should have this:
Simba Code:
program DeclarePlayers;
{$DEFINE SMART}
{$i srl/srl.simba}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
Players[0].Name := ''; // Username
Players[0].Pass := ''; // Password
Players[0].Nick := ''; // 3-4 lowercase letters from username; used for random event detection
Players[0].Active := True; // Set to true if you want to use Player 0
Players[0].Pin := ''; // Leave blank if the player doesn't have a bank pin
end;
procedure CombatTab;
var
x, y : Integer;
begin
if not LoggedIn then Exit;
FindNormalRandoms;
FindColorTolerance(x, y, 1215727, 523, 168, 543, 257, tol: integer);
end;
begin
ClearDebug;
SetupSRL;
DeclarePlayers;
LoginPlayer;
CombatTab;
end.
Now, you will see the Tol: integer part become highlighted if you again try to compile or run the script.
Tol is your tolerance. You want to replace that with a number. The higher the number, the more colours can be clicked, the lower the tolerance, the less amount of colours can be clicked.
So, for the fun of it, we will set it to 15.
So, your FindColorTolerance should look like this:
Simba Code:
FindColorTolerance(x, y, 1215727, 523, 168, 543, 257, 15);
Clicking Your Tab
Now, clicking your tab is very simple. To start, I personally like to put my FindColorTolerance section in an If and Then statement. It basically says that if you find this, then do this.
So, you should have this as your procedure:
Simba Code:
procedure CombatTab;
var
x, y : Integer;
begin
if not LoggedIn then Exit;
FindNormalRandoms;
if FindColorTolerance(x, y, 1215727, 523, 168, 543, 257, 15) then
begin
end;
end;
The begin and end is there because what you are putting in there is the clicking and waiting.
Next we will want to have the mouse move to the colour. So we use
This moves the mouse directly to the colour found.
We then want to click the colour (and the Combat Tab). To do so, we will use
Then, just for safety, we will add a wait. I will use this:
All together, the procedure should look like this:
Simba Code:
procedure CombatTab;
var
x, y : Integer;
begin
if not LoggedIn then Exit;
FindNormalRandoms;
if FindColorTolerance(x, y, 1215727, 523, 168, 543, 257, 15) then
begin
Mmouse(x, y, 0, 0);
ClickMouse2(Mouse_Left);
wait(990 + Random(789));
end;
end;
FailSafe
Now that we have the majority of the procedure done, we will want the script to do something if it cant find the colour.
You can have the script do a few different things. If you would like, you could choose another colour and have the script look for that colour if the previous one could not be found. We could also just terminate the script to be safe or do a blind click.
What we will do here is just terminate it for the sake of finishing the tutorial, but feel free to find another colour or just do a blind click.
So, to terminate the script in a failsafe, it should look something like this:
Simba Code:
procedure CombatTab;
var
x, y : Integer;
begin
if not LoggedIn then Exit;
FindNormalRandoms;
if FindColorTolerance(x, y, 1215727, 523, 168, 543, 257, 15) then
begin
Mmouse(x, y, 0, 0);
ClickMouse2(Mouse_Left);
writeln('Clicked the Combat Tab! YAY!');
wait(990 + Random(789));
end else
begin
writeln('Did not find colour. Terminating Script');
Terminatescript;
end;
end;
And thats it!
Running It
Your entire script should now look like this:
Simba Code:
program DeclarePlayers;
{$DEFINE SMART8}
{$i srl/srl.simba}
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
Players[0].Name := ''; // Username
Players[0].Pass := ''; // Password
Players[0].Nick := ''; // 3-4 lowercase letters from username; used for random event detection
Players[0].Active := True; // Set to true if you want to use Player 0
Players[0].Pin := ''; // Leave blank if the player doesn't have a bank pin
end;
procedure CombatTab;
var
x, y : Integer;
begin
if not LoggedIn then Exit;
FindNormalRandoms;
if FindColorTolerance(x, y, 1215727, 523, 168, 543, 257, 15) then
begin
Mmouse( x, y, 0, 0);
ClickMouse2(Mouse_Left);
writeln('Clicked the Combat Tab! YAY!');
wait(990 + Random(789));
end else
begin
writeln('Did not find colour. Terminating Script');
Terminatescript;
end;
end;
begin
ClearDebug;
SetupSRL;
DeclarePlayers;
LoginPlayer;
CombatTab;
end.
Now that everything is ready to go, what you should do is fill out the declare players and then press the green play button at the top.
What should happen is a SMART client shows up and should login your player. Then it should click the Combat tab.
If it successfully clicked the Combat Tab, you should get this:
Code:
Clicked the Combat Tab! YAY!
Successfully executed.
And if it does that, then congratulations, you have successfully learned and put to use the FindColorTolerance function and clicking methods.
Now, you can go on your way and script your own scripts that involve clicking in specific places.
Conclusion
So, hopefully you have learned how to use the FindColorTolerance Function and a few extra things along the way.
There are tons of different ways you can use FindColorTolerance to your advantage. As another example, I made a procedure that Home Teleports to Lumbdridge.
Simba Code:
procedure HomeTele;
var
x, y : Integer;
begin
GameTab(tab_Magic);
wait(990 + Random(789));
if FindColorTolerance(x, y, 4863772, 651, 213, 675, 235, 15) then
begin
Mmouse( x, y, 0, 0);
ClickMouse2(Mouse_Left);
writeln('Hat selected.');
wait(RandomRange(340, 568));
end;
if FindColorTolerance(x, y, 15655386, 651, 249, 675, 273, 15) then
begin
Mmouse( x, y, 0, 0);
ClickMouse2(Mouse_Left);
writeln('Teleport Tab selected.');
wait(RandomRange(340, 568));
end;
if FindColorTolerance(x, y, 15655386, 555, 284, 588, 322, 15) then
begin
Mmouse( x, y, 0, 0);
ClickMouse2(Mouse_Left);
writeln('Home Teleport selected.');
wait(RandomRange(840, 1568));
end;
if FindColorTolerance(x, y, 8943966, 307, 218, 339, 252, 15) then
begin
Mmouse( x, y, 0, 0);
ClickMouse2(Mouse_Left);
writeln('Lumbridge selected.');
wait(RandomRange(15000, 25000));
end;
end;
If you take that and put that inside of a script and command the script to run the procedure, it should end up teleporting you to Lumb. XD
Congratz! Your done!
If you have any questions, feel free to post them! I will answer them as fast as I can! XD
I hope this was useful and please let me know if there are any grammatical or spelling errors that I can fix.
*Note: Colour is how i spell it... its not a spelling error! XD
If there is a better way of formatting this, feel free to let me know also. I would like to make it as easy to read as possible.
Also, if there is anything I have gotten wrong or missed, please let me know about those, too!
Feel free to also Comment, +Rep, or do whatever you want! XD
Thanks for reading and hope this helped you!
StickToTheScript