timer script command is used to start or stop a timer for an entity. Timers can optionally be given a name which can be used to stop that specific timer using
timer off. Using the same non-empty name again will replace the timer as if
timer off was called before the second invocation. Multiple anonymous timers with no name can be started at the same time.
To stop all timers set by the entity instance script for the calling entity use
timer kill_local. This will also prevent the completion command from an in-progress
playanim -e command called from the entity instance script from being run. Unnamed timers for entity class scripts cannot be stopped prematurely (short of destroying the entity).
If you don't want to run anything exactly when some time expires but only want to check if a certain amount of time has elapsed then see the
timer [-mi] <count*> <interval*> <command...>
timer<name> [-mi] <count*> <interval*> <command...>
Context: Any Entity
-m: Duration is given in milliseconds instead of seconds
-i: Only run the timer if the player is near the entity
||Timer name - must be directly after the command name and all underscores are ignored|
||Number of times that the timer should fire - 0 to repeat indefinitely|
||Number of seconds (or milliseconds with
||A command to execute each time the timer fires|
<command> is run
<count> times, each time after the given
<interval> has elapsed since the last time (or since the
timer command was executed). If
0 then the timer repeats forever until it is stopped manually. Timers with interval 0 fire once per frame.
Idle timers started with the
-i flag will only execute the given command if the timer fires while the player is "near" the entity. The times when the player is not near the entity do not count against the given
<count> - e.g.
timer -i 1 1 herosay hello will display
hello exactly once when the player gets near to the calling entity. Scripts should not rely on the exact definition of "near" except that all visible entities or those in the same room as the player are considered to be "near". Instead of idle timers you can listen for the heartbeat event set using
main by default) if you do not require any precise timing guarantees.