Lua API reference
Every function the server gives your Lua scripts.
#Output
| Function | What it does |
|---|
print(...) | Writes to the server log. |
#Events
| Function | What 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. |
source | The player's id inside a net event. |
See Events and Net events.
#Messages
| Function | What it does |
|---|
SendMessage(playerId, text) | Message on the player's screen. -1 = all players. |
#Threads and time
| Function | What 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 / Trace | FiveM aliases. |
GetGameTimer() -> integer | Milliseconds since the server started. |
#Players
| Function | What it does |
|---|
GetPlayers() -> { id, ... } | All players (whole numbers). |
GetNumPlayers() -> integer | Number of players. |
GetMaxPlayers() -> integer | sv_maxplayers. |
GetPlayerName(id) -> string | The player's name. |
GetPlayerPing(id) -> integer | Ping in ms. |
DropPlayer(id, reason) | Kick the player with a reason. |
#Configuration
| Function | What it does |
|---|
GetConvar(name, default) -> string | A value from server.cfg. |
GetConvarInt(name, default) -> integer | A whole-number value from server.cfg. |
sv_licenseKey always returns the default.
#Commands
| Function | What it does |
|---|
RegisterCommand(name, fn(source, args, raw)) -> boolean | Add a console command. |
ExecuteCommand(commandLine) | Run a console command. |
#Resources
| Function | What it does |
|---|
GetCurrentResourceName() -> string | The name of this resource. |
StartResource(name) | Start a resource. |
StopResource(name) | Stop a resource. |
#Files
| Function | What it does |
|---|
LoadResourceFile(resource, file) -> string or nil | Read a file in the resource. |
SaveResourceFile(resource, file, data) -> boolean | Write a file in the resource. |
#JSON
| Function | What it does |
|---|
json.encode(value) -> string | Table to JSON. |
json.decode(text) -> value | JSON to table. |
#Modules
| Function | What it does |
|---|
require(modname) | Load a module from the resource's own folder. |
Last updated 2026-12-06