-
Notifications
You must be signed in to change notification settings - Fork 27
/
main.lua
1131 lines (1012 loc) · 37.6 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
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
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Variables
local QBCore = exports['qb-core']:GetCoreObject()
local PlayerData = QBCore.Functions.GetPlayerData()
local inInventory = false
local currentWeapon = nil
local currentOtherInventory = nil
local Drops = {}
local CurrentDrop = nil
local DropsNear = {}
local CurrentVehicle = nil
local CurrentGlovebox = nil
local CurrentStash = nil
local isCrafting = false
local isHotbar = false
local WeaponAttachments = {}
local showBlur = true
local stress = 0
-- Imported from qb-hud
RegisterNetEvent('hud:client:UpdateStress', function(newStress) -- Add this event with adding stress elsewhere
stress = newStress
end)
local function HasItem(items, amount)
local isTable = type(items) == 'table'
local isArray = isTable and table.type(items) == 'array' or false
local totalItems = #items
local count = 0
local kvIndex = 2
if isTable and not isArray then
totalItems = 0
for _ in pairs(items) do totalItems += 1 end
kvIndex = 1
end
for _, itemData in pairs(PlayerData.items) do
if isTable then
for k, v in pairs(items) do
local itemKV = {k, v}
if itemData and itemData.name == itemKV[kvIndex] and ((amount and itemData.amount >= amount) or (not isArray and itemData.amount >= v) or (not amount and isArray)) then
count += 1
end
end
if count == totalItems then
return true
end
else -- Single item as string
if itemData and itemData.name == items and (not amount or (itemData and amount and itemData.amount >= amount)) then
return true
end
end
end
return false
end
exports("HasItem", HasItem)
RegisterNUICallback('showBlur', function()
Wait(50)
TriggerEvent("ps-inventory:client:showBlur")
end)
RegisterNetEvent("ps-inventory:client:showBlur", function()
Wait(50)
showBlur = not showBlur
end)
-- Functions
local function GetClosestVending()
local ped = PlayerPedId()
local pos = GetEntityCoords(ped)
local object = nil
for _, machine in pairs(Config.VendingObjects) do
local ClosestObject = GetClosestObjectOfType(pos.x, pos.y, pos.z, 0.75, GetHashKey(machine), 0, 0, 0)
if ClosestObject ~= 0 then
if object == nil then
object = ClosestObject
end
end
end
return object
end
local function OpenVending()
local ShopItems = {}
ShopItems.label = "Vending Machine"
ShopItems.items = Config.VendingItem
ShopItems.slots = #Config.VendingItem
TriggerServerEvent("inventory:server:OpenInventory", "shop", "Vendingshop_"..math.random(1, 99), ShopItems)
end
local function DrawText3Ds(x, y, z, text)
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(true)
AddTextComponentString(text)
SetDrawOrigin(x,y,z, 0)
DrawText(0.0, 0.0)
local factor = (string.len(text)) / 370
DrawRect(0.0, 0.0+0.0125, 0.017+ factor, 0.03, 0, 0, 0, 75)
ClearDrawOrigin()
end
local function LoadAnimDict(dict)
if HasAnimDictLoaded(dict) then return end
RequestAnimDict(dict)
while not HasAnimDictLoaded(dict) do
Wait(10)
end
end
local function FormatWeaponAttachments(itemdata)
local attachments = {}
itemdata.name = itemdata.name:upper()
if itemdata.info.attachments ~= nil and next(itemdata.info.attachments) ~= nil then
for _, v in pairs(itemdata.info.attachments) do
attachments[#attachments+1] = {
attachment = v.item,
label = v.label,
image = QBCore.Shared.Items[v.item].image,
component = v.component
}
end
end
return attachments
end
local function IsBackEngine(vehModel)
return BackEngineVehicles[vehModel]
end
local function OpenTrunk()
local vehicle = QBCore.Functions.GetClosestVehicle()
LoadAnimDict("amb@prop_human_bum_bin@idle_b")
TaskPlayAnim(PlayerPedId(), "amb@prop_human_bum_bin@idle_b", "idle_d", 4.0, 4.0, -1, 50, 0, false, false, false)
if IsBackEngine(GetEntityModel(vehicle)) then
SetVehicleDoorOpen(vehicle, 4, false, false)
else
SetVehicleDoorOpen(vehicle, 5, false, false)
end
end
---Closes the trunk of the closest vehicle
local function CloseTrunk()
local vehicle = QBCore.Functions.GetClosestVehicle()
LoadAnimDict("amb@prop_human_bum_bin@idle_b")
TaskPlayAnim(PlayerPedId(), "amb@prop_human_bum_bin@idle_b", "exit", 4.0, 4.0, -1, 50, 0, false, false, false)
if IsBackEngine(GetEntityModel(vehicle)) then
SetVehicleDoorShut(vehicle, 4, false)
else
SetVehicleDoorShut(vehicle, 5, false)
end
end
---Closes the inventory NUI
local function closeInventory()
SendNUIMessage({
action = "close",
})
end
local function ToggleHotbar(toggle)
local HotbarItems = {
[1] = PlayerData.items[1],
[2] = PlayerData.items[2],
[3] = PlayerData.items[3],
[4] = PlayerData.items[4],
[5] = PlayerData.items[5],
[41] = PlayerData.items[41],
}
SendNUIMessage({
action = "toggleHotbar",
open = toggle,
items = HotbarItems
})
end
local function openAnim()
local ped = PlayerPedId()
LoadAnimDict('pickup_object')
TaskPlayAnim(ped,'pickup_object', 'putdown_low', 5.0, 1.5, 1.0, 48, 0.0, 0, 0, 0)
Wait(500)
StopAnimTask(ped, 'pickup_object', 'putdown_low', 1.0)
end
local function ItemsToItemInfo()
local item_count = 0
for _, _ in pairs(Config.CraftingItems) do
item_count = item_count + 1
end
local itemInfos = {}
for i = 1, item_count do
local ex_string = ""
for key, value in pairs(Config.CraftingItems[i].costs) do
ex_string = ex_string .. QBCore.Shared.Items[key]["label"] .. ": " .. value .. "x "
end
itemInfos[i] = { costs = ex_string }
end
local items = {}
for _, item in pairs(Config.CraftingItems) do
local itemInfo = QBCore.Shared.Items[item.name:lower()]
items[item.slot] = {
name = itemInfo["name"],
amount = tonumber(item.amount),
info = itemInfos[item.slot],
label = itemInfo["label"],
description = itemInfo["description"] or "",
weight = itemInfo["weight"],
type = itemInfo["type"],
unique = itemInfo["unique"],
useable = itemInfo["useable"],
image = itemInfo["image"],
slot = item.slot,
costs = item.costs,
threshold = item.threshold,
points = item.points,
}
end
Config.CraftingItems = items
end
local function SetupAttachmentItemsInfo()
local item_count = 0
for _, _ in pairs(Config.AttachmentCrafting) do
item_count = item_count + 1
end
local itemInfos = {}
for i = 1, item_count do
local ex_string = ""
for key, value in pairs(Config.AttachmentCrafting[i].costs) do
ex_string = ex_string .. QBCore.Shared.Items[key]["label"] .. ": " .. value .. "x "
end
itemInfos[i] = { costs = ex_string }
end
local items = {}
for _, item in pairs(Config.AttachmentCrafting) do
local itemInfo = QBCore.Shared.Items[item.name:lower()]
items[item.slot] = {
name = itemInfo["name"],
amount = tonumber(item.amount),
info = itemInfos[item.slot],
label = itemInfo["label"],
description = itemInfo["description"] or "",
weight = itemInfo["weight"],
unique = itemInfo["unique"],
useable = itemInfo["useable"],
image = itemInfo["image"],
slot = item.slot,
costs = item.costs,
threshold = item.threshold,
points = item.points,
}
end
Config.AttachmentCrafting = items
end
local function GetThresholdItems()
ItemsToItemInfo()
local items = {}
for k in pairs(Config.CraftingItems) do
if PlayerData.metadata["craftingrep"] >= Config.CraftingItems[k].threshold then
items[k] = Config.CraftingItems[k]
end
end
return items
end
local function GetAttachmentThresholdItems()
SetupAttachmentItemsInfo()
local items = {}
for k in pairs(Config.AttachmentCrafting) do
if PlayerData.metadata["attachmentcraftingrep"] >= Config.AttachmentCrafting[k].threshold then
items[k] = Config.AttachmentCrafting[k]
end
end
return items
end
local function RemoveNearbyDrop(index)
if not DropsNear[index] then return end
local dropItem = DropsNear[index].object
if DoesEntityExist(dropItem) then
DeleteEntity(dropItem)
end
DropsNear[index] = nil
if not Drops[index] then return end
Drops[index].object = nil
Drops[index].isDropShowing = nil
end
---Removes all drops in the area of the client
local function RemoveAllNearbyDrops()
for k in pairs(DropsNear) do
RemoveNearbyDrop(k)
end
end
local function CreateItemDrop(index)
local dropItem = CreateObject(Config.ItemDropObject, DropsNear[index].coords.x, DropsNear[index].coords.y, DropsNear[index].coords.z, false, false, false)
DropsNear[index].object = dropItem
DropsNear[index].isDropShowing = true
PlaceObjectOnGroundProperly(dropItem)
FreezeEntityPosition(dropItem, true)
if Config.UseTarget then
exports['qb-target']:AddTargetEntity(dropItem, {
options = {
{
icon = 'fa-solid fa-bag-shopping',
label = "Open Bag",
action = function()
TriggerServerEvent("inventory:server:OpenInventory", "drop", index)
end,
}
},
distance = 2.5,
})
end
end
-- Events
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
LocalPlayer.state:set("inv_busy", false, true)
PlayerData = QBCore.Functions.GetPlayerData()
QBCore.Functions.TriggerCallback("inventory:server:GetCurrentDrops", function(theDrops)
Drops = theDrops
end)
end)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
LocalPlayer.state:set("inv_busy", true, true)
PlayerData = {}
RemoveAllNearbyDrops()
end)
RegisterNetEvent('QBCore:Client:UpdateObject', function()
QBCore = exports['qb-core']:GetCoreObject()
end)
RegisterNetEvent('QBCore:Player:SetPlayerData', function(val)
PlayerData = val
end)
AddEventHandler('onResourceStop', function(name)
if name ~= GetCurrentResourceName() then return end
if Config.UseItemDrop then RemoveAllNearbyDrops() end
end)
RegisterNetEvent('inventory:client:CheckOpenState', function(type, id, label)
local name = QBCore.Shared.SplitStr(label, "-")[2]
if type == "stash" then
if name ~= CurrentStash or CurrentStash == nil then
TriggerServerEvent('inventory:server:SetIsOpenState', false, type, id)
end
elseif type == "trunk" then
if name ~= CurrentVehicle or CurrentVehicle == nil then
TriggerServerEvent('inventory:server:SetIsOpenState', false, type, id)
end
elseif type == "glovebox" then
if name ~= CurrentGlovebox or CurrentGlovebox == nil then
TriggerServerEvent('inventory:server:SetIsOpenState', false, type, id)
end
elseif type == "drop" then
if name ~= CurrentDrop or CurrentDrop == nil then
TriggerServerEvent('inventory:server:SetIsOpenState', false, type, id)
end
end
end)
RegisterNetEvent('inventory:client:ItemBox', function(itemData, type, amount)
amount = amount or 1
SendNUIMessage({
action = "itemBox",
item = itemData,
type = type,
itemAmount = amount
})
end)
RegisterNetEvent('inventory:client:requiredItems', function(items, bool)
local itemTable = {}
if bool then
for k in pairs(items) do
itemTable[#itemTable+1] = {
item = items[k].name,
label = QBCore.Shared.Items[items[k].name]["label"],
image = items[k].image,
}
end
end
SendNUIMessage({
action = "requiredItem",
items = itemTable,
toggle = bool
})
end)
RegisterNetEvent('inventory:server:RobPlayer', function(TargetId)
SendNUIMessage({
action = "RobMoney",
TargetId = TargetId,
})
end)
RegisterNetEvent('inventory:client:OpenInventory', function(PlayerAmmo, inventory, other)
if not IsEntityDead(PlayerPedId()) then
if Config.Progressbar.Enable then
QBCore.Functions.Progressbar('open_inventory', 'Opening Inventory...', math.random(Config.Progressbar.minT, Config.Progressbar.maxT), false, true, { -- Name | Label | Time | useWhileDead | canCancel
disableMovement = false,
disableCarMovement = false,
disableMouse = false,
disableCombat = false,
}, {}, {}, {}, function() -- Play When Done
ToggleHotbar(false)
if showBlur == true then
TriggerScreenblurFadeIn(1000)
end
SetNuiFocus(true, true)
if other then
currentOtherInventory = other.name
end
QBCore.Functions.TriggerCallback('inventory:server:ConvertQuality', function(data)
inventory = data.inventory
other = data.other
SendNUIMessage({
action = "open",
inventory = inventory,
slots = Config.MaxInventorySlots,
other = other,
maxweight = Config.MaxInventoryWeight,
Ammo = PlayerAmmo,
maxammo = Config.MaximumAmmoValues,
Name = PlayerData.charinfo.firstname .." ".. PlayerData.charinfo.lastname .." - [".. GetPlayerServerId(PlayerId()) .."]",
pName = PlayerData.charinfo.firstname .. PlayerData.charinfo.lastname,
pNumber = PlayerData.charinfo.phone,
pCID = PlayerData.citizenid,
pID = GetPlayerServerId(PlayerId()),
pStress = stress,
pDamage = 200 - GetEntityHealth(PlayerPedId()),
})
inInventory = true
end, inventory, other)
end)
else
Wait(500)
ToggleHotbar(false)
if showBlur == true then
TriggerScreenblurFadeIn(1000)
end
SetNuiFocus(true, true)
if other then
currentOtherInventory = other.name
end
QBCore.Functions.TriggerCallback('inventory:server:ConvertQuality', function(data)
inventory = data.inventory
other = data.other
SendNUIMessage({
action = "open",
inventory = inventory,
slots = Config.MaxInventorySlots,
other = other,
maxweight = Config.MaxInventoryWeight,
Ammo = PlayerAmmo,
maxammo = Config.MaximumAmmoValues,
Name = PlayerData.charinfo.firstname .." ".. PlayerData.charinfo.lastname .." - [".. GetPlayerServerId(PlayerId()) .."]",
pName = PlayerData.charinfo.firstname .. PlayerData.charinfo.lastname,
pNumber = PlayerData.charinfo.phone,
pCID = PlayerData.citizenid,
pID = GetPlayerServerId(PlayerId()),
pStress = stress,
pDamage = 200 - GetEntityHealth(PlayerPedId()),
})
inInventory = true
end,inventory,other)
end
end
end)
RegisterNetEvent('inventory:client:UpdateOtherInventory', function(items, isError)
SendNUIMessage({
action = "update",
inventory = items,
maxweight = Config.MaxInventoryWeight,
slots = Config.MaxInventorySlots,
error = isError,
})
end)
RegisterNetEvent('inventory:client:UpdatePlayerInventory', function(isError)
SendNUIMessage({
action = "update",
inventory = PlayerData.items,
maxweight = Config.MaxInventoryWeight,
slots = Config.MaxInventorySlots,
error = isError,
})
end)
RegisterNetEvent('inventory:client:CraftItems', function(itemName, itemCosts, amount, toSlot, points)
local ped = PlayerPedId()
SendNUIMessage({
action = "close",
})
isCrafting = true
QBCore.Functions.Progressbar("repair_vehicle", "Crafting..", (math.random(2000, 5000) * amount), false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
animDict = "mini@repair",
anim = "fixing_a_player",
flags = 16,
}, {}, {}, function() -- Done
StopAnimTask(ped, "mini@repair", "fixing_a_player", 1.0)
TriggerServerEvent("inventory:server:CraftItems", itemName, itemCosts, amount, toSlot, points)
TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items[itemName], 'add')
isCrafting = false
end, function() -- Cancel
StopAnimTask(ped, "mini@repair", "fixing_a_player", 1.0)
QBCore.Functions.Notify("Failed", "error")
isCrafting = false
end)
end)
RegisterNetEvent('inventory:client:CraftAttachment', function(itemName, itemCosts, amount, toSlot, points)
local ped = PlayerPedId()
SendNUIMessage({
action = "close",
})
isCrafting = true
QBCore.Functions.Progressbar("repair_vehicle", "Crafting..", (math.random(2000, 5000) * amount), false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
animDict = "mini@repair",
anim = "fixing_a_player",
flags = 16,
}, {}, {}, function() -- Done
StopAnimTask(ped, "mini@repair", "fixing_a_player", 1.0)
TriggerServerEvent("inventory:server:CraftAttachment", itemName, itemCosts, amount, toSlot, points)
TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items[itemName], 'add')
isCrafting = false
end, function() -- Cancel
StopAnimTask(ped, "mini@repair", "fixing_a_player", 1.0)
QBCore.Functions.Notify("Failed", "error")
isCrafting = false
end)
end)
RegisterNetEvent('inventory:client:PickupSnowballs', function()
local ped = PlayerPedId()
LoadAnimDict('anim@mp_snowball')
TaskPlayAnim(ped, 'anim@mp_snowball', 'pickup_snowball', 3.0, 3.0, -1, 0, 1, 0, 0, 0)
QBCore.Functions.Progressbar("pickupsnowball", "Collecting snowballs..", 1500, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {}, {}, {}, function() -- Done
ClearPedTasks(ped)
TriggerServerEvent('inventory:server:snowball', 'add')
TriggerEvent('inventory:client:ItemBox', QBCore.Shared.Items["snowball"], "add")
end, function() -- Cancel
ClearPedTasks(ped)
QBCore.Functions.Notify("Canceled", "error")
end)
end)
RegisterNetEvent('inventory:client:UseSnowball', function(amount)
local ped = PlayerPedId()
GiveWeaponToPed(ped, `weapon_snowball`, amount, false, false)
SetPedAmmo(ped, `weapon_snowball`, amount)
SetCurrentPedWeapon(ped, `weapon_snowball`, true)
end)
RegisterNetEvent('inventory:client:UseWeapon', function(weaponData, shootbool)
local ped = PlayerPedId()
local weaponName = tostring(weaponData.name)
local weaponHash = joaat(weaponData.name)
local weaponinhand = GetCurrentPedWeapon(PlayerPedId())
if currentWeapon == weaponName and weaponinhand then
TriggerEvent('weapons:client:DrawWeapon', nil)
SetCurrentPedWeapon(ped, `WEAPON_UNARMED`, true)
RemoveAllPedWeapons(ped, true)
TriggerEvent('weapons:client:SetCurrentWeapon', nil, shootbool)
currentWeapon = nil
elseif weaponName == "weapon_stickybomb" or weaponName == "weapon_pipebomb" or weaponName == "weapon_smokegrenade" or weaponName == "weapon_flare" or weaponName == "weapon_proxmine" or weaponName == "weapon_ball" or weaponName == "weapon_molotov" or weaponName == "weapon_grenade" or weaponName == "weapon_bzgas" then
TriggerEvent('weapons:client:DrawWeapon', weaponName)
GiveWeaponToPed(ped, weaponHash, 1, false, false)
SetPedAmmo(ped, weaponHash, 1)
SetCurrentPedWeapon(ped, weaponHash, true)
TriggerEvent('weapons:client:SetCurrentWeapon', weaponData, shootbool)
currentWeapon = weaponName
elseif weaponName == "weapon_snowball" then
TriggerEvent('weapons:client:DrawWeapon', weaponName)
GiveWeaponToPed(ped, weaponHash, 10, false, false)
SetPedAmmo(ped, weaponHash, 10)
SetCurrentPedWeapon(ped, weaponHash, true)
TriggerServerEvent('inventory:server:snowball', 'remove')
TriggerEvent('weapons:client:SetCurrentWeapon', weaponData, shootbool)
currentWeapon = weaponName
else
TriggerEvent('weapons:client:DrawWeapon', weaponName)
TriggerEvent('weapons:client:SetCurrentWeapon', weaponData, shootbool)
local ammo = tonumber(weaponData.info.ammo) or 0
if weaponName == "weapon_fireextinguisher" then
ammo = 4000
end
GiveWeaponToPed(ped, weaponHash, ammo, false, false)
SetPedAmmo(ped, weaponHash, ammo)
SetCurrentPedWeapon(ped, weaponHash, true)
if weaponData.info.attachments then
for _, attachment in pairs(weaponData.info.attachments) do
GiveWeaponComponentToPed(ped, weaponHash, joaat(attachment.component))
end
end
currentWeapon = weaponName
end
end)
RegisterNetEvent('inventory:client:CheckWeapon', function(weaponName)
if currentWeapon ~= weaponName:lower() then return end
local ped = PlayerPedId()
TriggerEvent('weapons:ResetHolster')
SetCurrentPedWeapon(ped, `WEAPON_UNARMED`, true)
RemoveAllPedWeapons(ped, true)
currentWeapon = nil
end)
RegisterNetEvent('inventory:client:AddDropItem', function(dropId, player, coords)
local forward = GetEntityForwardVector(GetPlayerPed(GetPlayerFromServerId(player)))
local x, y, z = table.unpack(coords + forward * 0.5)
Drops[dropId] = {
id = dropId,
coords = {
x = x,
y = y,
z = z - 0.3,
},
}
end)
RegisterNetEvent('inventory:client:RemoveDropItem', function(dropId)
Drops[dropId] = nil
if Config.UseItemDrop then
RemoveNearbyDrop(dropId)
else
DropsNear[dropId] = nil
end
end)
RegisterNetEvent('inventory:client:DropItemAnim', function()
local ped = PlayerPedId()
SendNUIMessage({
action = "close",
})
RequestAnimDict("pickup_object")
while not HasAnimDictLoaded("pickup_object") do
Wait(7)
end
TaskPlayAnim(ped, "pickup_object" ,"pickup_low" ,8.0, -8.0, -1, 1, 0, false, false, false )
Wait(2000)
ClearPedTasks(ped)
end)
RegisterNetEvent('inventory:client:SetCurrentStash', function(stash)
CurrentStash = stash
end)
RegisterNetEvent('inventory:client:craftTarget',function()
local crafting = {}
crafting.label = "Crafting"
crafting.items = GetThresholdItems()
TriggerServerEvent("inventory:server:OpenInventory", "crafting", math.random(1, 99), crafting)
end)
-- Commands
RegisterCommand('closeinv', function()
closeInventory()
end, false)
RegisterNetEvent("ps-inventory:client:closeinv", function()
closeInventory()
end)
RegisterCommand('inventory', function()
if IsNuiFocused() then return end
if not isCrafting and not inInventory then
if not PlayerData.metadata["isdead"] and not PlayerData.metadata["inlaststand"] and not PlayerData.metadata["ishandcuffed"] and not IsPauseMenuActive() then
local ped = PlayerPedId()
local curVeh = nil
local VendingMachine = nil
if not Config.UseTarget then VendingMachine = GetClosestVending() end
if IsPedInAnyVehicle(ped, false) then -- Is Player In Vehicle
local vehicle = GetVehiclePedIsIn(ped, false)
CurrentGlovebox = QBCore.Functions.GetPlate(vehicle)
curVeh = vehicle
CurrentVehicle = nil
else
local vehicle = QBCore.Functions.GetClosestVehicle()
if vehicle ~= 0 and vehicle ~= nil then
local pos = GetEntityCoords(ped)
local dimensionMin, dimensionMax = GetModelDimensions(GetEntityModel(vehicle))
local trunkpos = GetOffsetFromEntityInWorldCoords(vehicle, 0.0, (dimensionMin.y), 0.0)
if (IsBackEngine(GetEntityModel(vehicle))) then
trunkpos = GetOffsetFromEntityInWorldCoords(vehicle, 0.0, (dimensionMax.y), 0.0)
end
if #(pos - trunkpos) < 1.5 and not IsPedInAnyVehicle(ped) then
if GetVehicleDoorLockStatus(vehicle) < 2 then
CurrentVehicle = QBCore.Functions.GetPlate(vehicle)
curVeh = vehicle
CurrentGlovebox = nil
else
QBCore.Functions.Notify("Vehicle locked.", "error")
return
end
else
CurrentVehicle = nil
end
else
CurrentVehicle = nil
end
end
if CurrentVehicle then -- Trunk
local vehicleClass = GetVehicleClass(curVeh)
local maxweight
local slots
if vehicleClass == 0 then
maxweight = 38000
slots = 30
elseif vehicleClass == 1 then
maxweight = 50000
slots = 40
elseif vehicleClass == 2 then
maxweight = 75000
slots = 50
elseif vehicleClass == 3 then
maxweight = 42000
slots = 35
elseif vehicleClass == 4 then
maxweight = 38000
slots = 30
elseif vehicleClass == 5 then
maxweight = 30000
slots = 25
elseif vehicleClass == 6 then
maxweight = 30000
slots = 25
elseif vehicleClass == 7 then
maxweight = 30000
slots = 25
elseif vehicleClass == 8 then
maxweight = 15000
slots = 15
elseif vehicleClass == 9 then
maxweight = 60000
slots = 35
elseif vehicleClass == 12 then
maxweight = 120000
slots = 35
elseif vehicleClass == 13 then
maxweight = 0
slots = 0
elseif vehicleClass == 14 then
maxweight = 120000
slots = 50
elseif vehicleClass == 15 then
maxweight = 120000
slots = 50
elseif vehicleClass == 16 then
maxweight = 120000
slots = 50
else
maxweight = 60000
slots = 35
end
local other = {
maxweight = maxweight,
slots = slots,
}
TriggerServerEvent("inventory:server:OpenInventory", "trunk", CurrentVehicle, other)
OpenTrunk()
elseif CurrentGlovebox then
TriggerServerEvent("inventory:server:OpenInventory", "glovebox", CurrentGlovebox)
elseif CurrentDrop ~= 0 then
TriggerServerEvent("inventory:server:OpenInventory", "drop", CurrentDrop)
elseif VendingMachine then
local ShopItems = {}
ShopItems.label = "Vending Machine"
ShopItems.items = Config.VendingItem
ShopItems.slots = #Config.VendingItem
TriggerServerEvent("inventory:server:OpenInventory", "shop", "Vendingshop_"..math.random(1, 99), ShopItems)
else
openAnim()
TriggerServerEvent("inventory:server:OpenInventory")
end
end
end
end, false)
RegisterKeyMapping('inventory', 'Open Inventory', 'keyboard', 'TAB')
RegisterCommand('hotbar', function()
isHotbar = not isHotbar
if not PlayerData.metadata["isdead"] and not PlayerData.metadata["inlaststand"] and not PlayerData.metadata["ishandcuffed"] and not IsPauseMenuActive() then
ToggleHotbar(isHotbar)
end
end)
RegisterKeyMapping('hotbar', 'Toggles keybind slots', 'keyboard', 'z')
for i = 1, 6 do
RegisterCommand('slot' .. i,function()
if not PlayerData.metadata["isdead"] and not PlayerData.metadata["inlaststand"] and not PlayerData.metadata["ishandcuffed"] and not IsPauseMenuActive() and not LocalPlayer.state.inv_busy then
if i == 6 then
i = Config.MaxInventorySlots
end
TriggerServerEvent("inventory:server:UseItemSlot", i)
end
end, false)
RegisterKeyMapping('slot' .. i, 'Uses the item in slot ' .. i, 'keyboard', i)
end
RegisterNetEvent('ps-inventory:client:giveAnim', function()
LoadAnimDict('mp_common')
TaskPlayAnim(PlayerPedId(), 'mp_common', 'givetake1_b', 8.0, 1.0, -1, 16, 0, 0, 0, 0)
end)
-- NUI
RegisterNUICallback('RobMoney', function(data, cb)
TriggerServerEvent("police:server:RobPlayer", data.TargetId)
cb('ok')
end)
RegisterNUICallback('Notify', function(data, cb)
QBCore.Functions.Notify(data.message, data.type)
cb('ok')
end)
RegisterNUICallback('GetWeaponData', function(cData, cb)
local data = {
WeaponData = QBCore.Shared.Items[cData.weapon],
AttachmentData = FormatWeaponAttachments(cData.ItemData)
}
cb(data)
end)
RegisterNUICallback('RemoveAttachment', function(data, cb)
local ped = PlayerPedId()
local WeaponData = QBCore.Shared.Items[data.WeaponData.name]
print(data.AttachmentData.attachment:gsub("(.*).*_",''))
data.AttachmentData.attachment = data.AttachmentData.attachment:gsub("(.*).*_",'')
QBCore.Functions.TriggerCallback('weapons:server:RemoveAttachment', function(NewAttachments)
if NewAttachments ~= false then
local attachments = {}
RemoveWeaponComponentFromPed(ped, GetHashKey(data.WeaponData.name), GetHashKey(data.AttachmentData.component))
for _, v in pairs(NewAttachments) do
attachments[#attachments+1] = {
attachment = v.item,
label = v.label,
image = QBCore.Shared.Items[v.item].image
}
end
local DJATA = {
Attachments = attachments,
WeaponData = WeaponData,
}
cb(DJATA)
else
RemoveWeaponComponentFromPed(ped, GetHashKey(data.WeaponData.name), GetHashKey(data.AttachmentData.component))
cb({})
end
end, data.AttachmentData, data.WeaponData)
end)
RegisterNUICallback('getCombineItem', function(data, cb)
cb(QBCore.Shared.Items[data.item])
end)
RegisterNUICallback("CloseInventory", function()
if currentOtherInventory == "none-inv" then
CurrentDrop = nil
CurrentVehicle = nil
CurrentGlovebox = nil
CurrentStash = nil
SetNuiFocus(false, false)
inInventory = false
TriggerScreenblurFadeOut(1000)
ClearPedTasks(PlayerPedId())
return
end
if CurrentVehicle ~= nil then
CloseTrunk()
TriggerServerEvent("inventory:server:SaveInventory", "trunk", CurrentVehicle)
CurrentVehicle = nil
elseif CurrentGlovebox ~= nil then
TriggerServerEvent("inventory:server:SaveInventory", "glovebox", CurrentGlovebox)
CurrentGlovebox = nil
elseif CurrentStash ~= nil then
TriggerServerEvent("inventory:server:SaveInventory", "stash", CurrentStash)
CurrentStash = nil
else
TriggerServerEvent("inventory:server:SaveInventory", "drop", CurrentDrop)
CurrentDrop = nil
end
Wait(50)
TriggerScreenblurFadeOut(1000)
SetNuiFocus(false, false)
inInventory = false
end)
RegisterNUICallback("UseItem", function(data, cb)
TriggerServerEvent("inventory:server:UseItem", data.inventory, data.item)
cb('ok')
end)
RegisterNUICallback("combineItem", function(data, cb)
Wait(150)
TriggerServerEvent('inventory:server:combineItem', data.reward, data.fromItem, data.toItem)
cb('ok')
end)
RegisterNUICallback('combineWithAnim', function(data, cb)
local ped = PlayerPedId()
local combineData = data.combineData
local aDict = combineData.anim.dict
local aLib = combineData.anim.lib
local animText = combineData.anim.text
local animTimeout = combineData.anim.timeOut
QBCore.Functions.Progressbar("combine_anim", animText, animTimeout, false, true, {
disableMovement = false,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
animDict = aDict,
anim = aLib,
flags = 16,
}, {}, {}, function() -- Done
StopAnimTask(ped, aDict, aLib, 1.0)
TriggerServerEvent('inventory:server:combineItem', combineData.reward, data.requiredItem, data.usedItem)
end, function() -- Cancel
StopAnimTask(ped, aDict, aLib, 1.0)
QBCore.Functions.Notify("Failed", "error")
end)
cb('ok')
end)
RegisterNUICallback("SetInventoryData", function(data, cb)
TriggerServerEvent("inventory:server:SetInventoryData", data.fromInventory, data.toInventory, data.fromSlot, data.toSlot, data.fromAmount, data.toAmount)
cb('ok')
end)
RegisterNUICallback("PlayDropSound", function(_, cb)
PlaySound(-1, "CLICK_BACK", "WEB_NAVIGATION_SOUNDS_PHONE", 0, 0, 1)
cb('ok')