Viston Posted June 25, 2017 Share Posted June 25, 2017 (edited) So I'm trying to make the bot not attack the NPC that is under attack. I tried using !closestMonster.isInteracting() but no luck. NPC closestMonster = s.getNpcs().closest(Vars.radius, Vars.combatMonster); if (closestMonster != null && !closestMonster.isAttackable() && s.getInventory().contains(Vars.combatFood)) { s.getWalking().walk(closestMonster); } else if (closestMonster != null && !s.myPlayer().isUnderAttack() && s.getInventory().contains(Vars.combatFood)) { if (s.myPlayer().isAnimating()) { Vars.lastAnimation = System.currentTimeMillis(); } else if (closestMonster.interact("Attack") && System.currentTimeMillis() > (Vars.lastAnimation + 1000)) { Paint.status = "Attacking..."; Sleep.sleepUntil(() -> s.myPlayer().isUnderAttack(), 5000); } } Edited June 25, 2017 by Visty Quote Link to comment Share on other sites More sharing options...
Adept Posted June 25, 2017 Share Posted June 25, 2017 (edited) I imagine you don't want to attack an NPC which is under attack, but you want to attack one which is not. Here's how to find that monster: NPC notUnderAttack = getNpcs().closest(new Filter<NPC>() { @Override public boolean match(NPC npc) { return !npc.isUnderAttack() && !npc.isAnimating(); } }); Edited June 25, 2017 by Adept Quote Link to comment Share on other sites More sharing options...
Viston Posted June 25, 2017 Author Share Posted June 25, 2017 (edited) 7 minutes ago, Adept said: I imagine you don't want to attack an NPC which is under attack, but you want to attack one which is not. Here's how to find that monster: NPC notUnderAttack = getNpcs().closest(new Filter<NPC>() { @Override public boolean match(NPC npc) { return npc.isAttackable() && !npc.isHitBarVisible() && !npc.isAnimating(); } }); But will that fix the issue with people splashing on NPCs? Because, isUnderAttack() seems to fix the issue with people normally attacking the NPC. But when people splash on NPCs, you can't see their HitBar, so it doesn't work Edited June 25, 2017 by Visty Quote Link to comment Share on other sites More sharing options...
Adept Posted June 25, 2017 Share Posted June 25, 2017 (edited) Don't quote me on this but I believe NPCs "animate" when under attack (and are being splashed on) so !npc.isAnimating() should take care of that. Also, I just checked the API and the "!npc.isUnderAttack()" check in the filter I provided earlier is redundant since it's already checked for with "npc.isAttackable()". However since you explicitly stated to check for an NPC which is not under attack and not one which is attackable it makes more sense to keep the former. Edited my reply to reflect that. Edited June 25, 2017 by Adept Quote Link to comment Share on other sites More sharing options...
Alek Posted June 25, 2017 Share Posted June 25, 2017 Try checking out my Macro Killer source code, I made it public. 1 Quote Link to comment Share on other sites More sharing options...
Eliot Posted June 25, 2017 Share Posted June 25, 2017 (edited) I think this will work for you. NPC npc = getNpcs().closest(npc -> npc.getName().equals(npcName) && npc.getInteracting() == null && !npc.isUnderAttack()); If an NPC is being splashed on #getInteracting will not return null (iirc). Edited June 25, 2017 by Eliot 2 Quote Link to comment Share on other sites More sharing options...
Viston Posted June 26, 2017 Author Share Posted June 26, 2017 (edited) 3 hours ago, Eliot said: I think this will work for you. NPC npc = getNpcs().closest(npc -> npc.getName().equals(npcName) && npc.getInteracting() == null && !npc.isUnderAttack()); If an NPC is being splashed on #getInteracting will not return null (iirc). I appreciate your responds. Your piece of code works Also, just noticed that my code above checks useless stuff in the If statements lel Edited June 26, 2017 by Visty 1 Quote Link to comment Share on other sites More sharing options...
Viston Posted June 26, 2017 Author Share Posted June 26, 2017 3 hours ago, Alek said: Try checking out my Macro Killer source code, I made it public. Thank you, will do Quote Link to comment Share on other sites More sharing options...
Eliot Posted June 26, 2017 Share Posted June 26, 2017 51 minutes ago, Visty said: I appreciate your responds. Your piece of code works Also, just noticed that my code above checks useless stuff in the If statements lel Awesome! I'm glad I could help. Quote Link to comment Share on other sites More sharing options...
noidlox_ban_9 Posted June 26, 2017 Share Posted June 26, 2017 7 hours ago, Alek said: Try checking out my Macro Killer source code, I made it public. Link? Quote Link to comment Share on other sites More sharing options...
slazter Posted June 27, 2017 Share Posted June 27, 2017 On 2017-06-26 at 5:55 AM, noidlox_ban_9 said: Link? Quote Link to comment Share on other sites More sharing options...