From e8dc8f8d325ada23914decf4541f246f71dee29d Mon Sep 17 00:00:00 2001 From: Kakarot <57848836+GhzGarage@users.noreply.github.com> Date: Tue, 11 Mar 2025 23:34:24 -0500 Subject: [PATCH] Bring in client functions --- client/functions.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 client/functions.lua diff --git a/client/functions.lua b/client/functions.lua new file mode 100644 index 0000000..c409023 --- /dev/null +++ b/client/functions.lua @@ -0,0 +1,30 @@ +-- Callbacks + +function QBCore.Functions.CreateClientCallback(name, cb) + QBCore.ClientCallbacks[name] = cb +end + +function QBCore.Functions.TriggerCallback(name, ...) + local cb = nil + local args = { ... } + + if QBCore.Functions.IsFunction(args[1]) then + cb = args[1] + table.remove(args, 1) + end + + QBCore.ServerCallbacks[name] = { + callback = cb, + promise = promise.new() + } + TriggerServerEvent('QBCore:Server:TriggerCallback', name, table.unpack(args)) + if cb == nil then + Citizen.Await(QBCore.ServerCallbacks[name].promise) + return QBCore.ServerCallbacks[name].promise.value + end +end + +function QBCore.Functions.GetPlayerData(cb) + if not cb then return QBCore.PlayerData end + cb(QBCore.PlayerData) +end \ No newline at end of file