Jueix Posted February 12, 2019 Share Posted February 12, 2019 (edited) So I've tried a few methods and getting the bot to fish from all spots in aerial fishing but it only goes for the ones that shows up in the black line closest to the character doesn't fish any of the ones located in the red line or any off the ones further out than the red line but the bird can reach, think it may be a problem with the closest function. the code I have that runs in the best at the moment is if(!inventory.isFull()) { NPC Fishspot = npcs.closest("Fishing spot"); Fishspot.interact("Catch"); sleep(random(1000,4000)); } but would rather allow it to fish from all of the fishing spots. (Also the paint doesn't always seem to load each time I start the script, sometimes it does sometimes it doesn't, working on getting a better paint made but that's it for now.) Edited February 12, 2019 by Jueix Quote Link to comment Share on other sites More sharing options...
Czar Posted February 12, 2019 Share Posted February 12, 2019 Well, your Fishspot is grabbing the closest fishing spot (npcs.closest), which means it will keep targetting the nearest npc to your player's tile, so it won't be targetting the far away ones when there are fishing spots more closer. Try: NPC Fishspot = getNpcs().getAll().stream().filter(a -> a.getName().equalsIgnoreCase("Fishing spot")).findAny().orElseGet(() -> getNpcs().closest("Fishing spot")); What is different? This is grabbing all fishing spots in the area, and choosing any (findAny), instead of choosing closest. If it fails and none are found, it will resort to finding the closest one. This makes use of streams, otherwise the code would be much longer. Quote Link to comment Share on other sites More sharing options...
liverare Posted February 12, 2019 Share Posted February 12, 2019 (edited) You're absolutely right about what the problem is. You've got two solutions: Write your own function that finds the farthest NPCs you're after, or... Write your own function that filters out NPCs within a defined Area. @Czar idea would work, however I think a better solution would be to simply order the list by distance in descending order and return the first result: public NPC getFarthestNPC(String name) { return npcs.getAll().stream() .filter(npc -> name.equals(npc.getName())) .sorted((npc1, npc2) -> { double distToNpc1 = map.distance(npc1); double distToNpc2 = map.distance(npc2); return Double.compare(distToNpc2, distToNpc1); }) .findFirst() .orElse(null); } Then you can do: NPC cow = getFarthestNPC("Cow"); However, just always remember this will return the farthest NPC irrespective of whether or not you can reach it. It'll work fine if you don't need to physically reach a tile, but should you need to then you can tweak around with the code to include filtering for distance/real distance, by areas, etc. :edit: I have just realised that you WILL need to cache the farthest NPC and re-use and re-check it until it stops existing. Why? Because if you keep trying to find the farthest fishing spot, then your in-game player will be running about like a mong. Edited February 12, 2019 by liverare 1 Quote Link to comment Share on other sites More sharing options...