Library
Callback
Register and trigger asynchronous callbacks between client and server scripts with optional delay and await support.
Client Functions
RegisterClient
Register a callback handler on the client that the server can invoke.
dLib.Callback.RegisterClient(name, cb)| Argument | Type | Description |
|---|---|---|
name | string | The unique identifier for the callback to register. |
cb | function | The function to execute when the callback is triggered. |
dLib.Callback.RegisterClient('getClosestVehicle', function()
local vehicleId, distance = dBridge.Framework.GetClosestVehicle()
return vehicleId, distance
end)TriggerServer
Trigger a callback on the server from the client, with optional delay and additional arguments.
dLib.Callback.TriggerServer(name, delay, cb, ...)| Argument | Type | Description |
|---|---|---|
name | string | The unique identifier for the callback to trigger. |
delay? | number | Optional delay in milliseconds before the callback is invoked. |
cb | function | The function to execute once the server responds. |
args? | any | Additional arguments passed to the callback handler. |
AwaitServer
Trigger a callback on the server from the client and wait for the result, returning the server's response.
local retval = dLib.Callback.AwaitServer(name, cb, ...)| Argument | Type | Description |
|---|---|---|
name | string | The unique identifier for the callback to trigger. |
cb | function | The function to execute once the server responds. |
args? | any | Additional arguments passed to the callback handler. |
Server Functions
RegisterServer
Register a callback handler on the server that the client can invoke.
dLib.Callback.RegisterServer(name, cb)| Argument | Type | Description |
|---|---|---|
name | string | The unique identifier for the callback to register. |
cb | function | The function to execute when the callback is triggered. |
dLib.Callback.RegisterServer('getItemLabel', function(source, itemName)
local label = dBridge.Inventory.GetItemLabel(itemName)
return label
end)TriggerClient
Trigger a callback on a specific client from the server, with optional delay and additional arguments.
dLib.Callback.TriggerServer(name, playerId, delay, cb, ...)| Argument | Type | Description |
|---|---|---|
name | string | The unique identifier for the callback to trigger. |
playerId | number | The server ID of the target player. |
delay? | number | Optional delay in milliseconds before the callback is invoked. |
cb | function | The function to execute once the client responds. |
args? | any | Additional arguments passed to the callback handler. |
AwaitClient
Trigger a callback on a specific client from the server and wait for the result, returning the client's response.
local retval = dLib.Callback.AwaitClient(name, playerId, cb, ...)| Argument | Type | Description |
|---|---|---|
name | string | The unique identifier for the callback to trigger. |
playerId | number | The server ID of the target player. |
cb | function | The function to execute once the client responds. |
args? | any | Additional arguments passed to the callback handler. |