M MY Multiplayer: Wiki
Side
Kind

setTimer

Shared

Calls a function after an interval, once or repeatedly.

timer|false setTimer(function callback, float interval, any ... [, int repeats = 1])

Parameters

NameTypeDescription
callbackfunctionThe function to call.
intervalfloatThe interval in milliseconds, at least 1.
repeatsintHow many times to call it. 0 repeats forever.default 1
...anyArguments passed to the function on every call.

Returns

The timer, or false if the interval is under 1 ms.

A resource's timers stop with it. If the server or the game stalls for several intervals, the timer is called once, not once per missed interval.

Example

local seconds = 10
setTimer(function()
    seconds = seconds - 1
    outputDebugString(seconds .. " seconds left")
end, 1000, seconds)
Coming from MTAThe timer is a number, not an element, and belongs to the resource that created it: other resources cannot see it.

See also