I'm sure I'm doing something silly here, but I'm starting a timer in an NPC's init callback, and when I clone that NPC, it seems like all subsequent copies are having their timer callback invoked immediately.
It works fine if I clone the NPC before without enabling the script: when I spawn three, and enable each NPC's script separately, it works how I would expect it to.
What am I doing wrong? I assume that cloning is not how I should be doing this, but I don't know how to "save" an npc with scripts turned on.
My script:
var LIFESPAN = 255;
var DEATH_ID = 0;
function init(event){
event.npc.say("I live...");
event.npc.getTimers().start(DEATH_ID, LIFESPAN, false);
}
function timer(event){
if (event.id === DEATH_ID) {
event.npc.say("...now I die");
event.npc.despawn();
}
}
The goal is to have an NPC automatically despawn on a timer after they spawn.