Explv Posted May 15, 2017 Posted May 15, 2017 3 minutes ago, Prolax said: Hmm, still attacks the npc twice. Anything I can add? Sorry, previous answer was completely wrong, not sure why I wrote that, try storing the seagull in a global variable, and checking like this: private NPC seagull; @Override public final int onLoop() throws InterruptedException { if (seagull == null || !myPlayer().isInteracting(seagull)) { attackNpc(); } return random(100,300); } And of course assign seagull in your attackNPC method
Prolax Posted May 16, 2017 Author Posted May 16, 2017 22 hours ago, Explv said: Sorry, previous answer was completely wrong, not sure why I wrote that, try storing the seagull in a global variable, and checking like this: private NPC seagull; @Override public final int onLoop() throws InterruptedException { if (seagull == null || !myPlayer().isInteracting(seagull)) { attackNpc(); } return random(100,300); } And of course assign seagull in your attackNPC method public final class ProlaxAutoFighter extends Script { private NPC seagull; @Override public final int onLoop() throws InterruptedException { seagull = getNpcs().closest(npc -> npc.getName().equals("Seagull")); if (!myPlayer().isInteracting(seagull) && seagull != null && !seagull.isUnderAttack() && seagull.getHealthPercent() > 0 && !getCombat().isFighting()) { attackNpc(); } return random(100,300); } public void attackNpc(){ NPC seagull = getNpcs().closest(npc -> npc.getName().equals("Seagull")); seagull.interact("Attack"); new ConditionalSleep(3000,500) { @Override public boolean condition() { return seagull.getHealthPercent() == 0 || getCombat().isFighting() || seagull == null; } }.sleep(); } } Runs pretty good now. Is there any better way to store the seagull variable once?