Jump to content

Result of walking to position is returning true on failure


R I F T

Recommended Posts

I'm writing a sand crab script and before I run to the correct position to begin afking, I want to walk to an area first. I run to the area fine, but when I try and walk to the specific position, I get stuck in an infinite loop as getWalking().walk(desiredPosition) is falsely returning true. It always leaves me about 2-3 tiles away.

private Area currentArea;
private Position currentSpot;

...

private void takeSpot() {
  currentArea = spotManager.freeArea();
  currentSpot = spotManager.freeSpot();

  log("Found a spot at " + currentSpot.toString());
  log("Taking spot ...");

  while(!currentArea.contains(myPlayer())) {
    log("Moving to area ...");
    getWalking().walk(currentArea);
    new Sleep(() -> myPlayer().isMoving(), 6000).sleep();
    sleep(200);
  }
  log("Moved to area!");

  log("Current position: " + myPlayer().getPosition().toString());
  log("Desired position: " + currentSpot.toString());

  while(myPlayer().getPosition() != currentSpot) {
    log("Moving to position");
    log("Current position: " + myPlayer().getPosition().toString());
    log("Desired position: " + currentSpot.toString());
    log("Result of attempting to walk to position is: " + getWalking().walk(currentSpot));

    getWalking().walk(currentSpot);
    new Sleep(() -> !myPlayer().isMoving(), 3000).sleep();
  }
}

Example outputs of logs:

[INFO][Bot #1][11/30 07:41:28 PM]: Moving to position
[INFO][Bot #1][11/30 07:41:28 PM]: Current position: [x=1696, y=3470, z=0]
[INFO][Bot #1][11/30 07:41:28 PM]: Desired position: [x=1695, y=3471, z=0]
[INFO][Bot #1][11/30 07:41:28 PM]: Result of attempting to walk to position is: true
[INFO][Bot #1][11/30 07:41:28 PM]: Moving to position
[INFO][Bot #1][11/30 07:41:28 PM]: Current position: [x=1696, y=3470, z=0]
[INFO][Bot #1][11/30 07:41:28 PM]: Desired position: [x=1695, y=3471, z=0]
[INFO][Bot #1][11/30 07:41:28 PM]: Result of attempting to walk to position is: true
[INFO][Bot #1][11/30 07:41:28 PM]: Moving to position
[INFO][Bot #1][11/30 07:41:28 PM]: Current position: [x=1696, y=3470, z=0]
[INFO][Bot #1][11/30 07:41:28 PM]: Desired position: [x=1695, y=3471, z=0]
[INFO][Bot #1][11/30 07:41:28 PM]: Result of attempting to walk to position is: true

It says that the call to getWalking().walk(currentSpot) is true, however I'm still 2-3 squares away. I can move into the area containing this spot fine, but get stuck in an infinite loop in my second while loop.

I'm only using a static sleep(200) for debugging, as the client crashes otherwise.

I'm new to scripting and a Java nooblet, so any help is welcomed 

Edited by R I F T
Link to comment
Share on other sites

getWalking().walk(Position p);

Has a minimum distance threshold greater than zero, so if you’re within the threshold (I’m not 100% what it is) the event is considered successful.

You need a custom walk event. 

WalkingEvent myWalk = new WalkingEvent(Position p); 

myWalk.setMinDistanceThreshold(0);

execute(myWalk);

Also you should restructure to avoid while() loops. 

Edited by jca
  • Like 3
Link to comment
Share on other sites

17 minutes ago, jca said:

getWalking().walk(Position p) has a minimum distance threshold greater than zero, so if you’re within the threshold (I’m not 100% what it is, the event considered successful.

You need a custom walk event. 

WalkingEvent myWalk = new WalkingEvent(Position p); 

myWalk.setMinDistanceThreshold(0);

execute(myWalk); 

Easy fix. Thanks so much!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...