March 19, 20169 yr 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 Edited March 19, 20169 yr by The Hero of Time
March 19, 20169 yr 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 March 19, 20169 yr by MegaManAlpha
March 19, 20169 yr Author 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?
March 19, 20169 yr "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 March 19, 20169 yr by MegaManAlpha
March 19, 20169 yr 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).
March 19, 20169 yr "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
March 19, 20169 yr Author 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 Edited March 19, 20169 yr by The Hero of Time
Create an account or sign in to comment