Jump to content

AutoFighter script not running smooth


Recommended Posts

Posted
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

Posted
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?

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