Menu

Initnpctimer

Brynner

Syntax

Description

This script command will begin an NPC-attached timer on the running or
specified NPC. The timer will run internally in the NPC and is not attached to
any player, so will continue to run even when there are no players logged on.
It is important to note that an NPC can only run a single timer on itself at
any given time. In order to process multiple timers, the script would have to
use player based timers such as [Addtimer].

The timer runs in milliseconds (1/1000th of a second) from 0, and calling this
script command will begin a new timer (if a timer is not already running on
the NPC) or reset the current timer on the NPC. To completely stop the NPC
timer, the script command [Stopnpctimer] must be called, and to resume the
timer (without resetting the current tick) the script command
[Startnpctimer] must be called.

The script can access a timer event by creating a label matching the format
"OnTimer<tick>:" where the <tick> is replaced with a millisecond value to
occur on. The NPC timer does not reset automatically once reaching one of
these labels, therefore it is possible to multiple labels with incremented
<tick> values to handle the same NPC timer (see #Examples).

Parameters

Attach Flag

The flag value determines whether a player should be directly associated with
this NPC timer. When flag is specified (a value of 1) the script will attach
the player who is currently attached to the script, to the timer. If no player
is attached to the script when this flag is specified, then the
[Initnpctimer] call will fail.

If a player is successfully attached to the NPC timer, and logs out of the
game, then the event label "OnTimerQuit:" will run on the NPC (the player will
still be logged in at this point) to allow cleaning up and handling of the
timer.

NPC Name

If specified, the call to [Initnpctimer] will not apply to the current
running script but will take effect on the NPC which exists with the passed
NPC name. If an NPC could not be found with this name then the
[Initnpctimer] call will fail.

Examples

  • Announce every 1 second (resetting the timer after every 1000 milliseconds)

    initnpctimer;
    end;
    

    [OnTimer]1000:
    [Announce] "1 second has passed!", bc_all|bc_npc;
    initnpctimer;
    [End];

  • Announce at 5 and 10 seconds (stopping the timer once 10000 milliseconds is reached)

    initnpctimer;
    end;
    

    [OnTimer]5000:
    [Announce] "5 seconds have passed!", bc_all|bc_npc;
    [End];

    OnTimer10000:
    announce "10 seconds have passed!!", bc_all|bc_npc;
    [Stopnpctimer];
    end;

  • Perform an event on a player every 60 seconds (resetting the timer after every 60000 milliseconds)

    initnpctimer 1;
    end;
    

    [OnTimer]60000:
    [Percentheal] 10, 0;
    [Message] Strcharinfo, "You were healed 10% HP!";
    initnpctimer 1;
    [End];

    OnTimerQuit:
    [Stopnpctimer];
    [End];

[Category:Script Command]


Related

Wiki: Addtimer
Wiki: Announce
Wiki: End
Wiki: Initnpctimer
Wiki: Message
Wiki: OnTimer
Wiki: Percentheal
Wiki: Startnpctimer
Wiki: Stopnpctimer
Wiki: Timers (Scripting)

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.