Concepts/Timers

NewTimer("functionName", intervalMs, repeatCount [, args...]) calls the global function functionName every intervalMs milliseconds. repeatCount 0 means "forever". Up to 8 extra arguments (any value, including player/vehicle handles) are passed to every call. The function is looked up by name each time it fires, so it must be a global function (not a local). The returned Timer handle can be stopped, restarted, reset and deleted.

function ShowTip(player, text) { SmallMessage(player, text, 4000); }

function onPlayerSpawn(player, classID)
{
    NewTimer("ShowTip", 3000, 1, player, "Press TAB for the scoreboard");  // once, after 3 s
}

local clock = NewTimer("Tick", 1000, 0);    // forever, every second
function Tick() { /* ... */ }

Server limit: 128 timers. If the function named by a timer no longer exists, the server skips the call. On the client the timer is silently deleted.

Categories: Core concepts