mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
feat(resource): load callbacks
Load lib.callback for internal use.
This commit is contained in:
@@ -40,14 +40,14 @@ local function triggerClientCallback(_, event, playerId, cb, ...)
|
||||
end
|
||||
|
||||
---@overload fun(event: string, playerId: number, cb: function, ...)
|
||||
local callback = setmetatable({}, {
|
||||
lib.callback = setmetatable({}, {
|
||||
__call = triggerClientCallback
|
||||
})
|
||||
|
||||
---@param event string
|
||||
---@param playerId number
|
||||
--- Sends an event to a client and halts the current thread until a response is returned.
|
||||
function callback.await(event, playerId, ...)
|
||||
function lib.callback.await(event, playerId, ...)
|
||||
return triggerClientCallback(_, event, playerId, false, ...)
|
||||
end
|
||||
|
||||
@@ -68,10 +68,10 @@ local pcall = pcall
|
||||
---@param name string
|
||||
---@param cb function
|
||||
--- Registers an event handler and callback function to respond to client requests.
|
||||
function callback.register(name, cb)
|
||||
function lib.callback.register(name, cb)
|
||||
RegisterNetEvent(cbEvent:format(name), function(resource, key, ...)
|
||||
TriggerClientEvent(cbEvent:format(resource), source, key, callbackResponse(pcall(cb, source, ...)))
|
||||
end)
|
||||
end
|
||||
|
||||
return callback
|
||||
return lib.callback
|
||||
Reference in New Issue
Block a user