Lua API reference
Version 0.10.0 of the GAMPEON Lua API (Lua 5.4). Everything a script can use is listed here; anything else does not exist.
| Function | Side | What it does |
|---|---|---|
AddEventHandler |
Server and client | Run a function whenever an event fires. |
RemoveEventHandler |
Server and client | Remove a handler added with AddEventHandler. |
RegisterNetEvent |
Server and client | Allow an event to arrive from the other side (client to server or server to client). |
RegisterServerEvent |
Server and client | Old name of RegisterNetEvent, kept for ported FiveM scripts. |
TriggerEvent |
Server and client | Fire an event for all resources on the same side. |
CancelEvent |
Server and client | Cancel the event whose handler is running. |
WasEventCanceled |
Server and client | Check if a handler canceled the last event fired with TriggerEvent. |
TriggerServerEvent |
Client only | Send an event from the client to the server. |
TriggerClientEvent |
Server only | Send an event from the server to one player or to everyone. |
CreateThread |
Server and client | Run a function as its own thread, starting with the next tick. |
Wait |
Server and client | Pause the current thread. |
SetTimeout |
Server and client | Run a function once after a delay. |
Citizen.CreateThread |
Server and client | Same as CreateThread. Kept for ported FiveM scripts. |
Citizen.Wait |
Server and client | Same as Wait. Kept for ported FiveM scripts. |
Citizen.SetTimeout |
Server and client | Same as SetTimeout. Kept for ported FiveM scripts. |
exports |
Server and client | Offer a function to other resources, or call one. |
GetCurrentResourceName |
Server and client | Name of the resource this script belongs to. |
GetGameTimer |
Server and client | Milliseconds since the runtime started. Use it to measure time. |
GetHashKey |
Server and client | Hash of a name, for example of a model name. Same numbers as in FiveM. |
IsDuplicityVersion |
Server and client | True on the server, false on the client. |
json.encode |
Server and client | Turn a Lua value into a JSON string. |
json.decode |
Server and client | Turn a JSON string into a Lua value. |
print |
Server and client | Write a line to the server or client log, tagged with the resource name. |
load |
Server and client | Compile Lua source text. Precompiled bytecode is refused. |
RegisterCommand |
Server and client | Add a command for the console, the chat (/name) or key bindings. |
ExecuteCommand |
Server and client | Run a console command, as if typed into the server console. |
GetRegisteredCommands |
Server and client | List all commands that resources registered on this side. |
IsPlayerAceAllowed |
Server only | Check if a player has a permission (ACE). |
GetConvar |
Server and client | Read a convar as text. |
GetConvarInt |
Server and client | Read a convar as a whole number. |
GetConvarFloat |
Server and client | Read a convar as a number with decimals. |
GetConvarBool |
Server and client | Read a convar as true or false. |
SetConvar |
Server only | Set a convar on the server. |
SetConvarReplicated |
Server only | Set a convar that clients can read too. |
SetConvarServerInfo |
Server only | Set a convar that is shown in the server list. |
PerformHttpRequest |
Server only | Send a web request and get the answer in a callback. |
GetInvokingResource |
Server and client | Name of the resource that called the current export or triggered the current local event. |
LoadResourceFile |
Server and client | Read a file from a resource folder. |
SaveResourceFile |
Server only | Write a file into the own resource folder. |
GetResourceState |
Server and client | Check if a resource runs. |
GetNumResources |
Server and client | Number of running resources on this side. |
GetResourceByFindIndex |
Server and client | Name of the running resource at an index, for loops over all resources. |
GetResourcePath |
Server only | Folder of a resource on the server. |
GetResourceMetadata |
Server and client | Read a value from the manifest of a running resource. |
GetNumResourceMetadata |
Server and client | How many values a manifest directive has. |
vector2 |
Server and client | Create a vector2 with 2 numbers (x, y). |
vec2 |
Server and client | Short name for vector2. |
vector3 |
Server and client | Create a vector3 with 3 numbers (x, y, z). |
vec3 |
Server and client | Short name for vector3. |
vector4 |
Server and client | Create a vector4 with 4 numbers (x, y, z, w). |
vec4 |
Server and client | Short name for vector4. |
vec |
Server and client | Create a vector with 2, 3 or 4 numbers. |
promise.new |
Server and client | Create a promise that is resolved later. |
promise.resolve |
Server and client | Create a promise that is already resolved. |
promise.reject |
Server and client | Create a promise that is already rejected. |
promise.all |
Server and client | Wait for several promises; resolves with a list of their first values. |
promise.first |
Server and client | Resolve with the first promise that finishes. |
promise.race |
Server and client | Same as promise.first. |
Citizen.Await |
Server and client | Pause the current thread until a promise is resolved, then return its values. |
Citizen.Trace |
Server and client | Write to the server or client log, like print. |
MySQL.query |
Server only | Run a query. SELECT returns the rows; other statements return { affectedRows, insertId }. |
MySQL.single |
Server only | Run a query and return only the first row. |
MySQL.scalar |
Server only | Run a query and return the first column of the first row. |
MySQL.insert |
Server only | Run an INSERT and return the new ID. |
MySQL.update |
Server only | Run an UPDATE or DELETE and return the number of changed rows. |
MySQL.prepare |
Server only | Run a statement with ? placeholders, also many times with a list of parameter lists. |
MySQL.rawExecute |
Server only | Run a query and return the raw result. |
MySQL.execute |
Server only | Old name of MySQL.query. |
MySQL.transaction |
Server only | Run several statements in one transaction. If one fails, none of them is kept. |
MySQL.ready |
Server only | Run a function once the database is ready. |
MySQL.Async |
Server only | Old mysql-async names: fetchAll, fetchScalar, fetchSingle, insert, execute, transaction (callback form). |
MySQL.Sync |
Server only | Old mysql-async names that wait for the result: fetchAll, fetchScalar, fetchSingle, insert, execute, transaction. |
GetPlayers |
Server only | List the IDs of all players on the server. |
GetNumPlayerIndices |
Server only | Number of players on the server. |
GetPlayerFromIndex |
Server only | Player ID at a position in the player list. |
DoesPlayerExist |
Server only | Check whether a player ID is on the server. |
GetPlayerName |
Server and client | Display name of a player. |
GetPlayerIdentifiers |
Server only | All identifiers of a player. |
GetNumPlayerIdentifiers |
Server only | Number of identifiers of a player. |
GetPlayerIdentifier |
Server only | One identifier of a player by position. |
GetPlayerIdentifierByType |
Server only | The identifier of a player with a given prefix. |
GetPlayerEndpoint |
Server only | Network address of a player, as far as the server shares it. |
GetPlayerPing |
Server only | Round-trip time to a player in milliseconds. |
GetPlayerLastMsg |
Server only | Milliseconds since the last network event from a player. |
PlayerId |
Client only | Handle of your own player on the client. Pass it to GetPlayerServerId or GetPlayerName. |
GetPlayerServerId |
Client only | Server ID (source) of a player, as server scripts see it. |
DropPlayer |
Server only | Disconnect a player with a reason. |
GetPlayerPed |
Server and client | A player’s character (ped). |
PlayerPedId |
Client only | Your own character (ped) on the client. |
DoesEntityExist |
Server and client | Check if an entity handle still points to an entity. |
GetEntityCoords |
Server and client | Position of an entity in meters. |
GetEntityHeading |
Server and client | Direction an entity faces, in degrees. |
GetEntityForwardVector |
Server and client | Unit vector in the direction an entity faces. |
GetEntityForwardX |
Server and client | X part of GetEntityForwardVector. |
GetEntityForwardY |
Server and client | Y part of GetEntityForwardVector. |
GetEntityVelocity |
Server and client | Speed and direction of an entity in meters per second. |
GetEntityType |
Server and client | Kind of entity. |
SetEntityCoords |
Server only | Teleport an entity to a position in meters. |
SetEntityHeading |
Server only | Turn an entity to face a direction in degrees. |
GetEntityModel |
Server and client | Model of an entity as a hash. |
IsModelValid |
Server and client | Check if the game knows a model that CreateObject or CreateVehicle can create. |
IsModelAVehicle |
Server and client | Check if a model is a vehicle model. |
CreateObject |
Server only | Create an object in the world for every player. |
CreateObjectNoOffset |
Server only | Same as CreateObject. |
CreateVehicle |
Server only | Create a vehicle in the world for every player. |
DeleteEntity |
Server only | Delete an entity that a script created. |
FreezeEntityPosition |
Server only | Hold an entity in place without physics, or let it move again. |
Gampeon.ChatAddMessage |
Client only | Show a line in the chat window of the game. |
Gampeon.ChatClear |
Client only | Remove all lines from the chat window. |
Gampeon.ChatAddSuggestion |
Client only | Suggest a command while the player types in the chat window. |
Gampeon.ChatRemoveSuggestion |
Client only | Remove a command suggestion. |
StartResource |
Server only | Start a resource and its dependencies. |
StopResource |
Server only | Stop a resource and everything that depends on it. |
SendNUIMessage |
Client only | Send data to the page of this resource. |
SendNuiMessage |
Client only | Send a JSON text to the page of this resource. |
RegisterNUICallback |
Client only | Answer requests from the page of this resource. |
SetNuiFocus |
Client only | Give keyboard and mouse to the pages, or give them back to the game. |
SetNuiFocusKeepInput |
Client only | Let the game keep getting keyboard input while a page has focus. |
IsNuiFocused |
Client only | Whether a page has the keyboard focus. |
IsNuiFocusKeepingInput |
Client only | Whether the game keeps keyboard input while a page has focus. |
EnableBlockWorld |
Server only | Switch on the block world of this server. |
IsBlockWorldEnabled |
Server and client | Check whether this server has a block world. |
GetBlockWorldSeed |
Server only | Seed of the block world. |
GetBlock |
Server and client | Block at a position. |
SetBlock |
Server only | Change a block for every player. |
GetBlockSurfaceZ |
Server and client | Height of the highest solid block in a column. |
IsBlockProtected |
Server and client | Check whether a position is inside a zone or outside the world, where nobody can change blocks. |
GetBlockTypes |
Server and client | All block types. |
GetBlockTarget |
Client only | Block under the crosshair within reach. |
SetBlockHotbar |
Client only | Blocks the player can place, in the slots of the hotbar. |
GetBlockHotbarSlot |
Client only | Selected slot of the hotbar. |
SetBlockControlsEnabled |
Client only | Turn digging and placing with the mouse on or off for this player. |
SetBlockHudVisible |
Client only | Show or hide the built-in crosshair, block outline and hotbar. |
Globals
Section titled “Globals”source: ID of the player who sent the network event that is being handled.
Events
Section titled “Events”onResourceStart: A resource has started. Fired for every resource, including your own.onResourceStop: A resource is stopping. Save data here.playerJoining: A player joined and was verified.sourceis the new player ID.playerDropped: A player left.sourceis the player ID; GetPlayerName and GetPlayerIdentifiers still work inside the handler.gampeon:chatInput: The player pressed Enter in the chat window of the game. The built-in chat resource handles it.gampeon:nuiFocusReleased: The player held Escape for 2 seconds and took mouse and keyboard back from a web interface. The page stays visible, so close your menu here.blockBreak: A player wants to dig a block.sourceis the player. Call CancelEvent to keep the block, before any Wait.blockPlace: A player wants to place a block.sourceis the player. Call CancelEvent to refuse, before any Wait.blockChanged: A block changed, by a player or by SetBlock. Arrives right after the change, in the next server tick.blockHotbarSelect: The player picked another slot of the hotbar.
The same reference is available as JSON at /reference/lua-api.json and as type definitions for editors (see Editor setup).