Callbacks

CLIENT & SERVER SIDE

A standalone, framework-agnostic callback system designed to streamline client-server communication in FiveM projects.

It provides developers with a single, unified API for handling server callbacks, eliminating the need to write and manage multiple callback implementations for different frameworks.

Client Functions

callback

Trigger a server callback. All callbacks must be registered first on the server in order to be called.

Function

local function callback(name, data, cb)
    local cb_id = math.random(1, 1000000)
    callbacks[cb_id] = cb
    TriggerServerEvent('boii_utils:sv:trigger_callback', name, data, cb_id)
end

exports('callback', callback)
utils.callback.cb = callback

Example

--- Specfig the event name for the callback you created on the server.
local event_name = 'your event name'

--- Data *(optional)*
-- Any data sent this way from client you should always validate again on server.
local data = {
    ['some data key'] = 'some value'
}

--- Utils object
utils.callback.cb(event_name, data, function(response)
   if response then
       -- Do something
   end
end)

--- Direct export
exports.boii_utils:callback(...)

Server Functions

Last updated