Skip to content

Commit

Permalink
Update functions.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
makaman59 authored Dec 17, 2023
1 parent 99586aa commit 17a0bcc
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions client/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,46 @@ function QBCore.Functions.TriggerCallback(name, cb, ...)
TriggerServerEvent('QBCore:Server:TriggerCallback', name, ...)
end

function QBCore.Functions.uuid()
print('1')
math.randomseed(GetGameTimer())
local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
return string.gsub(template, '[xy]', function (c)
local v = (c == 'x') and math.random(0, 0xf) or math.random(8, 0xb)
return string.format('%x', v)
end)
end

function QBCore.Functions.TriggerRpc(name, ...)
local eventResponseId = QBCore.Functions.uuid()
local p = promise.new()

local event = RegisterNetEvent(eventResponseId, function(result)
RemoveEventHandler(QBCore.ServerRPC[eventResponseId].event)
QBCore.ServerRPC[eventResponseId] = nil
p:resolve(result)
end)

QBCore.ServerRPC[eventResponseId] = {
name = name,
args = {...},
promise = p,
event = event,
}

SetTimeout(2000, function()
if QBCore.ServerRPC[eventResponseId] then
p:reject('RPC timed out for event: ' .. QBCore.ServerRPC[eventResponseId].name)
RemoveEventHandler(QBCore.ServerRPC[eventResponseId].event)
QBCore.ServerRPC[eventResponseId] = nil
end
end)

TriggerServerEvent('QBCore:Server:TriggerRpc', name, eventResponseId, ...)

return Citizen.Await(p)
end

function QBCore.Functions.Progressbar(name, label, duration, useWhileDead, canCancel, disableControls, animation, prop, propTwo, onFinish, onCancel)
if GetResourceState('progressbar') ~= 'started' then error('progressbar needs to be started in order for QBCore.Functions.Progressbar to work') end
exports['progressbar']:Progress({
Expand Down

0 comments on commit 17a0bcc

Please sign in to comment.