Modules
Callback
Server

Server-Side Callbacks

Callbacks provide server-client communication with synchronous-style syntax.

lib.callback.register

Register a callback that clients can call. Automatically receives source as the first parameter.

lib.callback.register(name, func)

Parameters

  • name string - Unique identifier for the callback
  • func function - Function to execute when callback is triggered (receives source as first parameter)

Returns

  • success boolean - Always returns true
  • message string - Status message

Example

lib.callback.register('getVehicle', function(source)
    local vehicle = GetPlayerVehicle(source)
    if not vehicle then return nil end
    
    return {
        plate = vehicle.plate,
        model = vehicle.model
    }
end)

lib.callback.await

Call a client callback and wait for the result.

lib.callback.await(debug, name, source, timeout, ...any)

Parameters

  • debug boolean (optional) - Enable debug logging for this callback
  • name string - Name of the client callback to trigger
  • source number - Player server ID
  • timeout number | boolean - Timeout in milliseconds
  • any varargs - Additional arguments to pass to the callback

Return

  • any Response from the oposite side

Examples

RegisterCommand('impound', function(source)
    local vehicleData = lib.callback.await('getVehicleData', source)
    
    if vehicleData then
        ImpoundVehicle(vehicleData.plate)
    else
        print('Player not in vehicle')
    end
end)

Notes

  • Errors are logged to console and return nil to the caller.
  • Server callbacks automatically receive source (player ID) as first parameter
  • 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
  • Runtime errors are caught and logged automatically
  • Automatically handles nil returns and multiple return values
  • Backward compatible - both debug and timeout parameters are optional