Jump to content

AutoFighter script not running smooth


Prolax

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...