Results 1 to 20 of 20

Thread: [OGL] Walking v3

  1. #1
    Join Date
    Aug 2012
    Posts
    188
    Mentioned
    9 Post(s)
    Quoted
    71 Post(s)

    Default [OGL] Walking v3

    Hey guys! I'm back with more on the topic of walking around RS using OGL! This time I have several new functions that can utilize different techniques such as finding models during a tilewalk! I also included a maximum wait time for the waitFlag procedure in case your player happens to click in a non-walkable area.

    Here are three basic functions I use:

    getDistance returns the distance as an integer of the number of pixels between two points. You can use this to make sure you are near something.
    EDIT: As Obscurity pointed out there is already a distance function:
    Simba Code:
    somePoint.distanceFrom(anotherPoint)
    But I'll leave mine here just cause!
    Simba Code:
    function getDistance(point1, point2 : TPoint) : Integer;
    begin
      exit(round(sqrt((point1.X - point2.X) * (point1.X - point2.X) + (point1.Y - point2.Y) * (point1.Y - point2.Y))));
    end;

    sgn returns the sign of an integer you pass in (zero will return 0). I use this for getting the distance to travel in the tile walking functions.
    Simba Code:
    function sgn(x : Integer) : Integer;
    begin
      if x = 0 then
        exit(0)
      else
        if x > 0 then
          exit(1)
      else
        exit(-1);
    end;

    waitFlag will wait until the flag has disappeared to continue. It can take in an integer in milliseconds for how long it should wait for the flag to disappear (15000 is default). This is great for making sure errors don't occur.
    Simba Code:
    procedure waitFlag(maxWait : Integer = 15000);
    var
      flagTimer : TCountDown;
    begin
      flagTimer.setTime(maxWait);
      wait(250);
      while (not ogl.getTextures(1275).isEmpty()) do
      begin
        if flagTimer.isFinished() then
          exit();
        wait(1000);
      end;
      wait(randomrange(250, 500));
      if not ogl.getTextures(1275).isEmpty() then
        waitFlag();
    end;

    and walkTo simply walks to a point using the minimap. This is implemented in the following functions.
    Simba Code:
    procedure walkTo(point : TPoint);
    begin
      mouse.click(minimap.getScreenPosition(minimap.getLocalPosition().adjustPosition(point.X, point.Y)), 1);
    end;

    Ok now that we're through that lets get into the juicy stuff!
    Our first procedure is tileWalkInterval. This one walks to a "tile" you give it as a TPoint, and takes a randomness which affects the variation each point it goes to, and the step size (which you can increase/decrease in the code if you wish).
    Simba Code:
    procedure tileWalkInterval(point : TPoint; r : Integer);
    var
      stepSize, rx, ry, toGoX, toGoY : Integer;
      next : TPoint;
    begin
      stepSize := r + 7;
      toGoX := point.X;
      toGoY := point.Y;

      repeat
        rx := random(-r, r);
        ry := random(-r, r);
        next := [sgn(toGoX) * (min(abs(toGoX), stepSize)) + rx, sgn(toGoY) * (min(abs(toGoY), stepSize)) + ry];
        writeln('walking x: ', next.x, '   walking y: ', next.y);
        walkTo(next);
        waitFlag();

        toGoX := toGoX - next.X;
        toGoY := toGoY - next.Y;

      until (abs(toGoX) <= r) and (abs(toGoY) <= r);
    end;

    tileWalk is the procedure used to call the non-overloaded tileWalkInterval. It needs the array of TPoints to walk, and also the randomness you wish.
    Simba Code:
    procedure tileWalk(points : TPointArray; r : Integer);
    var
      i : Integer;
    begin
      for i := 0 to high(points) do
      begin
        writeln('Walking to: ', points[i]);
        tileWalkInterval(points[i], r);
      end;
    end;

    This tileWalkInterval is an overloaded version of the previous. This time, in addition, it takes a model ID as an integer, and the offset to click from that model as a TPoint (make sure to include randomness!).
    Simba Code:
    procedure tileWalkInterval(point : TPoint; r, modelID : Integer; modelOffSet : TPoint); overload;
    var
      stepSize, rx, ry, toGoX, toGoY : Integer;
      next : TPoint;
      modelTimer : TCountDown;
      models : glModelArray;
    begin
      stepSize := r + 7;
      toGoX := point.X;
      toGoY := point.Y;
      repeat
        rx := random(-r, r);
        ry := random(-r, r);
        next := [sgn(toGoX) * (min(abs(toGoX), stepSize)) + rx, sgn(toGoY) * (min(abs(toGoY), stepSize)) + ry];
        writeln('walking x: ', next.x, '   walking y: ', next.y);
        walkTo(next);
        repeat
          wait(randomrange(450, 950));
          models := ogl.getModels(modelID);
          if (not models.getVisible().isEmpty()) then
          begin
            if (models[0].isVisible()) then
            begin
              mouse.click(models[0].toPoint().adjustPosition(modelOffset.X, modelOffset.Y));
              writeLn('Clicked on model ', models[0].ID, '. Coords: ', models[0].toPoint());
              waitFlag();
              exit();
            end;
          end;
          if (not ogl.getTextures(1275).isEmpty()) then
            modelTimer.setTime(1000);
        until modelTimer.isFinished();
        waitFlag();

        toGoX := toGoX - next.X;
        toGoY := toGoY - next.Y;

      until (abs(toGoX) <= r) and (abs(toGoY) <= r);
    end;

    Our next method of walking to a point is iconWalk! As the name suggests, it uses an icon texture on the minimap. This time though, it takes in a maxWait time in case your icon (such as a bank) is in an unwalkable area (behind the counter for example). The default for the wait time is 15000 ms.
    Simba Code:
    function iconWalk(randomization: integer; icon: glTextureArray; offSetTiles: TPoint; maxWait : Integer = 15000): boolean;
    var
      rx, ry :integer;
    begin
      rx := randomrange(-(randomization), randomization);
      ry := randomrange(-(randomization), randomization);
      if icon.isEmpty() then
        result:=false
      else
      begin
        mouse.click(minimap.getScreenPosition(minimap.getLocalPosition(icon.closestTo(minimap.getScreenPosition(minimap.getLocalPosition()))[0]).adjustposition(offsetTiles.x+rx, offsetTiles.y+ry)), 1);
        if ((offSetTiles.y > 20) or (offSetTiles.y < -20)) or ((offSetTiles.x > 15) or (offSetTiles.x < -15)) then
          wait(3500)
        else
          wait(1000);
        waitFlag(maxWait);
        exit(true);
      end;
      exit(false);
    end;

    The next function can be used in almost any situation! modelWalk will find a model ID with an offset that you pass it and walk there. If it does in fact find your model it will walk to it and return true, otherwise it returns false.
    Simba Code:
    function modelWalk(modelID : Integer; offSet : TPoint) : boolean;
    var
      models : glModelArray;
      modelTimer : TCountDown;
      mousePoint : TPoint;
    begin
      modelTimer.setTime(1000);
      repeat
        models := ogl.getModels(modelID);
      until (not models.isEmpty) or modelTimer.isFinished();

      mousePoint := models[0].toPoint().adjustPosition(offSet.X + randomrange(-10, 10), offSet.Y + randomrange(-10, 10));
      mouse.move(mousePoint);
      if (mouse.getTooltip() = '') then
        mouse.click(mousePoint)
      else
        mouse.rightClickOption(mousePoint, ['alk', 'here']);
      waitFlag();
    end;

    And that's it for today! I spend a while on these so like always I absolutely love feedback! If you see any problems or possible improvements please post them, and I will work on them. Once again thank you @Ross; for the original procedures and idea, and @Clarity; and @Lucidity; for help answering questions about OGL.
    Last edited by Swag Bag; 07-22-2015 at 12:17 AM. Reason: Fixed a function

  2. #2
    Join Date
    Mar 2015
    Posts
    438
    Mentioned
    21 Post(s)
    Quoted
    211 Post(s)

    Default

    I'll start experimenting with these. I was already planning on doing it tonight with your v2 but this is even better!

    Edit: Works amazingly thanks Swag!
    Last edited by Clutch; 07-22-2015 at 02:08 AM.

  3. #3
    Join Date
    Jun 2012
    Posts
    586
    Mentioned
    112 Post(s)
    Quoted
    296 Post(s)

    Default

    ogLib has:
    Simba Code:
    somePoint.distanceFrom(anotherPoint)

    AFAIK, a decent way to do signum in Lape would be:
    Simba Code:
    function integer.sgn():integer;
    begin exit(integer(self<0)-integer(self>0));end;

    Simba Code:
    minimap.getScreenPosition(minimap.getLocalPosition().adjustPosition(point.X, point.Y)
    That's just brilliant, yet incredibly simple!



    Will look through more after work!




    Skype: obscuritySRL@outlook.com

  4. #4
    Join Date
    Aug 2012
    Posts
    188
    Mentioned
    9 Post(s)
    Quoted
    71 Post(s)

    Default

    Quote Originally Posted by CLUTCH
    ...
    Thanks clutch, glad I could help!

    Quote Originally Posted by OBSCURITY
    ...
    Well I never...I guess that's shorter than what I wrote! I'll be sure to change that in my code soon
    I'm guessing in Lape true is -1 in its Integer form?

  5. #5
    Join Date
    Mar 2015
    Posts
    438
    Mentioned
    21 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by Swag Bag View Post
    Thanks clutch, glad I could help!


    Well I never...I guess that's shorter than what I wrote! I'll be sure to change that in my code soon
    I'm guessing in Lape true is -1 in its Integer form?
    Might be an issue with my script itself - but found when the camera angle changes it can cause the bot to go completely whacko and ends up walking randomly elsewhere. Ex. Taverly bank like I showed you yesterday, ended up walking up by the druid ritual quest start area which isn't on the initial minimap and the opposite direction of the bank. Like you said though to make sure theres no duplicate textures I'll have to double check that as it's the most likely cause. The only other one being rotating the camera.

  6. #6
    Join Date
    Aug 2012
    Posts
    188
    Mentioned
    9 Post(s)
    Quoted
    71 Post(s)

    Default

    Quote Originally Posted by CLUTCH
    ...
    Can you post how you are using it and which walking script you're using? And also a screenshot of the minimal with textures on would help. Off the top of my head I believe bank textures are 45052, but several other building icons share the same thing.

    If there is a bug in the code I'll take a look as soon as I get home to fix it!

  7. #7
    Join Date
    Mar 2015
    Posts
    438
    Mentioned
    21 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by Swag Bag View Post
    Can you post how you are using it and which walking script you're using? And also a screenshot of the minimal with textures on would help. Off the top of my head I believe bank textures are 45052, but several other building icons share the same thing.

    If there is a bug in the code I'll take a look as soon as I get home to fix it!
    It is bank icon and there are alot of other icons, I will check once I'm off work to see if there are any shared textures between them.

  8. #8
    Join Date
    Jun 2012
    Posts
    586
    Mentioned
    112 Post(s)
    Quoted
    296 Post(s)

    Default

    All textures sharing a shape share IDs. Picture if the texture were just painted black. The bank shares an ID with ALOT of other icons. ColourID will be required.




    Skype: obscuritySRL@outlook.com

  9. #9
    Join Date
    Mar 2015
    Posts
    438
    Mentioned
    21 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by Obscurity View Post
    All textures sharing a shape share IDs. Picture if the texture were just painted black. The bank shares an ID with ALOT of other icons. ColourID will be required.
    Thanks for the info obs!

  10. #10
    Join Date
    Aug 2012
    Posts
    188
    Mentioned
    9 Post(s)
    Quoted
    71 Post(s)

    Default

    One technique I used to be certain I walk to a bank, is to do the tilewalk to the bank, and then the iconwalk (goes to nearest one) to make sure we are in the bank

  11. #11
    Join Date
    Mar 2015
    Posts
    438
    Mentioned
    21 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by Swag Bag View Post
    One technique I used to be certain I walk to a bank, is to do the tilewalk to the bank, and then the iconwalk (goes to nearest one) to make sure we are in the bank
    Alright cool that'll be a nice failsafe!

  12. #12
    Join Date
    Jun 2014
    Posts
    463
    Mentioned
    27 Post(s)
    Quoted
    229 Post(s)

    Default

    Quote Originally Posted by Swag Bag View Post
    One technique I used to be certain I walk to a bank, is to do the tilewalk to the bank, and then the iconwalk (goes to nearest one) to make sure we are in the bank
    An alternative you could do is grab the players dot on the minimap, and the left and right corners of the minimap and use the isinpoly for textures to determine if the texture is inside the triangle that's created. It should determine if you're facing where you want to be. I'm sure you could shorten the view to match what the main screen view is, I didn't bother with that. Here's how I did it.



    It's pretty messy, but it does what it's suppose to.

    Simba Code:
    1. function inDirection(): boolean;
    2. var
    3.   mapLBox, mapRBox: TBox;
    4.   x, y: integer;
    5. begin
    6.   if length(ogl.getTextures(40467, 2236455)) then
    7.   begin
    8.     mapLBox:=ogl.getTextures(147885)[0].bounds;
    9.     mapRBox:=ogl.getTextures(159981)[0].bounds;
    10.     if ogl.getTextures(40467, 2236455)[0].isInPoly([minimap.getPlayer(), point(mapLBox.x1, mapLBox.y1), point(mapRBox.x1, mapRBox.y1)]) then
    11.       exit(true);
    12.   end;
    13. end;
    Last edited by Lucidity; 07-22-2015 at 07:41 PM.
    Tsunami

  13. #13
    Join Date
    Mar 2015
    Posts
    438
    Mentioned
    21 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by Lucidity View Post
    An alternative you could do is grab the players dot on the minimap, and the left and right corners of the minimap and use the isinpoly for textures to determine if the texture is inside the triangle that's created. It should determine if you're facing where you want to be. I'm sure you could shorten the view to match what the main screen view is, I didn't bother with that. Here's how I did it.



    It's pretty messy, but it does what it's suppose to.

    Simba Code:
    1. function inDirection(): boolean;
    2. var
    3.   mapLBox, mapRBox: TBox;
    4.   x, y: integer;
    5. begin
    6.   if length(ogl.getTextures(40467, 2236455)) then
    7.   begin
    8.     mapLBox:=ogl.getTextures(147885)[0].bounds;
    9.     mapRBox:=ogl.getTextures(159981)[0].bounds;
    10.     if ogl.getTextures(40467, 2236455)[0].isInPoly([minimap.getPlayer(), point(mapLBox.x1, mapLBox.y1), point(mapRBox.x1, mapRBox.y1)]) then
    11.       exit(true);
    12.   end;
    13. end;
    Exactly what you mentioned to me yesterday but thanks this really did make more sense with the pictures haha:P

  14. #14
    Join Date
    Jun 2012
    Posts
    586
    Mentioned
    112 Post(s)
    Quoted
    296 Post(s)

    Default

    @Clutch; @Lucidity;

    Simba Code:
    function inDirection(id,colourID:int32):boolean;
    var
      arcTan:extended;
      point:tPoint;
      textureArray:glTextureArray;
    begin
      if length(textureArray:=ogl.getTextures(id,colourID)) then
      begin
        point:=minimap.getPlayer();
        exit(((arcTan:=arcTan2(point.y-textureArray[0].y,point.x-textureArray[0].x))>0.785398163) and (arcTan<2.35619449));
      end;
    end;
    Last edited by Obscurity; 07-22-2015 at 08:49 PM.




    Skype: obscuritySRL@outlook.com

  15. #15
    Join Date
    Mar 2015
    Posts
    438
    Mentioned
    21 Post(s)
    Quoted
    211 Post(s)

    Default

    Quote Originally Posted by Obscurity View Post
    @Clutch; @Lucidity;

    Simba Code:
    function inDirection(id,colourID:int32):boolean;
    var
      arcTan:extended;
      point:tPoint;
      textureArray:glTextureArray;
    begin
      if length(textureArray:=ogl.getTextures(id,colourID)) then
      begin
        point:=minimap.getPlayer();
        exit(((arcTan:=arcTan2(point.y-textureArray[0].y,point.x-textureArray[0].x))>0.785398163) and (arcTan<2.35619449));
      end;
    end;
    Thanks buddy, I'll be testing all of this out tonight as there's a script I wasn't able to finish due to walking. Hopefully all of this allows me to get it up and running.

  16. #16
    Join Date
    Aug 2012
    Posts
    188
    Mentioned
    9 Post(s)
    Quoted
    71 Post(s)

    Default

    Fixed a bug in iconWalk where it chooses the closest icon to the midpoint of the screen. The closestTo() should instead contain
    Simba Code:
    minimap.getScreenPosition(minimap.getLocalPosition())
    Which is the point of the player on the minimap.

    Also updated iconWalk and modelWalk to fix a bug.

  17. #17
    Join Date
    Jan 2012
    Location
    Long Island, NY
    Posts
    413
    Mentioned
    5 Post(s)
    Quoted
    95 Post(s)

    Default

    These look fantastic!! I've been working on my own walking methods, but this is nice I'll definitely use these in my current project.

  18. #18
    Join Date
    Aug 2015
    Posts
    3
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Hey man, looks fantastic. I modified it a bit to work with SRLCompatibility but i ran into some problems.

    Code:
    iconWalk(5, ogl.getTextures(45052), point(1,1), 15000);
    Gives the error: Error: Don't know which overloaded method to call with params (*unknown*, Int32) at line 70

    With:
    Code:
    tMouse.click(minimap.getScreenPosition(minimap.getLocalPosition(icon.closestTo(minimap.getScreenPosition(minimap.getLocalPosition()))[0]).adjustposition(offsetTiles.x+rx, offsetTiles.y+ry)), 1);
    at line 70, any idea how to fix this?

  19. #19
    Join Date
    Aug 2012
    Posts
    188
    Mentioned
    9 Post(s)
    Quoted
    71 Post(s)

    Default

    I'm not sure what SRLCompatability is; Does it have the ogl functions in it? That big messy line with mouse.click() is figuring out which icon is closest to the player that you passed in, and adjusting it based on the point that you passed in. Try casting the first argument in mouse.click like so and see what happens.
    Simba Code:
    tMouse.click(TPoint(minimap.getScreenPosition(minimap.getLocalPosition(icon.closestTo(minimap.getScreenPosition(minimap.getLocalPosition()))[0]).adjustposition(offsetTiles.x+rx, offsetTiles.y+ry))), 1);

  20. #20
    Join Date
    Jan 2007
    Location
    Not here
    Posts
    1,604
    Mentioned
    2 Post(s)
    Quoted
    19 Post(s)

    Default

    Sorry for the extremely beginner question but how do I set the TPointArrays? I can't seem to find them used in a tutorial anywhere in the way that I need them, I currently have:

    Simba Code:
    walkTiles: TPointArray;
    walkTiles[0]:= Point(81, 73);
      walkTiles[1]:= Point(85, 91);
      walkTiles[2]:= Point(65, 90);
      walkTiles[3]:= Point(48, 97);

    tileWalk(walkTiles, 2);

    The above gives bitmap errors when I try run it though, I'm assuming I'm setting the TPA incorrectly.

    EDIT: nvm, just needed to set the length of the array!
    Last edited by rkroxpunk; 11-24-2015 at 12:22 PM.
    Sleeping...

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
  •