Skip to content

Commit e8dc8f8

Browse files
committed
Bring in client functions
1 parent 11052e2 commit e8dc8f8

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

client/functions.lua

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-- Callbacks
2+
3+
function QBCore.Functions.CreateClientCallback(name, cb)
4+
QBCore.ClientCallbacks[name] = cb
5+
end
6+
7+
function QBCore.Functions.TriggerCallback(name, ...)
8+
local cb = nil
9+
local args = { ... }
10+
11+
if QBCore.Functions.IsFunction(args[1]) then
12+
cb = args[1]
13+
table.remove(args, 1)
14+
end
15+
16+
QBCore.ServerCallbacks[name] = {
17+
callback = cb,
18+
promise = promise.new()
19+
}
20+
TriggerServerEvent('QBCore:Server:TriggerCallback', name, table.unpack(args))
21+
if cb == nil then
22+
Citizen.Await(QBCore.ServerCallbacks[name].promise)
23+
return QBCore.ServerCallbacks[name].promise.value
24+
end
25+
end
26+
27+
function QBCore.Functions.GetPlayerData(cb)
28+
if not cb then return QBCore.PlayerData end
29+
cb(QBCore.PlayerData)
30+
end

0 commit comments

Comments
 (0)