This repository was archived by the owner on Apr 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
281 lines (269 loc) · 8.55 KB
/
client.lua
File metadata and controls
281 lines (269 loc) · 8.55 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
local mainOptions = {}
local weaponOptions = {}
local shopOptions = {}
local armorOptions = {}
---@param title string
---@param text string
---@param type string
local function notify(title, text, type)
lib.notify({
title = title,
description = text,
type = type
})
end
---@param type string
local function openArmory(type)
if Config.Passwords[type] then
local input = lib.inputDialog(Lang('armory_name'), {
{
type = 'input',
label = 'Password',
password = true,
required = true,
}
})
if not input then return end
if input[1] == Config.Password[type] then
lib.showContext('sync_armory:' .. type)
else
notify(Lang('armory'), Lang('incorrect_password'), 'error')
end
else
lib.showContext('sync_armory:' .. type)
end
end
---@param data table
local function getWeapon(data)
lib.registerContext({
id = 'sync_armory:addWeapons',
title = Lang('armory_name'),
menu = 'sync_armory:weapons',
options = {
{
title = 'Add Weapon',
description = 'All actions in the armory are logged. Ensure you are authorised to do this.',
icon = 'plus',
onSelect = function()
TriggerServerEvent('sync_armory:getWeapons', data)
lib.showContext(('sync_armory:%s:weapons'):format(data.type))
end
},
{
title = 'Remove Weapon',
icon = 'minus',
onSelect = function()
TriggerServerEvent('sync_armory:removeWeapons', data)
lib.showContext(('sync_armory:%s:weapons'):format(data.type))
end
}
}
})
lib.showContext('sync_armory:addWeapons')
end
---@param data table
local function getItem(data)
local input = lib.inputDialog('Shop', {
{
type = 'number',
label = 'Amount',
required = true,
}
})
if not input then return end
TriggerServerEvent('sync_armory:getItems', data.item, input[1])
lib.showContext(('sync_armory:%s:items'):format(data.type))
end
---@param amount number
local function setArmor(amount)
if not amount then return end
local playerPed = PlayerPedId()
if amount == 0 then
lib.progressBar({
duration = 3000,
label = 'Removing Armor',
position = 'bottom',
useWhileDead = false,
canCancel = false,
disable = {
car = true,
},
anim = {
dict = 'clothingtie',
clip = 'try_tie_negative_a'
}
})
elseif amount <= 50 then
lib.progressBar({
duration = 3000,
label = 'Equipping Armor',
position = 'bottom',
useWhileDead = false,
canCancel = false,
disable = {
car = true,
},
anim = {
dict = 'clothingtie',
clip = 'try_tie_negative_a'
}
})
elseif amount < 50 then
lib.progressBar({
duration = 3000,
label = 'Equipping Heavy Armor',
position = 'bottom',
useWhileDead = false,
canCancel = false,
disable = {
car = true,
},
anim = {
dict = 'clothingtie',
clip = 'try_tie_negative_a'
}
})
end
SetPedArmour(playerPed, amount)
end
local function init()
for type, location in pairs(Config.Locations) do
mainOptions[type] = {}
local main = mainOptions[type]
for _, v in pairs(location) do
if Config.UseTarget then
-- Register Target for Each Location
exports.ox_target:addBoxZone({
coords = v.coords,
size = vector3(2, 2, 2),
options = {
{
label = v.label or 'Open Armory',
icon = ('fa-solid fa-%s'):format(v.icon) or 'fa-solid fa-gun',
groups = v.job or 'police',
onSelect = function()
openArmory(type)
end
}
}
})
else
local uiText = ("**Police Armory** \nPress [E] to %s"):format(v.label or 'Open Armory')
local point = lib.points.new({
coords = v.coords,
distance = 20,
})
local marker = lib.marker.new({
coords = v.coords,
type = 1,
})
function point:nearby()
marker:draw()
if self.currentDistance < 2 then
if not lib.isTextUIOpen() then
lib.showTextUI(uiText, {
icon = v.icon or 'gun'
})
end
if IsControlJustPressed(0, 51) then
openArmory(type)
end
else
local isOpen, currentText = lib.isTextUIOpen()
if isOpen and currentText == uiText then
lib.hideTextUI()
end
end
end
end
end
-- Only added to main menu if it exists
if Config.Items[type] then
main[#main + 1] = {
title = 'Shop',
icon = 'basket-shopping',
menu = ('sync_armory:%s:items'):format(type)
}
end
if Config.Weapons[type] then
main[#main + 1] = {
title = 'Weapons',
icon = 'gun',
menu = ('sync_armory:%s:weapons'):format(type)
}
end
if Config.Armor[type] then
main[#main + 1] = {
title = 'Armor',
icon = 'vest',
menu = ('sync_armory:%s:armor'):format(type)
}
end
lib.registerContext({
id = ('sync_armory:%s'):format(type),
title = Lang('armory_name'),
options = main
})
end
for type, weapons in pairs(Config.Weapons) do
for _, v in pairs(weapons) do
weaponOptions[type] = {}
local weapon = weaponOptions[type]
weapon[#weapon + 1] = {
title = v.label,
args = { item = v.item, components = v.components, type = type },
onSelect = getWeapon,
icon = v.icon or 'gun'
}
end
lib.registerContext({
id = ('sync_armory:%s:weapons'):format(type),
menu = ('sync_armory:%s'):format(type),
title = Lang('armory_name'),
options = weaponOptions[type],
})
end
for type, items in pairs(Config.Items) do
shopOptions[type] = {}
local shop = shopOptions[type]
for i = 1, #items do
shop[#shop + 1] = {
title = items[i].label,
onSelect = getItem,
args = { item = items[i].item, type = type },
icon = items[i].icon or 'shop'
}
end
lib.registerContext({
id = ('sync_armory:%s:items'):format(type),
menu = ('sync_armory:%s'):format(type),
title = Lang('armory_name'),
options = shop,
})
end
for type, option in pairs(Config.Armor) do
armorOptions[type] = {}
local armor = armorOptions[type]
for _, v in pairs(option) do
armor[#armor + 1] = {
title = v.label,
onSelect = setArmor,
args = { amount = v.armor },
icon = v.icon or 'vest'
}
end
armor[#armor + 1] = {
title = 'Remove Vest',
onSelect = setArmor,
args = { amount = 0 },
icon = 'vest'
}
lib.registerContext({
id = ('sync_armory:%s:armor'):format(type),
menu = ('sync_armory:'):format(type),
title = Lang('armory_name'),
options = armor
})
end
end
init()