Runtime and Events
Scheduler
Client / Server
| Function | Returns | Purpose |
|---|---|---|
CreateThread(callback) | task ID | Starts a managed coroutine. Alias: Citizen.CreateThread. |
Wait(milliseconds) | none | Yields the current managed coroutine. Alias: Citizen.Wait. |
SetTimeout(milliseconds, callback) | task ID | Runs once after a delay. |
ClearTimeout(taskId) | boolean | Cancels a scheduled task. |
SetInterval(milliseconds, callback) | task ID | Runs repeatedly. |
ClearInterval(taskId) | boolean | Cancels an interval. |
Schedule(expression, callback) | task ID | Runs a five- or six-field cron expression. |
lua
CreateThread(function()
while true do
Wait(1000)
print('tick')
end
end)
Schedule('0 */5 * * * *', function()
print('every five minutes')
end)Avoid unbounded Wait(0) loops. The runtime enforces queue, callback, wakeup, and CPU budgets per resource.
Events
| Function | Side | Purpose |
|---|---|---|
AddEventHandler(name, callback) | Client / Server | Handles a local event. |
RegisterNetEvent(name, callback) | Client / Server | Handles local and network calls. |
TriggerEvent(name, ...) | Client / Server | Emits on the current process. |
TriggerServerEvent(name, ...) | Client | Sends JSON-serialized arguments to the server. |
TriggerClientEvent(name, peerId, ...) | Server | Sends arguments to one client. |
Custom event names are case-insensitive. Network handlers receive the sender in global source.
Commands and permissions
lua
RegisterCommand(commandName, callback, restricted)
Command.Execute(rawCommand, sourcePeer)
HasPermission(permission)
Player.HasPermission(peerId, permission)
IsPlayerAceAllowed(source, ace)
IsPlayerAdmin()restricted may be false, true for command.<name>, or an explicit ACE string. Permission-sensitive logic belongs on the server.
Exports
lua
exports('getState', function()
return { active = true }
end)
local state = exports['other_resource'].getState()Exports are synchronous and stay on the current side. A missing or failing export returns nil and writes an error to the log.
Convars
lua
GetConvar(key, defaultValue)
GetConvarInt(key, defaultValue)
GetConvarFloat(key, defaultValue)
GetConvarBool(key, defaultValue)
SetConvar(key, value)
SetReplicatedConvar(key, value)Resource-local variants use the GetResourceConvar* and SetResourceConvar* prefixes. Only server values are authoritative; setr values are replicated to clients, while sets values remain engine-only secrets.