Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question Is there a better way to check if NPC is dead?

Joined
May 14, 2018
Messages
9
Currently using this to delay until the npc is dead:

Code:
if (nearestNpc.interact("Attack")) {
    Execution.delayUntil(() -> !nearestNpc.isValid(), () -> false, 10, 60000, 70000);
}

It works fine, except it's too slow. Between the time that it dies and the time that it becomes invalid, there's a lag (about 1-3 seconds).

I tried doing this instead:

Code:
if (nearestNpc.interact("Attack")) {
    Execution.delayUntil(() -> nearestNpc.getHealthGauge().getPercent() == 0, () -> false, 10, 60000, 70000);
}

and it improves things a bit, but after some time nearestNpc.getHealthGauge().getPercent() throws a null pointer exception. This happens even if I null check it!

So I was wondering if anyone knows of the fastest way to check when an NPC is dead?
 
Joined
Jan 28, 2017
Messages
492
What do you null check nearestNPC, nearestNpc.getHealthGauge() or nearestNpc.getHealthGauge().getPercent()?
 
Joined
May 14, 2018
Messages
9
What do you null check nearestNPC, nearestNpc.getHealthGauge() or nearestNpc.getHealthGauge().getPercent()?

Initially, just nearestNpc.getHealthGauge(). But then getPercent() also threw a NullException, even when getHealthGauge() was NOT null. Weird. So I tried to null check both of them individually, which didn't work for getPercent, it still threw the error.

Anyway, got it sorted by doing:

Code:
Execution.delayUntil(() -> nearestNpc.getHealthGauge() == null, () -> false, 10, 60000, 70000);

and then storing the position of the dead NPC, and filtering the list of NPCS to exclude it (so that the player moves on to the next NPC as soon as it's dead and doesn't keep attacking until its invalid) :

Code:
LocatableEntityQueryResults<Npc> allNpcs = Npcs.newQuery().names(npcNames).off(killedNpcPosition).results().sortByDistance();
 
Joined
May 24, 2016
Messages
1,113
If you are on OSRS, health gauge works as a good solution to determine if an NPC is dying. Getting an NPE from it is likely on your end. Something like this should work:

Code:
Npc npc = Npcs.newQuery().names("test").filter(a -> {
    CombatGauge gauge = a.getHealthGauge();
    return gauge == null || gauge.getPercent() > 0;
}).results().nearest();
 
Top