mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 07:56:02 +01:00
feat(client/skillcheck): skillcheck array chaining
This commit is contained in:
@@ -1,19 +1,48 @@
|
|||||||
local skillcheck
|
local skillcheck
|
||||||
|
local gameCount = 0
|
||||||
|
local gameDifficulty
|
||||||
|
local gamePromise
|
||||||
|
|
||||||
|
local function resolveSkillCheck(success)
|
||||||
|
skillcheck:resolve(success)
|
||||||
|
skillcheck = nil
|
||||||
|
SetNuiFocus(false, false)
|
||||||
|
end
|
||||||
|
|
||||||
function lib.skillCheck(difficulty)
|
function lib.skillCheck(difficulty)
|
||||||
if skillcheck then return end
|
if skillcheck then return end
|
||||||
skillcheck = promise:new()
|
skillcheck = promise:new()
|
||||||
|
gameDifficulty = difficulty
|
||||||
SetNuiFocus(true, false)
|
SetNuiFocus(true, false)
|
||||||
|
if type(difficulty) == 'table' then
|
||||||
|
gameCount = 0
|
||||||
|
for i = 1, #difficulty do
|
||||||
|
gamePromise = promise:new()
|
||||||
|
SendNUIMessage({
|
||||||
|
action = 'startSkillCheck',
|
||||||
|
data = difficulty[i]
|
||||||
|
})
|
||||||
|
if not Citizen.Await(gamePromise) then
|
||||||
|
gamePromise = nil
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
action = 'startSkillCheck',
|
action = 'startSkillCheck',
|
||||||
data = difficulty
|
data = difficulty
|
||||||
})
|
})
|
||||||
|
end
|
||||||
return Citizen.Await(skillcheck)
|
return Citizen.Await(skillcheck)
|
||||||
end
|
end
|
||||||
|
|
||||||
RegisterNUICallback('skillCheckOver', function(data, cb)
|
RegisterNUICallback('skillCheckOver', function(data, cb)
|
||||||
cb(1)
|
cb(1)
|
||||||
skillcheck:resolve(data.success)
|
if not gamePromise then return resolveSkillCheck(data.success) end
|
||||||
skillcheck = nil
|
gamePromise:resolve(data.success)
|
||||||
SetNuiFocus(false, false)
|
if not data.success then return resolveSkillCheck(data.success) end
|
||||||
|
gameCount += 1
|
||||||
|
if gameCount == #gameDifficulty then
|
||||||
|
resolveSkillCheck(data.success)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
Reference in New Issue
Block a user