-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.lua
881 lines (796 loc) · 32.6 KB
/
server.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
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
local cfg = module("muamba_inventario_v2","config")
Tunnel.bindInterface("muamba_inventario_v2",srv)
Proxy.addInterface('muamba_inventario_v2',srv)
-----------------------------------------------------------------------------------------------------------------------------------------
-- Tabelas e temp_data
-----------------------------------------------------------------------------------------------------------------------------------------
local itens_config = usaveis
local chests = cfg.chest
local user_temp_trunk = {}
local tmp_chest = {}
local tmp_trunk_chest = {}
local cache = {}
cache.chestWeight = {} --Cache de baus de facs
srv.getInventory = function()
local source = source
local user_id = vRP.getUserId(source)
local inventory = {}
if user_id then
local data = GetInventory(user_id)
if data then
for k,v in pairs(data) do
if srv.get_info_item(k) then
table.insert(inventory,{ amount = parseInt(v.amount), name = srv.get_name_list(k), index = srv.get_index_item(k), key = k, type = srv.get_type_item(k), peso = parseInt(srv.get_item_peso(k)*v.amount) })
end
end
return inventory,GetInventoryWeight(user_id),GetInventoryMaxWeight(user_id)
end
end
end
srv.getPlayerWeapons = function()
local source = source
local user_id = vRP.getUserId(source)
if user_id then return GetPlayerWeapons(source,user_id) end
end
srv.get_chest_itens = function(name_chest)
if name_chest then
local itens = {}
local chest = "chest:"..name_chest
local data = vRP.getSData(chest)
local sdata = json.decode(data) or {}
if sdata then
for k,v in pairs(sdata) do
if srv.get_info_item(k) then
table.insert(itens,{ amount = parseInt(v.amount), name = srv.get_name_list(k), index = srv.get_index_item(k), key = k, type = srv.get_type_item(k), peso = parseInt(srv.get_item_peso(k)) })
end
end
return itens
end
end
end
srv.getPesoChest = function(data)
if data then
local chestTable = {}
local pesoChest = 0
for k,v in pairs(data) do
local pesoItemChest = srv.get_item_peso(k) * v.amount
pesoChest = pesoChest + pesoItemChest
end
return pesoChest
end
end
-----------------------------------------------------------------------------------------------------------------------------------------
-- Inventario
-----------------------------------------------------------------------------------------------------------------------------------------
srv.funcao_inventario = function(source)
local source = source
local user_id = vRP.getUserId(source)
if user_id then
local inventory = {}
local weapons = {}
local data = vRP.getUserDataTable(user_id)
if data and data.inventory then
for k,v in pairs(data.inventory) do
if srv.get_info_item(k) then
table.insert(inventory,{ amount = parseInt(v.amount), name = srv.get_name_list(k), index = srv.get_index_item(k), key = k, type = srv.get_type_item(k), peso = parseInt(srv.get_item_peso(k)*v.amount) })
end
end
return inventory,weapons,GetInventoryWeight(user_id),GetInventoryMaxWeight(user_id)
end
end
end
srv.EquipWeapon = function(item)
local source = source
local user_id = vRP.getUserId(source)
if user_id then
EquipWeapon(source,user_id,item)
end
end
srv.EquipAmmo = function(item,amount)
local source = source
local user_id = vRP.getUserId(source)
if user_id then
EquipAmmo(source,user_id,item,amount)
cl.updateMochila(source)
end
end
checkWeaponEquiped = function(source,key)
local slit = split(key,"|")[2]
for k,v in pairs(vRPclient.getWeapons(source))do
if k == slit then
return true
end
end
end
srv.garmas = function(item)
local source = source
local user_id = vRP.getUserId(source)
if user_id then
Garmas(source,user_id,item)
end
end
srv.useItem = function(index,name,amount,key)
local source = source
local user_id = vRP.getUserId(source)
if user_id and key ~= nil and name ~= nil then
if itens_config[key] ~= nil then
cl.closeNUI(source)
itens_config[key](source,user_id)
else
TriggerClientEvent('Notify',source,'negado','Este item não é usavel!')
end
end
end
srv.sendItem = function(index,name,amount,key)
local source = source
local user_id = vRP.getUserId(source)
if user_id and amount and tonumber(amount) >= 0 then
if verify_item(key,'enviar') then
SendItem(source,user_id,index,name,amount,key)
end
end
end
-----------------------------------------------------------------------------------------------------------------------------------------
-- Sistema de bau
-----------------------------------------------------------------------------------------------------------------------------------------
RemoveWeightInCache = function(chestName,value)
if cache.chestWeight[chestName] then
cache.chestWeight[chestName] = cache.chestWeight[chestName] - value
else
CreateCacheChestFacs(chestName)
end
end
AddWeightInCache = function(chestName,value)
if cache.chestWeight[chestName] then
cache.chestWeight[chestName] = cache.chestWeight[chestName] + value
else
CreateCacheChestFacs(chestName)
end
end
CreateCacheChestFacs = function(chestName)
local chest = "chest:"..chestName
local data = json.decode(vRP.getSData(chest)) or {}
if data then
local pesoChest = 0
for k,v in pairs(data) do
local pesoItemChest = srv.get_item_peso(k) * v.amount
pesoChest = pesoChest + pesoItemChest
end
cache.chestWeight[chestName] = pesoChest
return cache.chestWeight[chestName]
end
end
GetChestWeight = function(chestName)
if cache.chestWeight[chestName] then
return parseInt(cache.chestWeight[chestName])
else
return parseInt(CreateCacheChestFacs(chestName))
end
end
srv.getChest = function(chestName)
local source = source
local user_id = vRP.getUserId(source)
if user_id and chestName then
local itens = {}
local _data = vRP.getSData("chest:"..chestName)
local sdata = json.decode(_data) or {}
if sdata then
for k,v in pairs(sdata) do
if srv.get_info_item(k) then
table.insert(itens,{ amount = parseInt(v.amount), name = srv.get_name_list(k), index = srv.get_index_item(k), key = k, type = srv.get_type_item(k), peso = srv.get_item_peso(k) })
end
end
return itens,chests[chestName].tamanho,GetChestWeight(chestName)
end
end
end
srv.check_permi_bau = function(index)
local source = source
local user_id = vRP.getUserId(source)
if user_id then
if HasPermission(user_id,chests[index].permissao) then
return true
else
TriggerClientEvent('Notify',source,'negado',"Você não tem acesso a este bau!",8000)
end
return
end
end
srv.store_item = function(chestName,item,amount)
local source = source
local user_id = vRP.getUserId(source)
local temp_amount = amount
if user_id and not active[user_id] and temp_amount and temp_amount >= 0 then
active[user_id] = true
local chest = "chest:"..chestName
local sdata = json.decode(vRP.getSData(chest)) or {}
if sdata then
local chestPeso = GetChestWeight(chestName)
if chestPeso then
if (chestPeso + (srv.get_item_peso(item) * amount)) <= chests[chestName].tamanho then
if TryItem(user_id,item,tonumber(amount)) then
if sdata[item] ~= nil then
amount = amount + sdata[item].amount
sdata[item] = {amount = parseInt(amount)}
else
sdata[item] = {amount = parseInt(amount)}
end
vRP.setSData(chest,json.encode(sdata))
AddWeightInCache(chestName,srv.get_item_peso(item) * temp_amount)
TriggerEvent('groupmanager:chestAction',{org = chestName,user_id = user_id, action = "GUARDOU", item = item or "", amount = temp_amount or 0})
TriggerClientEvent('Notify',source,'sucesso',"Você guardou no bau "..temp_amount.."x "..srv.get_name_list(item))
webhook(chests[chestName].log,"```prolog\n[MUAMBA_CHEST]\n[ACTION]:COLOCOU\n[ID]:"..user_id.."\n[DB]:"..chestName.."\n[ITEM]:"..item.."\n[QUANTIDADE]:"..temp_amount..os.date("\n[Data]: %d/%m/%Y [Hora]: %H:%M:%S").."\n```")
else
TriggerClientEvent('Notify',source,'negado',"Você não possui "..temp_amount.."x "..srv.get_name_list(item))
end
else
TriggerClientEvent('Notify',source,'negado',"Este item não cabe no bau!")
end
end
end
active[user_id] = false
end
end
srv.take_item = function(chestName,item,amount)
local source = source
local user_id = vRP.getUserId(source)
local temp_amount = amount
if user_id and not active[user_id] and temp_amount and temp_amount >= 0 then
active[user_id] = true
if (GetInventoryWeight(user_id) + (srv.get_item_peso(item) * temp_amount)) <= GetInventoryMaxWeight(user_id) then
local chest = "chest:"..chestName
local sdata = json.decode(vRP.getSData(chest)) or {}
if sdata then
if sdata and sdata[item] and sdata[item].amount >= temp_amount then
local chest_amount = sdata[item].amount - temp_amount
if chest_amount == 0 then
sdata[item] = nil
else
sdata[item].amount = parseInt(chest_amount)
end
vRP.setSData(chest,json.encode(sdata))
RemoveWeightInCache(chestName,srv.get_item_peso(item) * temp_amount)
GiveItem(user_id,item,temp_amount)
TriggerClientEvent('Notify',source,'sucesso',"Você retirou "..amount.."x "..srv.get_name_list(item))
end
webhook(chests[chestName].log,"```prolog\n[MUAMBA_CHEST]\n[ACTION]:RETIROU\n[ID]:"..user_id.."\n[DB]:"..chestName.."\n[ITEM]:"..item.."\n[QUANTIDADE]:"..amount..os.date("\n[Data]: %d/%m/%Y [Hora]: %H:%M:%S").."\n```")
end
else
TriggerClientEvent('Notify',source,'negado',"Sua mochila está cheia ou não cabe este item!")
end
active[user_id] = false
end
end
srv.check_use_chest = function(chest_name)
local source = source
local user_id = vRP.getUserId(source)
if user_id and chest_name then
if tmp_chest[chest_name] == nil then
tmp_chest[chest_name] = user_id
return true
else
TriggerClientEvent('Notify',source,'negado',"O báu está em uso no momento!")
return false
end
end
end
srv.remove_chest_use = function(chest_name)
if chest_name ~= nil then
if tmp_chest[chest_name] then
tmp_chest[chest_name] = nil
end
end
end
-----------------------------------------------------------------------------------------------------------------------------------
-- Sistema de Porta malas
-----------------------------------------------------------------------------------------------------------------------------------
srv.getTrunkChest = function(veh)
local source = source
local user_id = vRP.getUserId(source)
if user_id then
local vname, plate, lock = veh.vname,veh.plate,veh.lock
if plate then
local portaMalas = {}
local placa_user_id = GetOwnerVehicle(plate,true)
local mala = "chest:u"..parseInt(placa_user_id).."veh_"..vname
local data = json.decode(vRP.getSData(mala)) or {}
if data then
for k,v in pairs(data) do
if srv.get_info_item(k) then
table.insert(portaMalas,{ amount = parseInt(v.amount), name = srv.get_name_list(k), index = srv.get_index_item(k), key = k, type = srv.get_type_item(k), peso = srv.get_item_peso(k) })
end
end
return portaMalas,GetVehicleTrunkSize(vname),srv.getPesoChest(data)
end
end
end
end
srv.store_item_trunk = function(plate,vname,item,amount)
local source = source
local user_id = vRP.getUserId(source)
if user_id and item and plate and vname and not active[user_id] and amount and tonumber(amount) >= 0 then
active[user_id] = true
if verify_item(item,'trunk') then
local placa_user_id = GetOwnerVehicle(plate,true)
if placa_user_id then
local max_chest = GetVehicleTrunkSize(vname)
local mala = "chest:u"..parseInt(placa_user_id).."veh_"..vname
local porta_malas = json.decode(vRP.getSData(mala)) or {}
local current_weight = srv.getPesoChest(porta_malas)
if current_weight + (srv.get_item_peso(item) * amount) <= max_chest then
if TryItem(user_id,item,tonumber(amount)) then
if porta_malas[item] then
porta_malas[item].amount = parseInt(porta_malas[item].amount + amount)
else
porta_malas[item] = {amount = parseInt(amount)}
end
vRP.setSData(mala,json.encode(porta_malas))
TriggerClientEvent('Notify',source,'sucesso',"Você guardou "..amount.."x "..srv.get_name_list(item))
webhook(config.webhook.trunkColocar,"```prolog\n[MUAMBA_TRUNK]\n[ACTION]:COLOCOU\n[ID]:"..user_id.."\n[DB]:"..mala.."\n[ITEM]:"..item.."\n[QUANTIDADE]:"..amount..os.date("\n[Data]: %d/%m/%Y [Hora]: %H:%M:%S").."\n```")
end
else
TriggerClientEvent('Notify',source,'aviso',"Espaço insuficiente!")
end
end
else
TriggerClientEvent('Notify',source,'aviso','Este item não pode ser guardado no porta malas!')
end
active[user_id] = false
end
end
srv.take_item_trunk = function(plate,vname,item,amount)
local source = source
local user_id = vRP.getUserId(source)
if user_id and item and not active[user_id] and amount and tonumber(amount) >= 0 then
active[user_id] = true
if plate and vname then
local placa_user_id = GetOwnerVehicle(plate,true)
if placa_user_id then
local mala = "chest:u"..parseInt(placa_user_id).."veh_"..vname
local data = vRP.getSData(mala)
local porta_malas = json.decode(data) or {}
if porta_malas then
if (GetInventoryWeight(user_id) + (srv.get_item_peso(item) * tonumber(amount))) <= GetInventoryMaxWeight(user_id) then
if porta_malas[item] and tonumber(amount) <= porta_malas[item].amount then
if (porta_malas[item].amount - amount) == 0 then
porta_malas[item] = nil
else
porta_malas[item].amount = porta_malas[item].amount - amount
end
vRP.setSData(mala,json.encode(porta_malas))
GiveItem(user_id,item,parseInt(amount))
TriggerClientEvent('Notify',source,'sucesso',"Você pegou "..parseInt(amount).."x "..srv.get_name_list(item))
webhook(config.webhook.trunkRetirar,"```prolog\n[MUAMBA_TRUNK]\n[ACTION]:PEGAR\n[ID]:"..user_id.."\n[DB]:"..mala.."\n[ITEM]:"..item.."\n[QUANTIDADE]:"..amount..os.date("\n[Data]: %d/%m/%Y [Hora]: %H:%M:%S").."\n```")
end
else
TriggerClientEvent('Notify',source,'aviso',"Espaço insuficiente!")
end
end
end
end
active[user_id] = false
end
end
srv.check_user_trunk = function(vnetid,placa,lock)
local source = source
local user_id = vRP.getUserId(source)
if placa ~= nil then
if not lock then
user_temp_trunk[user_id] = placa
cl.open_trunk(-1,vnetid,false)
return true
elseif tonumber(lock) == 1 then
user_temp_trunk[user_id] = placa
cl.open_trunk(-1,vnetid,false)
return true
else
tmp_trunk_chest[placa] = nil
TriggerClientEvent('Notify',source,'negado',"Veiculo está trancado!",3000)
return false
end
end
end
srv.openTrunk = function(placa)
local source = source
local user_id = vRP.getUserId(source)
if user_id then
Wait(math.random(1,100))
if tmp_trunk_chest[placa] == nil then
tmp_trunk_chest[placa] = source
return true
end
end
TriggerClientEvent('Notify',source,'negado',"Indisponivel!",3000)
return false
end
srv.remove_user_trunk = function(placa,vnetid)
local source = source
local user_id = vRP.getUserId(source)
user_temp_trunk[user_id] = nil
tmp_trunk_chest[placa] = nil
cl.open_trunk(-1,vnetid,true)
end
-----------------------------------------------------------------------------------------------------------------------------------
-- Sistema para homes
-----------------------------------------------------------------------------------------------------------------------------------
local user_homes = { }
local chestSize = { }
local cacheHomes = { }
local smHouse = { }
Citizen.CreateThread(function()
if config.homes_summer then
return
else
local table = config.core.gerateSizeHome()
if type(table) == "table" then
chestSize = table
print('[INVENTORY] Tabela de casas criada!')
else
print('[INVENTORY] Tabela de casas nao encotrada!')
end
end
end)
srv.openHomeChest = function(source,user_id,hname,vault)
if user_id and source then
if hname then
if cacheHomes[hname] == nil then
cacheHomes[hname] = user_id
local chest,dkey = config.core.getHomeChest(hname)
user_homes[user_id] = dkey
if vault then
smHouse[user_id] = vault
cl.open_house_chest(source,hname)
else
cl.open_house_chest(source,hname)
end
else
TriggerClientEvent('Notify',source,'sucesso','Bau em uso!',10000)
end
else
print('[INVENTORY ERROR] Nome da casa nao informado!')
end
end
end
srv.getItensHomes = function(hname)
local source = source
local user_id = vRP.getUserId(source)
if user_id then
local chest,dkey = config.core.getHomeChest(hname)
local itens = {}
user_homes[user_id] = dkey
for k,v in pairs(chest) do
if srv.get_info_item(k) then
table.insert(itens,{ amount = parseInt(v.amount), name = srv.get_name_list(k), index = srv.get_index_item(k), key = k, type = srv.get_type_item(k), peso = srv.get_item_peso(k) })
end
end
if smHouse[user_id] then
return itens,smHouse[user_id],getWeightItemHomes(chest)
else
return itens,chestSize[hname],getWeightItemHomes(chest)
end
end
end
getWeightItemHomes = function(data)
local peso = 0
for k,v in pairs(data) do
peso = parseInt(peso + (srv.get_item_peso(k) * v.amount))
end
return peso
end
srv.storeHomeChest = function(item,amount,index)
local itens = {}
local source = source
local user_id = vRP.getUserId(source)
if user_id and not active[user_id] and amount and tonumber(amount) >= 0 then
active[user_id] = true
local data = config.core.getHomeChest(index)
if amount == 0 then
amount = ItemAmount(user_id,item)
end
local weightHomes = getWeightItemHomes(data)
local maxChest = 0
if smHouse[user_id] then
maxChest = smHouse[user_id]
else
maxChest = chestSize[index]
end
if verify_item(item,'homes') then
if (weightHomes + (srv.get_item_peso(item)*amount)) <= maxChest then
if TryItem(user_id,item,amount) then
if data[item] then
data[item].amount = data[item].amount + amount
else
data[item] = {amount = parseInt(amount)}
end
webhook(config.webhook.homesStore,"```prolog\n[USER_iD]:"..user_id.."\n[ITEM]:"..srv.get_name_list(item)..'\n[QUANTIDADE]:'..amount..os.date("\n[Data]: %d/%m/%Y [Hora]: %H:%M:%S").."\n```")
vRP.setSData(user_homes[user_id],json.encode(data))
end
else
TriggerClientEvent('Notify',source,'negado','Espaço insuficiente!')
end
else
TriggerClientEvent('Notify',source,'negado','Você não pode guardar este item.',10000)
end
active[user_id] = false
end
end
srv.takeItemHome = function(item,amount,index)
local source = source
local user_id = vRP.getUserId(source)
if user_id and not active[user_id] and amount and tonumber(amount) >= 0 then
active[user_id] = true
local data = config.core.getHomeChest(index)
if data[item] and data[item].amount >= amount then
if amount == 0 then
amount = data[item].amount
end
local inv_peso = GetInventoryWeight(user_id)
if inv_peso + srv.get_item_peso(item) * amount <= GetInventoryMaxWeight(user_id) then
if data[item].amount - amount == 0 then
data[item] = nil
else
data[item].amount = data[item].amount - amount
end
GiveItem(user_id,item,amount)
vRP.setSData(user_homes[user_id],json.encode(data))
TriggerClientEvent('Notify',source,'sucesso','Você retirou '..amount.."x "..srv.get_name_list(item),10000)
webhook(config.webhook.homesTake,"```prolog\n[USER_iD]:"..user_id.."\n[ITEM]:"..srv.get_name_list(item)..'\n[QUANTIDADE]:'..amount..os.date("\n[Data]: %d/%m/%Y [Hora]: %H:%M:%S").."\n```")
end
end
active[user_id] = false
end
end
RegisterServerEvent('removeUserHomes')
AddEventHandler('removeUserHomes',function(index)
if cacheHomes[index] then
cacheHomes[index] = nil
if smHouse[user_id] then
smHouse[user_id] = nil
end
end
end)
AddEventHandler("playerDropped",function(reason)
local source = source
local user_id = vRP.getUserId(source)
if user_id then
for k,v in pairs(cacheHomes) do
if user_id == v then
cacheHomes[k] = nil
if smHouse[user_id] then
smHouse[user_id] = nil
end
end
end
end
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- Sistema de dropar
-----------------------------------------------------------------------------------------------------------------------------------------
local dropProp = {}
RegisterServerEvent('inventario:registerDrop')
AddEventHandler('inventario:registerDrop',function(index,quantidade,coord)
local source = source
local user_id = vRP.getUserId(source)
if user_id and TryItem(user_id,index,quantidade) then
addNewDrop(index,quantidade,coord)
cl.syncTable(-1,#dropProp,dropProp[#dropProp])
cl.CreateDrop(source,index,coord,#dropProp,quantidade)
TriggerClientEvent('Notify',source,'sucesso',"Você soltou "..quantidade.."x "..srv.get_name_list(index))
cl.closeNUI(source)
webhook(config.webhook.droparItem,"```prolog\n[DROPITEM]\n[ID]:"..user_id.."\n[ITEM]:"..index.."\n[QUANTIDADE]:"..quantidade..os.date("\n[Data]: %d/%m/%Y [Hora]: %H:%M:%S").."\n```")
vRPclient.playAnim(source,true,{{"pickup_object","pickup_low"}},false)
end
end)
addNewDrop = function(index,quantidade,coord)
dropProp[#dropProp+1] = {item = index,nitem = srv.get_name_list(index), count = quantidade,coordenada = coord,status = true,netId = 0,take = true}
end
RegisterServerEvent('create:item_drop')
AddEventHandler('create:item_drop',function(source, index, quantidade, coord)
addNewDrop(index,quantidade,coord)
cl.syncTable(-1,#dropProp,dropProp[#dropProp])
cl.CreateDrop(source,index,coord,#dropProp,quantidade)
TriggerClientEvent('Notify',source,'sucesso',"Você soltou "..quantidade.."x "..srv.get_name_list(index))
cl.closeNUI(source)
webhook(config.webhook.droparItem,"```prolog\n[DROPITEM]\n[ID]:"..user_id.."\n[ITEM]:"..index.."\n[QUANTIDADE]:"..quantidade..os.date("\n[Data]: %d/%m/%Y [Hora]: %H:%M:%S").."\n```")
end)
RegisterServerEvent('inventario:sync:drop:System')
AddEventHandler('inventario:sync:drop:System',function(fix,value)
dropProp[fix] = value
cl.syncTable(-1,fix,dropProp[fix])
end)
RegisterServerEvent('inventario:take:item:dropSystem')
AddEventHandler('inventario:take:item:dropSystem',function(index,item,qtd)
if dropProp[index].take then
dropProp[index].take = false
cl.syncTable(-1,index,dropProp[index])
local source = source
local user_id = vRP.getUserId(source)
if user_id then
local new_weight = GetInventoryWeight(user_id)+srv.get_item_peso(item)*qtd
if new_weight <= GetInventoryMaxWeight(user_id) then
GiveItem(user_id,item,qtd,true)
TriggerClientEvent('Notify',source,'sucesso',"Você pegou "..qtd.."x "..srv.get_name_list(item))
cl.closeNUI(source)
vRPclient.playAnim(source,true,{{"pickup_object","pickup_low"}},false)
dropProp[index] = {}
cl.syncTable(-1,index,dropProp[index])
webhook(config.webhook.dropPegar,"```prolog\n[DROP ITEM PEGAR]\n[ID]:"..user_id.."\n[ITEM]:"..srv.get_name_list(item).."\n[QUANTIDADE]:"..qtd..os.date("\n[Data]: %d/%m/%Y [Hora]: %H:%M:%S").."\n```")
else
dropProp[index].take = true
cl.syncTable(-1,index,dropProp[index])
end
end
end
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- Sistema de itens
-----------------------------------------------------------------------------------------------------------------------------------------
local item_list = cfg.itens
srv.create = function()
local itens_create = {}
for k,v in pairs(item_list) do
itens_create[k] = {v.nome,v.peso}
end
return itens_create
end
srv.get_name_list = function(index)
if item_list[index] ~= nil then
return item_list[index].nome
end
end
srv.get_index_item = function(index)
if item_list[index] ~= nil then
return item_list[index].index
end
end
srv.get_type_item = function(index)
if item_list[index] ~= nil then
return item_list[index].type
end
end
srv.get_info_item = function(index)
if item_list[index] ~= nil then
return item_list[index]
end
end
srv.get_item_peso = function(item)
if item_list[item] ~= nil then
if item_list[item].peso ~= nil then
return item_list[item].peso
else
return 0
end
else
return 0
end
end
srv.get_name_peso = function(item)
if item_list[item] ~= nil then
return item_list[item].name, item_list[item].peso
end
end
Citizen.CreateThread(function()
local teste = {}
for k,v in pairs(cfg.weapons) do
item_list["wbody|"..k] = {index = v.index,peso = v.peso,type = 'equipar',nome = v.nome}
item_list["wammo|"..k] = {index = v.indexMunicao,peso = v.pesoMunicao,type = 'recarregar',nome = v.nomeMunicao}
end
for k,v in pairs(item_list) do
vRP.defInventoryItem(k,v.nome,v.peso)
end
print('[Inventario] : Todos os itens foram criados!')
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- Sistema de segurança
-----------------------------------------------------------------------------------------------------------------------------------------
srv.playerLeave_inventario = function(user_id)
for k,v in pairs(tmp_chest) do
if tmp_chest[k] == user_id then
tmp_chest[k] = nil
print("[Inventario-bau] -ID:"..user_id.." -BAU:"..k)
end
end
for k,v in pairs(user_temp_trunk) do
if k == user_id then
tmp_trunk_chest[v] = nil
user_temp_trunk[k] = nil
end
end
end
RegisterServerEvent('inventory:cacheRemove')
AddEventHandler('inventory:cacheRemove',function(user_id)
for k,v in pairs(tmp_chest) do
if tmp_chest[k] == user_id then
tmp_chest[k] = nil
print("[Inventario-bau] -ID:"..user_id.." -BAU:"..k)
end
end
for k,v in pairs(user_temp_trunk) do
if k == user_id then
tmp_trunk_chest[v] = nil
user_temp_trunk[k] = nil
end
end
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- Hot bar
-----------------------------------------------------------------------------------------------------------------------------------------
local activeHotBar = {}
srv.useItemHotBar = function(item)
local source = source
local user_id = vRP.getUserId(source)
if user_id and item then
if item_list[item] and item_list[item].type == 'equipar' then
local slit = split(item,"|")[2]
if not slit then return end
if vRPclient.getWeapons(source)[slit] then
SetCurrentWeapon(source,slit)
TriggerClientEvent('Notify',source,'sucesso','Você equipou uma arma!')
else
TriggerClientEvent('Notify',source,'negado','Você não possui esta arma equipada!')
end
return
end
if activeHotBar[user_id] == 0 or activeHotBar[user_id] == nil then
local n = 0
if config.cooldownItemsHotbar[item] then
n = config.cooldownItemsHotbar[item]
else
n = config.defaultTimeQuickAcess
end
if itens_config[item] then
--if TryItem(user_id,item,1) then
itens_config[item](source,user_id)
activeHotBar[user_id] = n
--end
end
else
TriggerClientEvent('Notify',source,'aviso','Aguarde '..activeHotBar[user_id]..' segundos para usar novamente!')
end
end
end
Citizen.CreateThread(function()
while true do
for k,v in pairs(activeHotBar) do
if v > 0 then
activeHotBar[k] = activeHotBar[k] - 1
end
end
Wait(1000)
end
end)
-----------------------------------------------------------------------------------------------------------------------------------------
-- Outros
-----------------------------------------------------------------------------------------------------------------------------------------
check_array_table = function(tabela)
local n = 0
for k,v in pairs(tabela) do
n = n + 1
end
return n
end
verify_item = function(item,type)
if config.blacklist[type] then
if config.blacklist[type][item] then
return false
else
return true
end
end
return true
end
AddEventHandler('playerDropped', function (reason)
local user_id = vRP.getUserId(source)
srv.playerLeave_inventario(user_id)
end)
Citizen.CreateThread(function()
while true do
Wait(1000 * config.resetCache)
print('Inventario : Todos os baus foram resetados!')
print('Inventario : Todos os portas-malas foram resetados!')
print('Inventario : Todas as tabelas temporarias foram resetadas!')
user_temp_trunk = {}
tmp_chest = {}
tmp_trunk_chest = {}
end
end)