Files
ox_lib/imports/callbacks/server.lua
Linden 72575c90ee refactor(callbacks): remove the cb argument
BREAKING CHANGE: Registered callbacks now return values rather than sending them as a callback.

Previously the cb needed to be called to return to the client, now it will happen once the function closes. i.e.

cb(string, string, false) -> return string, string, false
2022-01-01 20:43:06 +11:00

14 lines
429 B
Lua

local ServerCallback = {}
---@param name string
---@param callback function
--- Registers an event handler and callback function to respond to client requests.
ServerCallback.Register = function(name, callback)
name = ('__cb_%s:%s'):format(GetCurrentResourceName(), name)
RegisterServerEvent(name, function(id, ...)
TriggerClientEvent(name..id, source, {callback(source, ...)})
end)
end
return ServerCallback