This repository has been archived by the owner on May 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.lua
107 lines (98 loc) · 2.17 KB
/
main.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Citizen.CreateThread(function()
-- Init on resource reload
Wait(500)
if GetPlayerPed(-1) then
init()
alreadySpawned = true
end
while true do
Wait(1)
if not blockinput then
for _, data in ipairs(config.controls) do
if menuopen or data.alwayslisten then
for i, control in ipairs(data.control) do
if not IsControlPressed(1, control) then
break
end
if i == #data.control then -- check if all specified controls are pressed
if IsControlJustPressed(1, control) then
data.scrollcooldown = config.scrolling.cooldown
send(data.action)
elseif IsControlPressed(1, control) and data.scrollcooldown then
if data.scrollcooldown > 0 then
data.scrollcooldown = data.scrollcooldown - 1
else
data.scrollcooldown = config.scrolling.continouscooldown
send(data.action)
end
elseif IsControlJustReleased(1, control) then
data.scrollcooldown = 0
end
end
end
end
end
end
end
end)
function init()
SendNUIMessage({
config = {data = config}
})
TriggerEvent("menu:setup")
TriggerServerEvent("menu:setup")
end
AddEventHandler("playerSpawned", function(spawn)
if not alreadySpawned then
init()
alreadySpawned = true
end
end)
RegisterNUICallback("playsound", function(data, cb)
PlaySoundFrontend(-1, data.name, "HUD_FRONTEND_DEFAULT_SOUNDSET", true)
end)
RegisterNUICallback("menuclose", function(data, cb)
menuopen = false
end)
RegisterNUICallback("print", function(data, cb)
print(data.msg)
end)
function send(data)
if data == "toggle" then
if not menuopen then
menuopen = true
SendNUIMessage({
showmenu = true
})
else
menuopen = false
SendNUIMessage({
hidemenu = true
})
end
elseif data == "enter" then
SendNUIMessage({
menuenter = true
})
elseif data == "back" then
SendNUIMessage({
menuback = true
})
elseif data == "up" then
SendNUIMessage({
menuup = true
})
elseif data == "down" then
SendNUIMessage({
menudown = true
})
elseif data == "right" then
SendNUIMessage({
menuright = true
})
elseif data == "left" then
SendNUIMessage({
menuleft = true
})
end
end