Jump to content
ThatGamerBlue

getClosest() returning weird results

Recommended Posts

While standing here, if both fishing spots are up getClosest() will return this one: mP3WpjL.png

While standing in the other tile, it will return the other fishing spot, causing the loop to click one spot, then click the other spot over and over. I don't want to use an isAnimating() check because the fishing animation carries on for a few ticks after the fishing spot disappears.

Is there a way to fix this issue? My fishing method: 

NPC currentSpot;
Position currentLocation;

public void fish() {
		NPC fishingSpot = getNpcs().closest(6825);
		if(fishingSpot == null) {
			log("spot == null");
			return;
		}
		if(currentSpot == null) {
			currentSpot = fishingSpot;
			fishingSpot.interact("Bait");
		}
		if(!currentSpot.equals(fishingSpot)) {
			currentSpot = fishingSpot;
			fishingSpot.interact("Bait");
		}
		getMouse().moveOutsideScreen();
	}

 

Link to comment
Share on other sites

2 minutes ago, Juggles said:

Nothing wrong with waiting until you're done animating. 

No human instantly clicks after the spot disappears 

There is a delay in the onLoop(), but I figured that's pretty irrelevant for the core issue, also the RuneLoader client has a beep after you stopped fishing from the spot moving or your inv being full, so I'm trying to replicate the response time from that.

Link to comment
Share on other sites

What's really wrong with isAnimating(), or to be exact isMoving()? A good check to do in order not to click around too much,

Would do it more or less like this and not worry about stuff (untested).

Finds closest spot and interacts with it. Would be good to add additional check to be sure that the fishing spot is good, like if it has the required action, is reachable and etc

public void fish() {
		NPC fishingSpot = getNpcs().closest("Fishing spot"); // Or whatever it is called. Don't use ids
		if (fishingSpot != null) {
         	fishingSpot.interact("Bait");
          new ConditionalSleep(5000, 250) {
			@Override
			public boolean condition() throws InterruptedException {
				return !myPlayer().isMoving() && myPlayer().isAnimating();
			}
		};
          getMouse().moveOutsideScreen();
        }
}

 

Link to comment
Share on other sites

I don't really understand what you mean by "other tile" and all that, but usually these issues occur because distance checks are done with ints. So if its at an angle, the distance is 1.41~ which as an int is rounded to 1. So a tile south 1 tile and east 1 tile is the "same" distance as one just south of you, due to the rounding. Then its just a matter of which NPC is first/last in the internal entity list.

Also, you should sleep after interacting until the player is animating/interacting, with a max time (see ConditionalSleep or the other implementations around the forums). Also you can check if the spot exists still using currentSpot.exists(), once the fishing spot is gone exists() will return false.

  • Like 2
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.

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...