Jump to content

How to get entity (ignoring which is closest)


Recommended Posts

Posted

I'm missing something silly and can't figure it out.

Right now I'm using

NPC fishingSpot = npcs.closest(o -> o.getName().contains("Fishing spot"));

and its super obvious when all the bots switch to the closest fishing spot at the same time. So I'm trying to switch my script to ignore which fishing spot is closest and just pick any of the ones it can find.

I checked the API documentation and I thought I could use npcs.getAll() but when I try

NPC fishingSpot = getNpcs().getAll().filter(new NameFilter("Fishing spot"));
and
NPC fishingSpot = npcs.getAll().filter(new NameFilter("Fishing spot"));

the editor is giving me an error on the ".filter" portion. I'm definitely using getAll() wrong but I'm not sure how to fix it.

Posted (edited)

@sinclair666
Only thing I can think of at the moment since I am tired but should work. First you can grab the closest fishing spot like I did below then grab the position and tell it the fishing spot you want is != to the second closest fishing spot's position.

NPC closestfishingSpot = getNpcs().closest(npc -> npc != null && npc.getName().equals("Fishing spot"));
        
NPC fishingSpot = getNpcs().closest(npc -> npc != null && npc.getName().equals("Fishing spot") && npc.getPosition() != closestfishingSpot.getPosition());

EDIT 1 Hold up I just had an idea and need a sec to test if it would work.
EDIT 2 : Nope nvm brian.exe stopped working and couldn't finish the thought sorry.

Edited by Gunman
Posted
1 hour ago, Gunman said:

@sinclair666
Only thing I can think of at the moment since I am tired but should work. First you can grab the closest fishing spot like I did below then grab the position and tell it the fishing spot you want is != to the second closest fishing spot's position.


NPC closestfishingSpot = getNpcs().closest(npc -> npc != null && npc.getName().equals("Fishing spot"));
        
NPC fishingSpot = getNpcs().closest(npc -> npc != null && npc.getName().equals("Fishing spot") && npc.getPosition() != closestfishingSpot.getPosition());

EDIT 1 Hold up I just had an idea and need a sec to test if it would work.
EDIT 2 : Nope nvm brian.exe stopped working and couldn't finish the thought sorry.

Thanks

1 hour ago, FuryShark said:

 


List<NPC> fishingSpots = getNpcs().filter(new NameFilter<>("Fishing spot"));

 

 

Couldn't seem to get this working, the IDE is highlighting <NPC> and giving the error "Type java.awt.list does not have type parameters"

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...