feat(callback): client callback

Allow the client to listen for and respond to server requests.
Basically just copy-paste and swap the two.
This commit is contained in:
Linden
2022-06-09 05:15:27 +10:00
parent c85e9032f9
commit 76fcc007c4
2 changed files with 62 additions and 2 deletions

View File

@@ -69,4 +69,15 @@ function callback.await(event, delay, ...)
return triggerServerCallback(_, event, delay, false, ...)
end
---@param name string
---@param cb function
--- Registers an event handler and callback function to respond to server requests.
function callback.register(name, cb)
name = ('__cb_%s'):format(name)
RegisterNetEvent(name, function(key, ...)
TriggerServerEvent(cbEvent, key, { cb(...) })
end)
end
return callback