-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.lua
598 lines (550 loc) · 20.8 KB
/
client.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
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
----Gets ESX-------------------------------------------------------------------------------------------------------------------------------
ESX = exports["es_extended"]:getSharedObject()
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
ESX.PlayerData = xPlayer
PlayerLoaded = true
end)
RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
ESX.PlayerData.job = job
end)
AddEventHandler('esx:onPlayerSpawn', function()
local ped = PlayerPedId()
end)
storageID = nil
rentBalance = nil
local npcSpawned = false
local npc
---------------------------------------------------------------------------------------------------------------------------------------
--Qtaret Zones for each storage
Citizen.CreateThread(function()
local storageConfig = Config.Storages
for i = 1, #storageConfig, 1 do
local storageName = storageConfig[1].name
local length, width = storageConfig[i].bt_length or 0.5, storageConfig[i].bt_width or 0.5
local minZ, maxZ = storageConfig[i].bt_minZ or 10.0, storageConfig[i].bt_maxZ or 100.0
local heading = storageConfig[i].bt_heading or 0.0
local distance = storageConfig[i].bt_distance or 2.0
local storageid = storageConfig[i].id
if Config.Target == 'ox_target' then
exports.ox_target:addBoxZone({
coords = storageConfig[i].coords,
size = vec3(length, width, 10),
rotation = heading,
options = {
{
name = i .. storageName,
event = "koe_storageunitsv2:checkOwned",
icon = "fas fa-warehouse",
label = "Open Storage Unit " .. storageid,
id = storageid,
canInteract = function(entity, distance, coords, name)
return true
end
},
{
event = "koe_storageunitsv2:policeBreach",
icon = "fas fa-warehouse",
label = "Breach the unit",
id = storageid,
groups = 'police',
canInteract = function()
local player = PlayerPedId()
return IsPedOnFoot(player)
end,
},
}
})
end
if Config.Target == 'qtarget' then
exports['qtarget']:AddBoxZone(i .. storageName, storageConfig[i].coords, length, width, {
name=i .. storageName,
heading=heading,
debugPoly=false,
minZ=minZ,
maxZ=maxZ
}, {
options = {
{
event = "koe_storageunitsv2:checkOwned",
icon = "fas fa-warehouse",
label = "Open Storage Unit " .. storageid,
id = storageid,
canInteract = function()
local player = PlayerPedId()
return IsPedOnFoot(player)
end,
},
{
event = "koe_storageunitsv2:policeBreach",
icon = "fas fa-warehouse",
label = "Breach the unit",
id = storageid,
job = 'police',
canInteract = function()
local player = PlayerPedId()
return IsPedOnFoot(player)
end,
},
},
distance = 2.5
})
end
end
end)
---Checks the IDs above to then check the status of the storage youre interacting with
RegisterNetEvent('koe_storageunitsv2:checkOwned')
AddEventHandler('koe_storageunitsv2:checkOwned', function(data, balance)
storageID = data.id
TriggerServerEvent('koe_storageunitsv2:checkUnit', storageID)
TriggerServerEvent('koe_storageunitsv2:checkTime', storageID)
end)
--If the storage is NOT owned this menu pops up
RegisterNetEvent('koe_storageunitsv2:buyMenu')
AddEventHandler('koe_storageunitsv2:buyMenu',function(storageID)
lib.registerContext({
id = 'buymenu',
title = 'Storage Units',
options = {
['Purchase Unit'] = {
description = 'Purchase this unit for $' ..Config.UnitPrice,
arrow = true,
event = 'koe_storageunitsv2:buyStorage',
metadata = {'Purchase with cash'}
}
}
})
lib.showContext('buymenu')
end)
RegisterNetEvent('koe_storageunitsv2:buyStorage')
AddEventHandler('koe_storageunitsv2:buyStorage', function(data)
local ox_inventory = exports.ox_inventory
local count = ox_inventory:Search(2, 'money')
if count >= Config.UnitPrice then
local input = lib.inputDialog('Enter a Pin number', {
{ type = "input", label = "UNIT PIN", password = true, icon = 'lock' },
})
if input then
local pin = input[1]
TriggerServerEvent('koe_storageunitsv2:buyUnit', storageID, pin)
TriggerServerEvent('koe_storageunitsv2:addTimeToDb', storageID)
if Config.Notify == 'ox_lib' then
lib.notify({
title = 'Storage Unit',
description = 'Unit Purchased',
type = 'success',
duration = 8000,
position = 'top',
})
end
if Config.Notify == 'swt' then
exports['swt_notifications']:Success('success','Unit purchased!','top',8000,true)
end
if Config.Notify == 'okok' then
exports['okokNotify']:Alert("Storage Units", "Unit purchased!", 8000, 'success')
end
if Config.Notify == 'esx' then
ESX.ShowNotification('Unit purchased!')
end
if Config.Notify == 'ox' then
lib.notify({
title = 'Storage Units',
description = 'Unit purchased!',
type = 'success',
duration = 8000,
position = 'top'
})
end
if Config.Notify == 'custom' then
--Enter custom code here
end
end
else
if Config.Notify == 'ox_lib' then
lib.notify({
title = 'Storage Unit',
description = 'Not enough money',
type = 'error',
duration = 8000,
position = 'top',
})
end
if Config.Notify == 'swt' then
exports['swt_notifications']:Negative('error','Not enough money','top',8000,true)
end
if Config.Notify == 'okok' then
exports['okokNotify']:Alert("Storage Units", "Not enough money", 8000, 'error')
end
if Config.Notify == 'ox' then
lib.notify({
title = 'Storage Units',
description = 'Not enough money',
type = 'error',
duration = 8000,
position = 'top'
})
end
if Config.Notify == 'esx' then
ESX.ShowNotification('Not enough money')
end
if Config.Notify == 'custom' then
--Enter custom code here
end
end
end)
RegisterNetEvent('koe_storageunitsv2:changePin')
AddEventHandler('koe_storageunitsv2:changePin', function(data)
local keyboard = lib.inputDialog('Enter your current PIN', {
{ type = "input", label = "Unit PIN", password = true, icon = 'lock' },
})
if keyboard then
local oldpin = tonumber(keyboard[1])
ESX.TriggerServerCallback('koe_storageunitsv2:checkPin', function(oldpin)
if oldpin then
local keyboard2 = lib.inputDialog('Enter a NEW PIN', {
{ type = "input", label = "NEW PIN", password = true, icon = 'lock' },
})
if keyboard2 then
local newpin = tonumber(keyboard2[1])
TriggerServerEvent('koe_storageunitsv2:pinChange', storageID,newpin)
if Config.Notify == 'ox_lib' then
lib.notify({
title = 'Storage Unit',
description = 'Your pin was changed',
type = 'success',
duration = 8000,
position = 'top',
})
end
if Config.Notify == 'swt' then
exports['swt_notifications']:Success('success','Your pin was changed!','top',8000,true)
end
if Config.Notify == 'okok' then
exports['okokNotify']:Alert("Storage Units", "Your pin was changed!", 8000, 'success')
end
if Config.Notify == 'esx' then
ESX.ShowNotification('Your pin was changed!')
end
if Config.Notify == 'ox' then
lib.notify({
title = 'Storage Units',
description = 'Your pin was changed!',
type = 'inform',
duration = 8000,
position = 'top'
})
end
if Config.Notify == 'custom' then
--Enter custom code here
end
end
else
if Config.Notify == 'ox_lib' then
lib.notify({
title = 'Storage Unit',
description = 'You have entered the wrong pin.',
type = 'error',
duration = 8000,
position = 'top',
})
end
if Config.Notify == 'swt' then
exports['swt_notifications']:Negative('error','You have entered the wrong pin. ','top',8000,true)
end
if Config.Notify == 'okok' then
exports['okokNotify']:Alert("Storage Units", "You have entered the wrong pin.", 8000, 'error')
end
if Config.Notify == 'esx' then
ESX.ShowNotification('You have entered the wrong pin.')
end
if Config.Notify == 'ox' then
lib.notify({
title = 'Storage Units',
description = 'You have entered the wrong pin.',
type = 'error',
duration = 8000,
position = 'top'
})
end
if Config.Notify == 'custom' then
--Enter custom code here
end
end
end, storageID,keyboard[1])
end
end)
--If the storage IS owned by YOU this menu pops up
RegisterNetEvent('koe_storageunitsv2:ownerMenu')
AddEventHandler('koe_storageunitsv2:ownerMenu',function(storageID, balance)
rentBalance = balance
lib.registerContext({
id = 'ownermenu',
title = 'Storage Management',
options = {
['Open Storage'] = {
description = 'Open your storage unit',
arrow = true,
event = 'koe_storageunitsv2:registerStash',
metadata = {'Open this unit'}
},
['Rent Management'] = {
description = 'Rent Management',
arrow = true,
event = 'koe_storageunitsv2:rentMenu',
metadata = {"Click to manage rent"}
},
['Pin Management'] = {
description = 'Change your Pin',
arrow = true,
event = 'koe_storageunitsv2:changePin',
metadata = {'You will enter current pin to change it.'}
},
['Sell this unit'] = {
description = 'Put the unit back on the market',
arrow = true,
event = 'koe_storageunitsv2:sellConfirm',
metadata = {'This will take you to another menu to sell the unit'}
},
}
})
lib.showContext('ownermenu')
end)
RegisterNetEvent('koe_storageunitsv2:rentMenu')
AddEventHandler('koe_storageunitsv2:rentMenu',function(storageID)
lib.registerContext({
id = 'rentmenu',
title = 'Rent Menu',
options = {
['Rent Balance'] = {
description = 'You have $'..rentBalance..' in the account',
},
['Add Rent'] = {
description = 'Add rent to balance',
arrow = true,
event = 'koe_storageunitsv2:addBalance',
metadata = {'Rent cost is ($' ..Config.RentPrice..') its due every week on the date of purchase. Click to add more money'}
},
['Remove Balance'] = {
description = 'Remove Balance',
arrow = true,
event = 'koe_storageunitsv2:removeBalance',
metadata = {"Click to withdrawl the money in your account"}
},
}
})
lib.showContext('rentmenu')
end)
RegisterNetEvent('koe_storageunitsv2:addBalance')
AddEventHandler('koe_storageunitsv2:addBalance', function(data)
local input = lib.inputDialog('Add Balance to rent', {'Rent Amount'})
if input[1] then
rent = tonumber(input[1])
TriggerServerEvent('koe_storageunitsv2:addRentBalance', rent, rentBalance, storageID)
end
end)
RegisterNetEvent('koe_storageunitsv2:removeBalance')
AddEventHandler('koe_storageunitsv2:removeBalance', function(data)
local input = lib.inputDialog('Remove Balance from rent', {'Amount'})
if input[1] then
amount = tonumber(input[1])
TriggerServerEvent('koe_storageunitsv2:removeRentBalance', amount, rentBalance, storageID)
end
end)
RegisterNetEvent('koe_storageunitsv2:registerStash')
AddEventHandler('koe_storageunitsv2:registerStash', function(data)
local keyboard2 = lib.inputDialog('Enter your current PIN', {
{ type = "input", label = "Unit PIN", password = true, icon = 'lock' },
})
if keyboard2[1] ~= nil then
ESX.TriggerServerCallback('koe_storageunitsv2:checkPin', function(pin)
if pin then
TriggerServerEvent('koe_storageunitsv2:registerStash', storageID)
else
if Config.Notify == 'ox_lib' then
lib.notify({
title = 'Storage Unit',
description = 'You have entered the wrong pin',
type = 'error',
duration = 8000,
position = 'top',
})
end
if Config.Notify == 'swt' then
exports['swt_notifications']:Negative('error','You have entered the wrong pin.','top',8000,true)
end
if Config.Notify == 'okok' then
exports['okokNotify']:Alert("Storage Units", "You have entered the wrong pin.", 8000, 'error')
end
if Config.Notify == 'esx' then
ESX.ShowNotification('You have entered the wrong pin.')
end
if Config.Notify == 'ox' then
lib.notify({
title = 'Storage Units',
description = 'You have entered the wrong pin.',
type = 'error',
duration = 8000,
position = 'top'
})
end
if Config.Notify == 'custom' then
--Enter custom code here
end
end
end, storageID,keyboard2[1])
end
end)
RegisterNetEvent('koe_storageunitsv2:openStash')
AddEventHandler('koe_storageunitsv2:openStash', function(stashID)
TriggerEvent('ox_inventory:openInventory', 'stash', stashID)
Wait(2000)
LoadAnimDict('anim@gangops@facility@servers@bodysearch@')
TaskPlayAnim(PlayerPedId(), "anim@gangops@facility@servers@bodysearch@" ,"player_search" ,8.0, -8.0, -1, 48, 0, false, false, false )
end)
function LoadAnimDict(dict)
while (not HasAnimDictLoaded(dict)) do
RequestAnimDict(dict)
Citizen.Wait(10)
end
end
RegisterNetEvent('koe_storageunitsv2:sellConfirm')
AddEventHandler('koe_storageunitsv2:sellConfirm',function(storageID)
lib.registerContext({
id = 'sellmenu',
title = 'Sell Unit',
options = {
['Sell Unit'] = {
description = 'Sell the unit',
arrow = true,
event = 'koe_storageunitsv2:storageSell',
metadata = {'This will sell the unit!'}
},
}
})
lib.showContext('sellmenu')
end)
RegisterNetEvent('koe_storageunitsv2:storageSell')
AddEventHandler('koe_storageunitsv2:storageSell', function()
TriggerServerEvent('koe_storageunitsv2:sellUnit', storageID)
if Config.Notify == 'ox_lib' then
lib.notify({
title = 'Storage Unit',
description = 'You have sold the unit!',
type = 'success',
duration = 8000,
position = 'top',
})
end
if Config.Notify == 'swt' then
exports['swt_notifications']:Success('success','You sold the unit!','top',8000,true)
end
if Config.Notify == 'okok' then
exports['okokNotify']:Alert("Storage Units", "You sold the unit!", 8000, 'success')
end
if Config.Notify == 'esx' then
ESX.ShowNotification('You sold the unit!')
end
if Config.Notify == 'ox' then
lib.notify({
title = 'Storage Units',
description = 'You sold the unit!',
type = 'success',
duration = 8000,
position = 'top'
})
end
if Config.Notify == 'custom' then
--Enter custom code here
end
end)
--If the storage IS owned but not by you this menu pops up
RegisterNetEvent('koe_storageunitsv2:otherMenu')
AddEventHandler('koe_storageunitsv2:otherMenu',function(storageID)
lib.registerContext({
id = 'othermenu',
title = 'Owned Storage',
options = {
['Open Storage Unit'] = {
description = 'Open unit with pin',
event = 'koe_storageunitsv2:registerStash'
}
}
})
lib.showContext('othermenu')
end)
RegisterNetEvent('koe_storageunitsv2:policeBreach')
AddEventHandler('koe_storageunitsv2:policeBreach', function(storageID)
for k, v in pairs(Config.Policeraid.Jobs) do
if v.job == ESX.PlayerData.job.name and ESX.PlayerData.job.grade >= v.grade then
TriggerServerEvent('koe_storageunitsv2:registerStash', storageID.id)
TriggerServerEvent('koe_storageunitsv2:breachLog', storageID.id)
end
end
for k, v in pairs(Config.Policeraid.Jobs) do
if v.job == ESX.PlayerData.job.name and ESX.PlayerData.job.grade < v.grade then
if Config.Notify == 'ox_lib' then
lib.notify({
title = 'Storage Unit',
description = 'Not a high enough rank to do that.',
type = 'error',
duration = 8000,
position = 'top',
})
end
if Config.Notify == 'swt' then
exports['swt_notifications']:Negative('error','Not a high enough rank to do that.','top',8000,true)
end
if Config.Notify == 'okok' then
exports['okokNotify']:Alert("Storage Units", "Not a high enough rank to do that.", 8000, 'error')
end
if Config.Notify == 'esx' then
ESX.ShowNotification('Not a high enough rank to do that.')
end
if Config.Notify == 'ox' then
lib.notify({
title = 'Storage Units',
description = 'Not a high enough rank to do that!',
type = 'error',
duration = 8000,
position = 'top'
})
end
if Config.Notify == 'custom' then
--Enter custom code here
end
end
end
if ESX.PlayerData.job.name ~= 'police' then
if Config.Notify == 'ox_lib' then
lib.notify({
title = 'Storage Unit',
description = 'You are not a cop. You cannot do that.',
type = 'error',
duration = 8000,
position = 'top',
})
end
if Config.Notify == 'swt' then
exports['swt_notifications']:Negative('error','You cant do that, youre not a cop.','top',8000,true)
end
if Config.Notify == 'okok' then
exports['okokNotify']:Alert("Storage Units", "You cant do that, youre not a cop.", 8000, 'error')
end
if Config.Notify == 'esx' then
ESX.ShowNotification('You cant do that, youre not a cop.')
end
if Config.Notify == 'ox' then
lib.notify({
title = 'Storage Units',
description = 'You cant do that, youre not a cop!',
type = 'error',
duration = 8000,
position = 'top'
})
end
if Config.Notify == 'custom' then
--Enter custom code here
end
end
end)