GamesLauncherNewsDocsCommunityMy accountMy serversDownload Launcher
DocsLua scripting

Lua API reference

Every function the server gives your Lua scripts.

#Output

FunctionWhat it does
print(...)Writes to the server log.

#Events

FunctionWhat it does
AddEventHandler(name, fn)Listen for an event.
TriggerEvent(name, ...)Local event to all resources.
RegisterNetEvent(name [, fn])Allow an event from clients.
RegisterServerEvent(name [, fn])Alias for RegisterNetEvent.
TriggerClientEvent(name, playerId, ...)Event to one client, or all with -1.
sourceThe player's id inside a net event.

See Events and Net events.

#Messages

FunctionWhat it does
SendMessage(playerId, text)Message on the player's screen. -1 = all players.

#Threads and time

FunctionWhat it does
CreateThread(fn)Start a coroutine.
Wait(ms)Wait (only inside a thread).
SetTimeout(ms, fn)Run fn after ms milliseconds.
Citizen.CreateThread / Wait / SetTimeout / TraceFiveM aliases.
GetGameTimer() -> integerMilliseconds since the server started.

#Players

FunctionWhat it does
GetPlayers() -> { id, ... }All players (whole numbers).
GetNumPlayers() -> integerNumber of players.
GetMaxPlayers() -> integersv_maxplayers.
GetPlayerName(id) -> stringThe player's name.
GetPlayerPing(id) -> integerPing in ms.
DropPlayer(id, reason)Kick the player with a reason.

#Configuration

FunctionWhat it does
GetConvar(name, default) -> stringA value from server.cfg.
GetConvarInt(name, default) -> integerA whole-number value from server.cfg.

sv_licenseKey always returns the default.

#Commands

FunctionWhat it does
RegisterCommand(name, fn(source, args, raw)) -> booleanAdd a console command.
ExecuteCommand(commandLine)Run a console command.

#Resources

FunctionWhat it does
GetCurrentResourceName() -> stringThe name of this resource.
StartResource(name)Start a resource.
StopResource(name)Stop a resource.

#Files

FunctionWhat it does
LoadResourceFile(resource, file) -> string or nilRead a file in the resource.
SaveResourceFile(resource, file, data) -> booleanWrite a file in the resource.

#JSON

FunctionWhat it does
json.encode(value) -> stringTable to JSON.
json.decode(text) -> valueJSON to table.

#Modules

FunctionWhat it does
require(modname)Load a module from the resource's own folder.

Last updated 2026-12-06