Logo

DIVERSITY

Documentation

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.

client.lua
dLib.Callback.RegisterClient(name, cb)
ArgumentTypeDescription
name
string
The unique identifier for the callback to register.
cb
function
The function to execute when the callback is triggered.
client.lua
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.

client.lua
dLib.Callback.TriggerServer(name, delay, cb, ...)
ArgumentTypeDescription
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.

client.lua
local retval = dLib.Callback.AwaitServer(name, cb, ...)
ArgumentTypeDescription
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.

server.lua
dLib.Callback.RegisterServer(name, cb)
ArgumentTypeDescription
name
string
The unique identifier for the callback to register.
cb
function
The function to execute when the callback is triggered.
server.lua
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.

server.lua
dLib.Callback.TriggerServer(name, playerId, delay, cb, ...)
ArgumentTypeDescription
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.

server.lua
local retval = dLib.Callback.AwaitClient(name, playerId, cb, ...)
ArgumentTypeDescription
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.

Was this page helpful?