-
-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client/skillcheck): skillcheck array chaining
- Loading branch information
1 parent
ed8e804
commit 4a28666
Showing
1 changed file
with
36 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,48 @@ | ||
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) | ||
if skillcheck then return end | ||
skillcheck = promise:new() | ||
gameDifficulty = difficulty | ||
SetNuiFocus(true, false) | ||
SendNUIMessage({ | ||
action = 'startSkillCheck', | ||
data = difficulty | ||
}) | ||
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 | ||
return Citizen.Await(skillcheck) | ||
end | ||
|
||
RegisterNUICallback('skillCheckOver', function(data, cb) | ||
cb(1) | ||
skillcheck:resolve(data.success) | ||
skillcheck = nil | ||
SetNuiFocus(false, false) | ||
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 | ||
end) |