Jump to content

Recommended Posts

Posted

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.

  • 2 weeks later...
Posted

That is a good question because if you do it separately it dose not seem to be global. But if you clone them it seems to be  the same timer????

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.