Jump to content

getNPCS().closest, i want to find the second closest npc cause closest is in combat


Recommended Posts

Posted

Without using OSBot filters/DIY: You can do this by grabbing all the NPCs and then sorting the collection with a Comparator. Once you have this sorted collection you can iterate through them to check for everything else such as already in combat, health, etc. Of course you can do this in reverse and filter NPCs that aren't in combat, have high health, etc. and then go on to sort the collection.

  • Like 1
  • 2 weeks later...
Posted
getNpcs().closest(NPC NAME, (n) -> (!n.isUnderAttack()));

 

For some reason im getting an error in eclipse im not sure if im using it correctly.

NPC npc;
npc = script.getNpcs().closest(target,(n) -> (!n.isUnderAttack()));

(script is being passed into the constructor and save in a private variable)

Posted (edited)

For some reason im getting an error in eclipse im not sure if im using it correctly.

NPC npc;npc = script.getNpcs().closest(target,(n) -> (!n.isUnderAttack()));
(script is being passed into the constructor and save in a private variable)
Your fine then. Booby rocket wrote it like that assuming the class extended script. But if you are using a private field it's ok.

The error is probably because your project isn't compile under java 8

Edited by Joseph

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