Tomm0017/rsmod

Npcs can still random walk when one shotted.

old-kyle-escabar opened this issue · 1 comments

Current Behavior

When one hitting a npc. The random walk timer still can trigger them to walk around before the death animation ends.

Expected Behavior

The walk timer does not fire if npc.isAlive() == false

Steps to Reproduce the Problem

  1. One shot any npc a few times and you will see it.

Below is the following fix for this. Tested and all appears to be working.
Changes made to the npc_random_walk.plugin.kts file.

on_timer(SEARCH_FOR_PATH_TIMER) {
    if (npc.isActive() && npc.isAlive()) {
        val facing = npc.attr[FACING_PAWN_ATTR]?.get()
        if (facing == null) {
            val rx = world.random(-npc.walkRadius..npc.walkRadius)
            val rz = world.random(-npc.walkRadius..npc.walkRadius)

            val start = npc.spawnTile
            val dest = start.transform(rx, rz)

            /*
             * Only walk to destination if the chunk has previously been created.
             */
            if (world.collision.chunks.get(dest, createIfNeeded = false) != null) {
                npc.walkTo(dest)
            }
        }
    }

    npc.timers[SEARCH_FOR_PATH_TIMER] = world.random(SEARCH_FOR_PATH_DELAY)
} 

Added && npc.isAlive() to the global if() logic