Results 1 to 21 of 21

Thread: Custom Item, Button, etc. Clicking Using FindColorTolerance

  1. #1
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,164
    Mentioned
    26 Post(s)
    Quoted
    433 Post(s)

    Default Custom Item, Button, etc. Clicking Using FindColorTolerance

    Custom Item, Button, etc. Clicking Using FindColorTolerance

    Written By: StickToTheScript


    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:

    Simba Code:
    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:



    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.


    Quote Originally Posted by The Mayor View Post
    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
    Simba Code:
    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
    Simba Code:
    ClickMouse2(Mouse_Left);

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

    Simba Code:
    wait(990 + Random(789));


    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

  2. #2
    Join Date
    Sep 2012
    Location
    Australia.
    Posts
    839
    Mentioned
    16 Post(s)
    Quoted
    225 Post(s)

    Default

    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.

    I spell colour like you do aswell.

  3. #3
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,164
    Mentioned
    26 Post(s)
    Quoted
    433 Post(s)

    Default

    Quote Originally Posted by Chris! View Post
    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.

    I spell colour like you do aswell.
    Thanks! I will definitely make changes!

    Very useful! XD

  4. #4
    Join Date
    Jan 2013
    Posts
    294
    Mentioned
    1 Post(s)
    Quoted
    121 Post(s)

    Default

    nice easy to understand tutorial to find basic objects with few/single color.

  5. #5
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,164
    Mentioned
    26 Post(s)
    Quoted
    433 Post(s)

    Default

    Quote Originally Posted by dzpliu View Post
    nice easy to understand tutorial to find basic objects with few/single color.
    That was my goal! XD

  6. #6
    Join Date
    Mar 2006
    Location
    Belgium
    Posts
    3,564
    Mentioned
    111 Post(s)
    Quoted
    1475 Post(s)

    Default

    Nice guide, easy to read

    Creds to DannyRS for this wonderful sig!

  7. #7
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,164
    Mentioned
    26 Post(s)
    Quoted
    433 Post(s)

    Default

    Quote Originally Posted by Sjoe View Post
    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.

  8. #8
    Join Date
    Nov 2011
    Location
    United States
    Posts
    815
    Mentioned
    6 Post(s)
    Quoted
    284 Post(s)

    Default

    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

  9. #9
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,164
    Mentioned
    26 Post(s)
    Quoted
    433 Post(s)

    Default

    Quote Originally Posted by Itankbots View Post
    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

  10. #10
    Join Date
    Dec 2010
    Posts
    89
    Mentioned
    4 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by StickToTheScript
    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!

  11. #11
    Join Date
    Mar 2006
    Location
    Belgium
    Posts
    3,564
    Mentioned
    111 Post(s)
    Quoted
    1475 Post(s)

    Default

    Quote Originally Posted by StickToTheScript View Post
    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
    Last edited by Sjoe; 04-26-2013 at 11:48 PM.

    Creds to DannyRS for this wonderful sig!

  12. #12
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,164
    Mentioned
    26 Post(s)
    Quoted
    433 Post(s)

    Default

    Quote Originally Posted by Valithor View Post
    Nice Tutorial S2S! I really like how you wrote it out! Looks very clean!

    Keep up the good work!
    Thanks Val!

    Quote Originally Posted by Sjoe View Post
    It's good at is it
    Awesome! Good to know! Just as long as it is easy to read!

  13. #13
    Join Date
    Dec 2010
    Posts
    89
    Mentioned
    4 Post(s)
    Quoted
    8 Post(s)

    Default

    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: I also like your usage of "FindColorTolerance();" nicely done. As I mentioned earlier, I love the clean feel of the thread.

  14. #14
    Join Date
    Jun 2007
    Location
    The land of the long white cloud.
    Posts
    3,702
    Mentioned
    261 Post(s)
    Quoted
    2006 Post(s)

  15. #15
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,164
    Mentioned
    26 Post(s)
    Quoted
    433 Post(s)

    Default

    Quote Originally Posted by The Mayor View Post
    it might be useful to say why you subtract 50 from the Y coords. It's because of the NavBar at the top:

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

  16. #16
    Join Date
    Mar 2007
    Posts
    393
    Mentioned
    1 Post(s)
    Quoted
    98 Post(s)

    Default

    Seems nice guide for beginners
    and I didn't know i need to do this:
    Code:
    X - 2 = Actual X
    
    Y - 53 = Actual Y
    I've done only
    Code:
    Y - 50
    in my scripts :/

  17. #17
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,164
    Mentioned
    26 Post(s)
    Quoted
    433 Post(s)

    Default

    Quote Originally Posted by t4q View Post
    Seems nice guide for beginners
    and I didn't know i need to do this:
    Code:
    X - 2 = Actual X
    
    Y - 53 = Actual Y
    I've done only
    Code:
    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

  18. #18
    Join Date
    Mar 2007
    Posts
    393
    Mentioned
    1 Post(s)
    Quoted
    98 Post(s)

    Default

    I've always used -50 for Y and all my scripts are working...
    but if they stop doing I know what might be wrong

  19. #19
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,164
    Mentioned
    26 Post(s)
    Quoted
    433 Post(s)

    Default

    Quote Originally Posted by t4q View Post
    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

  20. #20
    Join Date
    Apr 2013
    Location
    Minnesota
    Posts
    38
    Mentioned
    0 Post(s)
    Quoted
    16 Post(s)

    Default

    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

  21. #21
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,164
    Mentioned
    26 Post(s)
    Quoted
    433 Post(s)

    Default

    Quote Originally Posted by TheeMason View Post
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •