Skip to content

Commit

Permalink
🆕csoki callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Thekuca authored Feb 1, 2024
1 parent b925a8e commit 2fd609a
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions [core]/es_extended/client/modules/callback.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@ local clientCallbacks = {}
---@param eventName string
---@param callback function
---@param ... any
ESX.TriggerServerCallback = function(eventName, callback, ...)
serverRequests[RequestId] = callback
ESX.TriggerServerCallback = setmetatable({
Await = function(eventName, ...)
local p = promise.new()

TriggerServerEvent("esx:triggerServerCallback", eventName, RequestId, GetInvokingResource() or "unknown", ...)
ESX.TriggerServerCallback(eventName, function(...)
p:resolve(...)
end, ...)

RequestId = RequestId + 1
end
return Citizen.Await(p)
end
}, {
__call = function(eventName, callback, ...)
serverRequests[RequestId] = callback

TriggerServerEvent('esx:triggerServerCallback', eventName, RequestId, GetInvokingResource() or 'unknown', ...)

RequestId = RequestId + 1
end
})

RegisterNetEvent("esx:serverCallback", function(requestId, invoker, ...)
if not serverRequests[requestId] then
Expand Down

0 comments on commit 2fd609a

Please sign in to comment.