Jump to content

Bot only uses these tiles to fish?


Jueix

Recommended Posts

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.

bot-only-uses-these-tiles.jpg

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 by Jueix
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

You're absolutely right about what the problem is. You've got two solutions:

  1. Write your own function that finds the farthest NPCs you're after, or...
  2. 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 by liverare
  • 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...