MGT Madness Posted November 15, 2015 Share Posted November 15, 2015 As title says, this is because the closest npc is already in combat, so i'd like the bot to find the second closest npc to attack. Rather than sit there until a new close npc spawns xD - Thank you for your time Quote Link to comment Share on other sites More sharing options...
Nitrousek Posted November 15, 2015 Share Posted November 15, 2015 There's better way. Don't use closest at all. Filter through all the npcs and find ones that are not in combat. use npcs.getAll() for example : For(NPC n : npcs.getAll()) { if (!n.isincombat... etc } 1 Quote Link to comment Share on other sites More sharing options...
Flamezzz Posted November 15, 2015 Share Posted November 15, 2015 You can apply a filter before selecting the closest npc: npcs.closest(n -> !n.isUnderAttack()) Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted November 15, 2015 Share Posted November 15, 2015 getNpcs().closest(NPC NAME, (n) -> (!n.isUnderAttack())); Quote Link to comment Share on other sites More sharing options...
Alek Posted November 15, 2015 Share Posted November 15, 2015 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. 1 Quote Link to comment Share on other sites More sharing options...
Codex Posted November 27, 2015 Share Posted November 27, 2015 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) Quote Link to comment Share on other sites More sharing options...
Joseph Posted November 27, 2015 Share Posted November 27, 2015 (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 November 27, 2015 by Joseph Quote Link to comment Share on other sites More sharing options...
Codex Posted November 27, 2015 Share Posted November 27, 2015 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 Oh right.. I'm sure I have Java 8. cheers anyway! Quote Link to comment Share on other sites More sharing options...
Joseph Posted November 27, 2015 Share Posted November 27, 2015 Oh right.. I'm sure I have Java 8. cheers anyway! you need java 8 to run the apps and jdk 1.8 to be able to code with java 8. Once you have both installed you just change the setting your ide. im on the phone so i can show you right now Quote Link to comment Share on other sites More sharing options...