Jump to content

npcs.closest ?


The Hero of Time

Recommended Posts

fbee9c17158b55d7d3614d831776a98e.gif

NPC FishingSpot = npcs.closest("Fishing spot");

works if you do it once, the second time its like it picks a random one between the two. the one it's currently fishing at is obviously closer

 

 

 

Yes I noticed this too. It's because of:

 

It picks the closest, those tiles all around you (even the diagonals) are considered 1 tile away. Then it picks a random one OR it picks the first one on the checking order.

 

Common distance calculations should be: direct tiles: 10 g cost, diaganol tiles: 14 g cost. It doesn't look like osbot is using this standard in .closest.

 

It just sees all the tiles around you as just 1 away.

 

Edited by MegaManAlpha
Link to comment
Share on other sites

Yes I noticed this too. It's because of:

 

It picks the closest, those tiles all around you (even the diagonals) are considered 1 tile away. Then it picks a random one OR it picks the first one on the checking order.

 

Common distance calculations should be: direct tiles: 10 g cost, diaganol tiles: 14 g cost. It doesn't look like osbot is using this standard in .closest.

 

It just sees all the tiles around you as just 1 away.

"Then it picks a random one OR it picks the first one on the checking order."

I expected this, i didn't realize a diagonal tile was 1 tile though

//try

NPC FishingSpot = npcs.closest(true, "Fishing spot");

what does it do?

Link to comment
Share on other sites

"Then it picks a random one OR it picks the first one on the checking order."

I expected this, i didn't realize a diagonal tile was 1 tile though

what does it do?

 

 

TEMP FIX - this should work (if it doesn't let me know, I'll make a more advanced one with A* heuristics):

public NPC megaGetClosestNpc(String npcName) {

   int bestDistance = Integer.MAX_VALUE;
   NPC best = null;

   for(NPC npc : npcs.getAll()) {
      if(npc != null && npc.getName().equals(npcName)) {
         int thisDistance = map.realDistance(npc);
         if(thisDistance < bestDistance) {
            best = npc;
            bestDistance = thisDistance;
         }
      }
   }

   return best;

}

 

Edited by MegaManAlpha
Link to comment
Share on other sites

OSBot has 2 distance methods, distance and realDistance. By default the closest method uses distance which is just a rounded pythagora's algorithm computation which is why a tile diagonally next to you is computed as round(sqrt(2)) = 1 even though its 1.4 and the ones directly accessible have distance equal to 1. Using realDistance on the other hand will yield a result of 0 on tiles north west east or south of you and a 2 for diagonal tiles.

 

The reason why we don't use realDistance is the fact that it can only compute distances in the area local to your player (~30 tiles around you) so we mostly rely on distance. As for accurately determining long distances I implemented an algorithm that computes a path length that is used for webwalking (there is no support in the API for such thing). 

Link to comment
Share on other sites

"Then it picks a random one OR it picks the first one on the checking order."

I expected this, i didn't realize a diagonal tile was 1 tile though

what does it do?

 

the boolean is whether or not it should use "Real Distance"

When using real distance, the LocalPathFinder is used to find the length of the actual path to the tile, rather than euclidean distance

 

  • Like 2
Link to comment
Share on other sites

 

 

TEMP FIX - this should work (if it doesn't let me know, I'll make a more advanced one with A* heuristics):

public NPC megaGetClosestNpc(String npcName) {

   int bestDistance = Integer.MAX_VALUE;
   NPC best = null;

   for(NPC npc : npcs.getAll()) {
      if(npc != null && npc.getName().equals(npcName)) {
         int thisDistance = map.realDistance(npc);
         if(thisDistance < bestDistance) {
            best = npc;
            bestDistance = thisDistance;
         }
      }
   }

   return best;

}

 

ill try adding the parameter true first, if it doesnt work ill try this

 

i appreciate you helping with this code, but apparently you can enable realdistance just by adding true as parameter to .closest ;)

//try

NPC FishingSpot = npcs.closest(true, "Fishing spot");

 

 

OSBot has 2 distance methods, distance and realDistance. By default the closest method uses distance which is just a rounded pythagora's algorithm computation which is why a tile diagonally next to you is computed as round(sqrt(2)) = 1 even though its 1.4 and the ones directly accessible have distance equal to 1. Using realDistance on the other hand will yield a result of 0 on tiles north west east or south of you and a 2 for diagonal tiles.

 

The reason why we don't use realDistance is the fact that it can only compute distances in the area local to your player (~30 tiles around you) so we mostly rely on distance. As for accurately determining long distances I implemented an algorithm that computes a path length that is used for webwalking (there is no support in the API for such thing). 

 

 

the boolean is whether or not it should use "Real Distance"

When using real distance, the LocalPathFinder is used to find the length of the actual path to the tile, rather than euclidean distance

 

 

thanks for the explanation and the solution guys! cheers boge.png

Edited by The Hero of Time
  • Like 1
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...