2022-10-16 00:22:13 +11:00
|
|
|
---@type promise?
|
2022-10-13 14:15:49 +02:00
|
|
|
local skillcheck
|
2022-10-15 14:30:10 +02:00
|
|
|
local gameCount = 0
|
2022-10-16 00:22:13 +11:00
|
|
|
|
|
|
|
|
---@alias SkillCheckDifficulity 'easy' | 'medium' | 'hard' | { areaSize: number, speedMultiplier: number }
|
|
|
|
|
|
|
|
|
|
---@type SkillCheckDifficulity | SkillCheckDifficulity[]
|
2022-10-15 14:30:10 +02:00
|
|
|
local gameDifficulty
|
2022-10-16 00:22:13 +11:00
|
|
|
|
|
|
|
|
---@type promise?
|
2022-10-15 14:30:10 +02:00
|
|
|
local gamePromise
|
|
|
|
|
|
|
|
|
|
local function resolveSkillCheck(success)
|
2022-10-16 00:22:13 +11:00
|
|
|
if skillcheck then
|
|
|
|
|
skillcheck:resolve(success)
|
|
|
|
|
skillcheck = nil
|
|
|
|
|
SetNuiFocus(false, false)
|
|
|
|
|
end
|
2022-10-15 14:30:10 +02:00
|
|
|
end
|
2022-10-13 14:15:49 +02:00
|
|
|
|
2022-10-16 00:22:13 +11:00
|
|
|
---@param difficulty SkillCheckDifficulity | SkillCheckDifficulity[]
|
|
|
|
|
---@return boolean?
|
2022-10-13 14:15:49 +02:00
|
|
|
function lib.skillCheck(difficulty)
|
|
|
|
|
if skillcheck then return end
|
2022-10-16 00:22:13 +11:00
|
|
|
|
2022-10-13 14:15:49 +02:00
|
|
|
skillcheck = promise:new()
|
2022-10-15 14:30:10 +02:00
|
|
|
gameDifficulty = difficulty
|
2022-10-13 14:15:49 +02:00
|
|
|
SetNuiFocus(true, false)
|
2022-10-16 00:22:13 +11:00
|
|
|
|
2022-10-15 14:30:10 +02:00
|
|
|
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({
|
|
|
|
|
action = 'startSkillCheck',
|
|
|
|
|
data = difficulty
|
|
|
|
|
})
|
|
|
|
|
end
|
2022-10-16 00:22:13 +11:00
|
|
|
|
2022-10-13 14:15:49 +02:00
|
|
|
return Citizen.Await(skillcheck)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
RegisterNUICallback('skillCheckOver', function(data, cb)
|
|
|
|
|
cb(1)
|
2022-10-15 14:30:10 +02:00
|
|
|
if not gamePromise then return resolveSkillCheck(data.success) end
|
|
|
|
|
gamePromise:resolve(data.success)
|
|
|
|
|
if not data.success then return resolveSkillCheck(data.success) end
|
|
|
|
|
gameCount += 1
|
|
|
|
|
if gameCount == #gameDifficulty then
|
|
|
|
|
resolveSkillCheck(data.success)
|
|
|
|
|
end
|
2022-10-16 00:22:13 +11:00
|
|
|
end)
|