# Globals — client runtime

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

19 functions.

## AddEventHandler

```lua
AddEventHandler(event, handler)
```

`SHARED` — Available without a live game instance.

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.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `event` | `string` | required | — |
| `handler` | `function` | required | — |

Returns: `handler id`

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

## ClearTimeout

```lua
ClearTimeout(id)
```

`SHARED` — Available without a live game instance.

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.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `id` | `integer` | required | — |

Returns: `boolean`

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

## CreateThread

```lua
CreateThread(body)
```

`SHARED` — Available without a live game instance.

Starts a coroutine managed by the host.

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

| Parameter | Type | Required | Default |
|---|---|---|---|
| `body` | `function` | required | — |

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

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

## DeleteResourceKvp

```lua
DeleteResourceKvp(key)
```

`SHARED` — Available without a live game instance.

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.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `key` | `string` | required | — |

Returns: `boolean`, `reason`

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

## exports

```lua
exports(name, body)
```

`SHARED` — Available without a live game instance.

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.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `name` | `string` | required | — |
| `body` | `function` | required | — |

Returns: `boolean`

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

## GetCurrentResourceName

```lua
GetCurrentResourceName()
```

`SHARED` — Available without a live game instance.

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` (line 6496) as `LuaResourceName`.

## GetInvokingResource

```lua
GetInvokingResource()
```

`SHARED` — Available without a live game instance.

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` (line 6497) as `LuaInvokingResource`.

## GetInvokingResourceGeneration

```lua
GetInvokingResourceGeneration()
```

`SHARED` — Available without a live game instance.

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` (line 6498) as `LuaInvokingResourceGeneration`.

## GetResourceKvp

```lua
GetResourceKvp(key, [default])
```

`SHARED` — Available without a live game instance.

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.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `key` | `string` | required | — |
| `default` | `any` | optional | — |

Returns: `value or nil`, `reason`

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

## GetResourceState

```lua
GetResourceState(resource)
```

`SHARED` — Available without a live game instance.

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.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `resource` | `string` | required | — |

Returns: `string`

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

## print

```lua
print(…)
```

`SHARED` — Available without a live game instance.

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.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `…` | `any` | required | — |

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

## RegisterNetEvent

```lua
RegisterNetEvent(event, [handler])
```

`NETWORK` — Uses the network backend.

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.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `event` | `string` | required | — |
| `handler` | `function` | optional | — |

Returns: `handler id`

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

## RemoveEventHandler

```lua
RemoveEventHandler(event, handler)
```

`SHARED` — Available without a live game instance.

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.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `event` | `string` | required | — |
| `handler` | `function` | required | — |

Returns: `boolean`

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

## require

```lua
require(module)
```

`SHARED` — Available without a live game instance.

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.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `module` | `string` | required | — |

Returns: `whatever the module returns`

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

## SetResourceKvp

```lua
SetResourceKvp(key, value)
```

`SHARED` — Available without a live game instance.

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.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `key` | `string` | required | — |
| `value` | `any` | required | — |

Returns: `boolean`, `reason`

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

## SetTimeout

```lua
SetTimeout(milliseconds, body)
```

`SHARED` — Available without a live game instance.

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.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `milliseconds` | `integer` | required | — |
| `body` | `function` | required | — |

Returns: `timer id`

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

## TriggerEvent

```lua
TriggerEvent(event, [payload])
```

`SHARED` — Available without a live game instance.

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.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `event` | `string` | required | — |
| `payload` | `table` | optional | — |

Returns: `boolean`

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

## TriggerServerEvent

```lua
TriggerServerEvent(event, [payload])
```

`NETWORK` — Uses the network backend.

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.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `event` | `string` | required | — |
| `payload` | `table` | optional | — |

Returns: `boolean`

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

## Wait

```lua
Wait(milliseconds)
```

`SHARED` — Available without a live game instance.

Suspends the current coroutine.

Only usable inside a `CreateThread`.

| Parameter | Type | Required | Default |
|---|---|---|---|
| `milliseconds` | `integer` | required | — |

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

