timer

From Arx Libertatis Wiki
Revision as of 07:18, 24 July 2022 by Ds (talk | contribs) (Created page with "{{ScriptCommandPage |description=start or stop a timer |context=any |default=0 |special= [-mi] count interval command <name [-mi] count interval command <name off kill_local |flags= m Duration is given in milliseconds instead of seconds i Only run the timer if the player is near the entity |parameters= name string Timer name - must be directly after the command name and all underscores are ignored count int* Number of times that the timer should fire - 0 to repeat indefi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The 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 for the calling entity use timer kill_local, which is the only way to stop unnamed timers (short of destroying the entity).

ℹ️  Unlike all other commands and their parameters, the optional timer name parameter comes directly after the command name without any space and before any flags. All underscores in the timer name are ignored.

⚠️
Save files store the byte offset of the command that is to be run when the timer fires and the same byte position will be used when the timer fires even if the script is changed. Mods need to take care never to change the position of any timer commands if they want to stay compatible with old save files.

If you don't want to run anything after after the timer expired but want to check if a certain amount of time has elapsed then see the starttimer command.

Usage

timer [-mi] <count*> <interval*> <command...>
timer<name> [-mi] <count*> <interval*> <command...>
timer<name> off
timer kill_local

Context: Any Entity

Flags:

 -m: Duration is given in milliseconds instead of seconds
 -i: Only run the timer if the player is near the entity

Parameters:

ParameterTypeDescription
name string Timer name - must be directly after the command name and all underscores are ignored
count int or variable Number of times that the timer should fire - 0 to repeat indefinitely
interval int or variable Number of seconds (or milliseconds with -m) until the timer firers
command command A command to execute each time the timer fires

The specified <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 <count> is 0 then the timer repeats forever until it is stopped manually.

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".