-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcl_skillbar.lua
86 lines (79 loc) · 1.93 KB
/
cl_skillbar.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
local levels = {
["easy"] = {
duration = 3000,
width = 30
},
["normal"] = {
duration = 1500 ,
width = 20,
},
["medium"] = {
duration = 2000,
width = 1
},
["hard"] = {
duration = 650 ,
width = 10,
}
}
local activePromise = nil
local inProgress = false
function CreateSkillbar(amount,level)
if not inProgress then
if type(level) == "string" then
if not levels[level] then
return false
end
level = levels[level]
elseif type(level) == "table" then
if not level.duration or not level.width then
return false
end
end
activePromise = promise:new()
inProgress = true
SendNUIMessage({
action = "open",
diff = level,
amount=amount
})
CreateThread(listenToKeyCheck)
return Citizen.Await(activePromise)
else return false
end
end
function listenToKeyCheck()
while inProgress do
Wait(0)
if IsControlJustPressed(1,38) then
SendNUIMessage({
action = "check"
})
end
end
end
RegisterNUICallback("finish",function(data,cb)
local success = data.success
inProgress = false
if activePromise ~= nil then
activePromise:resolve(success)
activePromise = nil
end
end)
AddEventHandler('qb-core:client:OnPlayerDeath',function()
if activePromise and inProgress then
activePromise:resolve(false)
activePromise = nil
inProgress = false
SendNUIMessage({
action = "hide"
})
end
end)
AddEventHandler('skilbar:stop',function()
inProgress = false
SendNUIMessage({
action = "hide"
})
end)
exports("CreateSkillbar",CreateSkillbar)