mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
fix(callback): handle external resource events
Calling registered callback events in another resource should respond to the invoking resource.
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
local events = {}
|
local events = {}
|
||||||
local timers = {}
|
local timers = {}
|
||||||
local cbEvent = ('__cb_%s'):format(cache.resource)
|
local cbEvent = ('__ox_cb_%s')
|
||||||
|
|
||||||
RegisterNetEvent(cbEvent, function(key, ...)
|
RegisterNetEvent(cbEvent:format(cache.resource), function(key, ...)
|
||||||
local cb = events[key]
|
local cb = events[key]
|
||||||
return cb and cb(...)
|
return cb and cb(...)
|
||||||
end)
|
end)
|
||||||
@@ -38,7 +38,7 @@ local function triggerServerCallback(_, event, delay, cb, ...)
|
|||||||
key = ('%s:%s'):format(event, math.random(0, 100000))
|
key = ('%s:%s'):format(event, math.random(0, 100000))
|
||||||
until not events[key]
|
until not events[key]
|
||||||
|
|
||||||
TriggerServerEvent(('__cb_%s'):format(event), key, ...)
|
TriggerServerEvent(cbEvent:format(event), cache.resource, key, ...)
|
||||||
|
|
||||||
local promise = not cb and promise.new()
|
local promise = not cb and promise.new()
|
||||||
|
|
||||||
@@ -73,10 +73,8 @@ end
|
|||||||
---@param cb function
|
---@param cb function
|
||||||
--- Registers an event handler and callback function to respond to server requests.
|
--- Registers an event handler and callback function to respond to server requests.
|
||||||
function callback.register(name, cb)
|
function callback.register(name, cb)
|
||||||
name = ('__cb_%s'):format(name)
|
RegisterNetEvent(cbEvent:format(name), function(resource, key, ...)
|
||||||
|
TriggerServerEvent(cbEvent:format(resource), key, { cb(...) })
|
||||||
RegisterNetEvent(name, function(key, ...)
|
|
||||||
TriggerServerEvent(cbEvent, key, { cb(...) })
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
local events = {}
|
local events = {}
|
||||||
local cbEvent = ('__cb_%s'):format(cache.resource)
|
local cbEvent = ('__ox_cb_%s')
|
||||||
|
|
||||||
RegisterNetEvent(cbEvent, function(key, ...)
|
RegisterNetEvent(cbEvent:format(cache.resource), function(key, ...)
|
||||||
local cb = events[key]
|
local cb = events[key]
|
||||||
return cb and cb(...)
|
return cb and cb(...)
|
||||||
end)
|
end)
|
||||||
@@ -19,7 +19,7 @@ local function triggerClientCallback(_, event, playerId, cb, ...)
|
|||||||
key = ('%s:%s:%s'):format(event, math.random(0, 100000), playerId)
|
key = ('%s:%s:%s'):format(event, math.random(0, 100000), playerId)
|
||||||
until not events[key]
|
until not events[key]
|
||||||
|
|
||||||
TriggerClientEvent(('__cb_%s'):format(event), playerId, key, ...)
|
TriggerClientEvent(cbEvent:format(event), playerId, cache.resource, key, ...)
|
||||||
|
|
||||||
local promise = not cb and promise.new()
|
local promise = not cb and promise.new()
|
||||||
|
|
||||||
@@ -54,10 +54,8 @@ end
|
|||||||
---@param cb function
|
---@param cb function
|
||||||
--- Registers an event handler and callback function to respond to client requests.
|
--- Registers an event handler and callback function to respond to client requests.
|
||||||
function callback.register(name, cb)
|
function callback.register(name, cb)
|
||||||
name = ('__cb_%s'):format(name)
|
RegisterNetEvent(cbEvent:format(name), function(resource, key, ...)
|
||||||
|
TriggerClientEvent(cbEvent:format(resource), source, key, { cb(source, ...) })
|
||||||
RegisterNetEvent(name, function(key, ...)
|
|
||||||
TriggerClientEvent(cbEvent, source, key, { cb(source, ...) })
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user