Client-Side Callbacks
Callbacks enable communication between client and server with synchronous-style syntax.
lib.callback.register
Register a callback that the server can call.
lib.callback.register(name, func)Parameters
- name
string- Unique identifier for the callback - func
function- Function to execute when callback is triggered
Returns
- success
boolean- Always returnstrue - message
string- Status message
Example
lib.callback.register('getVehicleData', function()
local ped = PlayerPedId()
local vehicle = GetVehiclePedIsIn(ped, false)
if vehicle == 0 then return nil end
return {
plate = GetVehicleNumberPlateText(vehicle),
fuel = GetVehicleFuelLevel(vehicle)
}
end)lib.callback.await
Call a server callback and wait for the result.
lib.callback.await(debug, name, timeout, ...)Parameters
- debug
boolean(optional) - Enable debug logging for this callback - name
string- Name of the server callback to trigger - timeout
number | boolean- Timeout in milliseconds - ...
varargs- Additional arguments to pass to the callback
Return
anyResponse from the oposite side
Examples
-- Basic usage (10 second timeout)
local vehicle = lib.callback.await('getVehicle')
if vehicle then
print('Found:', vehicle.plate)
else
print('No vehicle found')
endNotes
- Default timeout: 10000ms (10 seconds)
- Timeout is specified in milliseconds
- If timeout is boolean, it will use the default timeout value
- Debug mode logs callback triggers, returns, and timeouts
- Automatically handles nil returns and multiple return values
- Backward compatible - both
debugandtimeoutparameters are optional