Globals

Runs inside the game process. Reads and presentation are local; anything that changes shared state has to go through the server.

client runtime19 functionsMarkdown

AddEventHandler(event, handler)

Listens for a local event.

Registers a callback on the current resource's local event bus. The handler is owned by the current resource generation and is discarded automatically when that generation stops or reloads; it never receives network traffic unless the event was separately registered as a network event.

Parameters

  • eventstringrequired
  • handlerfunctionrequired

Returns

  • handler id

Registered in ResourceHost.cpp as LuaAddEventHandler (line 6490).

ClearTimeout(id)

Cancels a timer created by SetTimeout.

Cancels a pending timeout owned by the current resource generation. It returns false when the id is unknown or the callback has already begun; cancelling cannot interrupt a callback that is currently running.

Parameters

  • idintegerrequired

Returns

  • boolean

Registered in ResourceHost.cpp as LuaClearTimeout (line 6489).

CreateThread(body)

Starts a coroutine managed by the host.

Its body may call Wait, which an ordinary function cannot.

Parameters

  • bodyfunctionrequired

Example

CreateThread(function()
    while true do
        print(CyberM.character.speed())
        Wait(1000)
    end
end)

Registered in ResourceHost.cpp as LuaCreateThread (line 6486).

DeleteResourceKvp(key)

FiveM-style alias for CyberM.kvp.delete.

FiveM-familiar alias for CyberM.kvp.delete. It atomically removes only the named key owned by the calling resource and reports whether that key existed.

Parameters

  • keystringrequired

Returns

  • boolean
  • reason

Registered in ResourceHost.cpp as LuaKvpDelete (line 6502).

exports

SHARED

exports(name, body)

Declares a function callable by other resources.

Publishes a named function from the current resource so another resource can call it through CyberM.exports.call. The registration is tied to the current generation, so stale functions cannot survive a stop or hot reload.

Parameters

  • namestringrequired
  • bodyfunctionrequired

Returns

  • boolean

Registered in ResourceHost.cpp as LuaRegisterExport (line 6495).

GetCurrentResourceName()

Name of the current resource.

Returns the immutable manifest name of the resource whose Lua VM is executing. Use it for diagnostics and namespacing, not as a mutable display label.

Returns

  • string

Registered in ResourceHost.cpp as LuaResourceName (line 6496).

GetInvokingResource()

Real caller of the currently executing export.

Returns nil outside an export callback. Use this value for service ownership instead of accepting a forgeable owner argument.

Returns

  • resource name, or nil

Registered in ResourceHost.cpp as LuaInvokingResource (line 6497).

GetInvokingResourceGeneration()

Generation of the resource invoking the current export.

Returns nil outside an export callback. A changed generation lets a service retire handles left by an older VM.

Returns

  • integer, or nil

Registered in ResourceHost.cpp as LuaInvokingResourceGeneration (line 6498).

GetResourceKvp(key, [default])

FiveM-style alias for CyberM.kvp.get.

FiveM-familiar alias for CyberM.kvp.get. It returns the original stored Lua type or nil when absent and stays inside the active connection-address and calling-resource namespace.

Parameters

  • keystringrequired
  • defaultanyoptional

Returns

  • value or nil
  • reason

Registered in ResourceHost.cpp as LuaKvpGet (line 6501).

GetResourceState(resource)

State of a resource.

Reads the lifecycle state currently known by the client resource host. This is a snapshot only: it does not start, stop, or wait for the target resource.

Parameters

  • resourcestringrequired

Returns

  • string

Registered in ResourceHost.cpp as LuaGetResourceState (line 6499).

SHARED

print(…)

Writes to the CyberM log, prefixed with the resource name.

Writes a resource-prefixed line to the CyberM log. Values are converted with bounded formatting; this does not send a chat message or write into a WebUI page.

Parameters

  • anyrequired

Registered in ResourceHost.cpp as LuaPrint (line 6484).

RegisterNetEvent(event, [handler])

Allows an event to arrive from the server.

Allows an authenticated server event with this name to enter the current resource, and optionally attaches a handler in the same call. Registration is generation-scoped, requires network.events, and does not turn arbitrary client events into server events.

Parameters

  • eventstringrequired
  • handlerfunctionoptional

Returns

  • handler id

Registered in ResourceHost.cpp as LuaRegisterNetEvent (line 6493).

RemoveEventHandler(event, handler)

Removes a handler.

Removes the exact callback previously registered for the named local event. It returns false when that event/callback pair is not owned by the current resource generation.

Parameters

  • eventstringrequired
  • handlerfunctionrequired

Returns

  • boolean

Registered in ResourceHost.cpp as LuaRemoveEventHandler (line 6491).

require

SHARED

require(module)

Loads a module from the resource.

Loads a Lua module declared inside the current resource and caches its result for that resource generation. Resolution stays inside the sandbox: it does not expose the host filesystem, native package loaders, or modules from another resource.

Parameters

  • modulestringrequired

Returns

  • whatever the module returns

Registered in ResourceHost.cpp as LuaRequire (line 6485).

SetResourceKvp(key, value)

FiveM-style alias for CyberM.kvp.set.

FiveM-familiar alias for CyberM.kvp.set. It stores one typed value in the calling resource's persistent namespace for the active connection address; it cannot select another server or resource.

Parameters

  • keystringrequired
  • valueanyrequired

Returns

  • boolean
  • reason

Registered in ResourceHost.cpp as LuaKvpSet (line 6500).

SetTimeout(milliseconds, body)

Runs a function once, later.

Schedules a Lua callback after at least the requested number of milliseconds without blocking the game thread. The timer belongs to the current resource generation and is cancelled automatically on stop or hot reload.

Parameters

  • millisecondsintegerrequired
  • bodyfunctionrequired

Returns

  • timer id

Registered in ResourceHost.cpp as LuaSetTimeout (line 6488).

TriggerEvent(event, [payload])

Fires a local event.

Dispatches an event only inside the client resource runtime. Arguments must fit the runtime's bounded script-value representation; use TriggerServerEvent for traffic that must cross the network.

Parameters

  • eventstringrequired
  • payloadtableoptional

Returns

  • boolean

Registered in ResourceHost.cpp as LuaTriggerEvent (line 6492).

TriggerServerEvent(event, [payload])

Sends an event to the server.

Serializes and sends an event to the connected server with the caller's authenticated player identity. It requires network.events; tables must be serializable and payload limits are enforced before anything is queued.

Parameters

  • eventstringrequired
  • payloadtableoptional

Returns

  • boolean

Registered in ResourceHost.cpp as LuaTriggerServerEvent (line 6494).

Wait

SHARED

Wait(milliseconds)

Suspends the current coroutine.

Only usable inside a CreateThread.

Parameters

  • millisecondsintegerrequired

Registered in ResourceHost.cpp as LuaWait (line 6487).

For agents and LLMs: this page as Markdown · llms.txt · llms-full.txt