Jump to content

How to get entity (ignoring which is closest)


sinclair666

Recommended Posts

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.

Link to comment
Share on other sites

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

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"

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...