PDA

View Full Version : Custom Item, Button, etc. Clicking Using FindColorTolerance



StickToTheScript
04-21-2013, 05:42 AM
Custom Item, Button, etc. Clicking Using FindColorTolerance
Written By: StickToTheScript (http://villavu.com/forum/member.php?u=81500)

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.


http://i.imgur.com/136iRME.png



There are a few ways of doing this. You could us the:

GameTab(tab_Combat);

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:

http://i.imgur.com/64r5rHQ.png

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:

http://i.imgur.com/gnHxwpq.png


2. Put your cursor on the BOTTOM RIGHT of the two swords. Should look like this:

http://i.imgur.com/1Nuh55J.png

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:

http://i.imgur.com/KGeK9u3.png

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.



it might be useful to say why you subtract 50 from the Y coords. It's because of the NavBar at the top:

http://puu.sh/2Fqef.jpg
*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:



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.



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:

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:

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:

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:

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:

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:

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
MMouse(x, y, 0, 0);

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
ClickMouse2(Mouse_Left);

Then, just for safety, we will add a wait. I will use this:

wait(990 + Random(789));


All together, the procedure should look like this:

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:

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:

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:


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.

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

Chris!
04-21-2013, 05:49 AM
From a rough run through of this, it's very nice!

If you want to make the formatting better, please feel free to read through my guide. You can find it here (http://villavu.com/forum/showthread.php?t=94074).

I spell colour like you do aswell. :)

StickToTheScript
04-21-2013, 06:00 AM
From a rough run through of this, it's very nice!

If you want to make the formatting better, please feel free to read through my guide. You can find it here (http://villavu.com/forum/showthread.php?t=94074).

I spell colour like you do aswell. :)

Thanks! I will definitely make changes!

Very useful! XD

dzpliu
04-21-2013, 06:04 AM
nice easy to understand tutorial to find basic objects with few/single color.

StickToTheScript
04-21-2013, 06:12 AM
nice easy to understand tutorial to find basic objects with few/single color.

That was my goal! XD

Sjoe
04-21-2013, 06:21 AM
Nice guide, easy to read :)

StickToTheScript
04-21-2013, 06:23 AM
Nice guide, easy to read :)

Thanks a lot! It took a bit of time, but i hope it works! XD

Should I center it?? The main issue is the text wrappings. They all stay to the left.

Itankbots
04-21-2013, 10:56 AM
Love the guide, I always enjoy reading other peoples guides and seeing how they run through things ;) Keep it up man

Love how you kept it simple

StickToTheScript
04-21-2013, 01:43 PM
Love the guide, I always enjoy reading other peoples guides and seeing how they run through things ;) Keep it up man

Love how you kept it simple

Lol! Thanks! Its surprising that i managed to get it done within 1 and a half hours. XD

Valithor
04-22-2013, 09:50 PM
Lol! Thanks! Its surprising that i managed to get it done within 1 and a half hours. XD

Nice Tutorial S2S! I really like how you wrote it out! Looks very clean!

Keep up the good work!

Sjoe
04-22-2013, 09:52 PM
Thanks a lot! It took a bit of time, but i hope it works! XD

Should I center it?? The main issue is the text wrappings. They all stay to the left.

It's good as it is :p

StickToTheScript
04-23-2013, 02:52 AM
Nice Tutorial S2S! I really like how you wrote it out! Looks very clean!

Keep up the good work!

Thanks Val!


It's good at is it :p

Awesome! Good to know! Just as long as it is easy to read!

Valithor
04-23-2013, 04:25 AM
P.S. Those actual X and Y equations are awesome! I've forever struggled with finding the "real" coordinate when writing my scripts! When I saw that I was like: :wow: :drool: I also like your usage of "FindColorTolerance();" nicely done. As I mentioned earlier, I love the clean feel of the thread.

The Mayor
04-23-2013, 05:03 AM
it might be useful to say why you subtract 50 from the Y coords. It's because of the NavBar at the top:

http://puu.sh/2Fqef.jpg

StickToTheScript
04-23-2013, 12:19 PM
it might be useful to say why you subtract 50 from the Y coords. It's because of the NavBar at the top:

http://puu.sh/2Fqef.jpg

Awesome! Thanks man! I quoted you and threw it in there! XD

t4q
04-24-2013, 08:30 AM
Seems nice guide for beginners :)
and I didn't know i need to do this:

X - 2 = Actual X

Y - 53 = Actual Y

I've done only
Y - 50 in my scripts :/

StickToTheScript
04-24-2013, 05:01 PM
Seems nice guide for beginners :)
and I didn't know i need to do this:

X - 2 = Actual X

Y - 53 = Actual Y

I've done only
Y - 50 in my scripts :/

Sometimes the 'X' changes. I noticed a few times that it clicks the original integer, but other times it will be around 4 pixels off. Thats why I made it 2.

I dont know why it would do that, but it works, so I am happy. XD

t4q
04-24-2013, 06:09 PM
I've always used -50 for Y and all my scripts are working...
but if they stop doing I know what might be wrong :)

StickToTheScript
04-24-2013, 06:17 PM
I've always used -50 for Y and all my scripts are working...
but if they stop doing I know what might be wrong :)

I dont believe it matters too much. I did it for safety. You can freely do what you want. XD

TheeMason
04-26-2013, 11:39 PM
Just fantastic! It was a simple and great read. Worth it just for the true x and y coordinates! This will help with getting precision coordinates, helping to expand the anitban in any script I write now. +Rep the little I can give XD

StickToTheScript
04-27-2013, 03:42 AM
Just fantastic! It was a simple and great read. Worth it just for the true x and y coordinates! This will help with getting precision coordinates, helping to expand the anitban in any script I write now. +Rep the little I can give XD

Thanks! Enjoy and have fun! This little tool can work wonders! XD