Results 1 to 7 of 7

Thread: How To Open A Gate

  1. #1
    Join Date
    Dec 2012
    Posts
    73
    Mentioned
    0 Post(s)
    Quoted
    10 Post(s)

    Default How To Open A Gate

    Hello,

    these are my first, very noobish steps to build my own script, mostly by copying or at least looking at parts of other scripts. I know there are a buttload of tutorials and tips around here and I didn't go through them all, but I hope that some of you will be kind enough to at least push me in the right direction; you can link me to tutorials or videos all you want, but please bear with me a little.

    So I want to make a simple script that walks from a to b. Using SPS and the path generation program available it works (more or less), until to a point where a gate needs to be opened.

    Trouble is the gate might not always be visible, the procedure needs to do the following:

    a) - Check if it finds the color of the gate on the screen, if yes, continue to the next step

    - If not, rotate the screen to a certain degree, then repeat the process.

    "If... then... else" is the kind of loop I need for something like this, right?

    b) - Click on the gate, opening the context menu

    - Read the options. If one says "Open Gate" then it has found the right object.
    If not: Back to a)

    - Click on the "Open Gate" option and end the procedure.

    Now I have some issues with this whole business, especially when it comes to two points:

    1. Which function do I need to use to get the whole color detection working?
    An AIO Powerminer from the public scripts section has something that looks as if it could be the solution:

    Code:
    If FindObjCustom(x, y, ['ne Co'], [2895406, 2105633], 3) Then...
    This video gives some information on how to use color functions, unfortunately it's only for "FindColor".


    What are all these parameters? The SRL documentation doesn't really explain it. Also, am I on the right way or are these functions not made for what I want to do?

    2. Does Simba/SRL even have an OCR module for reading the options of a context menu? It surely seems to have a few OCR functions (btw. what is "uptext"?).


    Alright, as I said all these questions are not really sofisticated, but I surely hope that somebody might at least show me a map of this whole jungle of functions, options and whatnot

    Thanks a lot!

  2. #2
    Join Date
    Feb 2012
    Location
    Discord
    Posts
    3,114
    Mentioned
    37 Post(s)
    Quoted
    538 Post(s)

  3. #3
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    1,631
    Mentioned
    47 Post(s)
    Quoted
    254 Post(s)

    Default

    The parameters of FindObjCustom(x, y, ['ne Co'], [2895406, 2105633], 3)
    X, Y are the variables where you are going to store the result in. Both need to be Integer.
    ['ne Co'] is an Array of String of the possible uptexts. I suggest not using capital letters as some get misread more often as lowercase letters.
    [2895406, 2105633] is an Array of Integer: The colors you want to search for
    And finally 3 is an Integer, the tolerance.

    To find the gate I would use a while loop and rotate the compass a maximum of 360 degrees before exiting out. So rotate 15 degrees for like 24 times or generate a random number 10-20 and add everything up.

    Simba Code:
    function FindGate: boolean;
    var
      totalRotation, r: Integer;

    begin
      while totalRotation < 360 do
      begin
        r := RandomRange(10, 20);
        totalRotation := totalRotation + r;
        MakeCompass(rs_GetCompassAngleDegrees + r);
        {* Try to find the object like this
        if findTheObject then
        begin
          Result := True;
          break;
        end;
        *}

      end;
    end;

    Script source code available here: Github

  4. #4
    Join Date
    Dec 2012
    Posts
    73
    Mentioned
    0 Post(s)
    Quoted
    10 Post(s)

    Default

    Thanks to J J, your explanation of the FindObj parameters was most helpful, along with the videos of YoHoJo.

    Here is how I solved the problem: After observing that the bot always comes out at a certain angle after walking the path to the gate I simply added a procedure to turn the screen. Like so:

    Code:
    Procedure TurnToMakeGateOpenScriptWork;
    begin
      KeyDown(37);
      wait(1000);
      KeyUp(37);
      wait(3000);
    end;
    Then, to open the gate, I did this:

    Code:
    Procedure OpenGate;
    
    var
        x, y: Integer;
    
    begin
    if FindObjCustom(x, y, ['Open', 'Gate'], [3622483, 3094077], 3)
    then
      begin
      Writeln('Yeah, I found the gate mate');
      ClickMouse(x, y, mouse_Left);
      Writeln('OK, clicked on the gate. Waiting for 12 seconds for the process to finish...');
      Wait(12000);
      end;
    //else Writeln('Now where is that gate? Continuing with Walking...');
    
    end;
    Works like a charm, only problem seems to be that the script won't compile if I uncomment the "else" along with the second Writeln.
    Could somebody help me out?

  5. #5
    Join Date
    Jan 2012
    Location
    Calgary, AB, Canada
    Posts
    1,819
    Mentioned
    5 Post(s)
    Quoted
    120 Post(s)

    Default

    Here is a better method for finding the gate, just added uptext checking. Also the else comment should work now as you must have had the semicolon behind the end.

    Simba Code:
    procedure OpenGate;
    var
      x, y: Integer;
    begin
    if FindObjCustom(x, y, ['Open', 'Gate'], [3622483, 3094077], 3)
    then
      begin
        MMouse(x, y, 0, 0); // Moves the mouse there
        if WaitUpText('pen', 1000) then // Checks if it has this uptext
        begin
          Writeln('Yeah, I found the gate mate');
          ClickMouse2(mouse_Left); // Clicks on it ( dont use MoveMouse or ClickMouse they'll get you banned)
          Writeln('OK, clicked on the gate. Waiting for 12 seconds for the process to finish...');
          Wait(12000);
        end else Writeln('Now where is that gate? Continuing with Walking...');
      end;
    end;
    Current Project: Retired

  6. #6
    Join Date
    Dec 2012
    Posts
    73
    Mentioned
    0 Post(s)
    Quoted
    10 Post(s)

    Default

    Hey,

    isn't uptext checking already included in the FindObj procedure? It is using it to detect the gate after all.

    Also, a little question on top: is there a big difference between "MoveMouse" and "MMouse", or is it the same?

    Thanks for your suggestions, really appreciate it!

  7. #7
    Join Date
    Jan 2012
    Location
    Calgary, AB, Canada
    Posts
    1,819
    Mentioned
    5 Post(s)
    Quoted
    120 Post(s)

    Default

    Quote Originally Posted by SomeGuyFromHere View Post
    Hey,

    isn't uptext checking already included in the FindObj procedure? It is using it to detect the gate after all.

    Also, a little question on top: is there a big difference between "MoveMouse" and "MMouse", or is it the same?

    Thanks for your suggestions, really appreciate it!
    Oh yeah forgot about findobj since I really don't use it often at all. MMouse is much more humanlike whereas MoveMouse is really fast and isn't that safe to use if you want to avoid a ban
    Current Project: Retired

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
  •