Skip to content

LuaAPI Timers

itvnnnd87 edited this page Oct 24, 2026 · 3 revisions

Timers

Time events

In System\Timers.lua:

Function Called when
onTimerProcessSecond() Every second.
onTimerProcessMinute() When a new minute starts.
onTimerProcessHour() When a new hour starts.
onTimerProcessDayChange() When a new day starts (00:00).

Script timers

Unit: seconds (whole seconds, at least 1). Creating a timer with an existing name replaces the old one. An error in one timer is written to the log and does not affect the others. Timers are cleared when LuaAPI is reloaded.

The callback receives n, the number of times the timer has run so far (1, 2, 3 ...). If the callback is not a function, the timer is not created, the error is logged and the function returns false.

Daily / weekly events from an XML schedule: see Scheduler.

Timer.Create

Timer.Create(seconds, name, function() ... end) → boolean

Runs the function once after seconds, then the timer is removed.

Message.SendAll(0, "The server will save in 30 seconds")
Timer.Create(30, "SaveNotice", function()
    Message.SendAll(0, "Saved. Thank you for waiting")
end)

Timer.CreateRepeating

Timer.CreateRepeating(seconds, name, function(n) ... end) → boolean

Runs the function every seconds until the timer is removed.

-- every 10 minutes: a reminder for everyone
Timer.CreateRepeating(600, "Reminder", function(n)
    Message.SendAll(0, "Remember to vote for the server! (" .. n .. ")")
end)

Timer.RepeatNTimes

Timer.RepeatNTimes(seconds, name, times, function(n) ... end) → boolean

Runs the function every seconds, times times (n = 1..times), then the timer is removed.

-- 10 second countdown
Timer.RepeatNTimes(1, "Countdown", 10, function(n)
    Message.SendAll(0, "The event starts in " .. (11 - n) .. " seconds")
end)

Timer.Remove

Timer.Remove(name)

Removes the timer. Nothing happens if it does not exist.

function Invasion_End()
    Timer.Remove("InvasionWave")
    Message.SendAll(0, "The invasion is over")
end

Timer.Exists

Timer.Exists(name) → boolean

true if the timer still exists (paused timers included).

if Timer.Exists("Countdown") then
    Message.Send(aIndex, 1, "The countdown is already running")
    return 1
end

Timer.GetRemaining

Timer.GetRemaining(name) → number

Seconds until the next run, 0 if the timer does not exist.

if Timer.Exists("SaveNotice") then
    Message.Send(aIndex, 1, "Save in " .. Timer.GetRemaining("SaveNotice") .. " seconds")
end

Timer.Stop

Timer.Stop(name) → boolean

Pauses the timer (it keeps its remaining time). Returns false if the timer does not exist.

if Timer.Stop("InvasionWave") then
    Message.SendAll(0, "The invasion is paused")
end

Timer.Start

Timer.Start(name) → boolean

Resumes a paused timer. Returns false if the timer does not exist.

if Timer.Start("InvasionWave") then
    Message.SendAll(0, "The invasion goes on in " .. Timer.GetRemaining("InvasionWave") .. " seconds")
end

Timer.IsActive

Timer.IsActive(name) → boolean

true if the timer exists and is not paused.

if Timer.Exists("InvasionWave") and not Timer.IsActive("InvasionWave") then
    Message.Send(aIndex, 1, "The invasion is paused")
end

Next: Safety and languages

Clone this wiki locally