@@ -5,17 +5,13 @@ local Utils = client.utils
55local currentWeapon
66
77RegisterNetEvent (' ox_inventory:disarm' , function (newSlot )
8- Utils .Disarm (currentWeapon , newSlot )
8+ currentWeapon = Utils .Disarm (currentWeapon , newSlot )
99end )
1010
1111RegisterNetEvent (' ox_inventory:clearWeapons' , function ()
1212 Utils .ClearWeapons (currentWeapon )
1313end )
1414
15- AddEventHandler (' ox_inventory:currentWeapon' , function (weapon )
16- currentWeapon = weapon
17- end )
18-
1915local StashTarget
2016exports (' setStashTarget' , function (id , owner )
2117 StashTarget = id and {id = id , owner = owner }
@@ -232,13 +228,14 @@ local function useSlot(slot)
232228 useItem (data , function (result )
233229 if result then
234230 if currentWeapon ?.slot == result .slot then
235- return Utils .Disarm (currentWeapon )
231+ currentWeapon = Utils .Disarm (currentWeapon )
232+ return
236233 end
237234
238235 local playerPed = PlayerData .ped
239236 ClearPedSecondaryTask (playerPed )
240237 if data .throwable then item .throwable = true end
241- if currentWeapon then Utils .Disarm (currentWeapon ) end
238+ if currentWeapon then currentWeapon = Utils .Disarm (currentWeapon ) end
242239 local sleep = (PlayerData .job .name == ox .police and (GetWeapontypeGroup (data .hash ) == 416676503 or GetWeapontypeGroup (data .hash ) == 690389602 )) and 400 or 1200
243240 local coords = GetEntityCoords (playerPed , true )
244241 Utils .PlayAnimAdvanced (sleep * 2 , sleep == 400 and ' reaction@intimidation@cop@unarmed' or ' reaction@intimidation@1h' , ' intro' , coords .x , coords .y , coords .z , 0 , 0 , GetEntityHeading (playerPed ), 8.0 , 3.0 , - 1 , 50 , 0.1 )
@@ -277,6 +274,7 @@ local function useSlot(slot)
277274 SetPedInfiniteAmmo (playerPed , true , data .hash )
278275 end
279276
277+ currentWeapon = item
280278 TriggerEvent (' ox_inventory:currentWeapon' , item )
281279 Utils .ItemNotify ({item .label , item .name , ox .locale (' equipped' )})
282280 Wait (sleep )
@@ -392,7 +390,7 @@ function OnPlayerData(key, val)
392390 end
393391 table .wipe (nearbyMarkers )
394392 elseif key == ' dead' and val then
395- Utils .Disarm (currentWeapon )
393+ currentWeapon = Utils .Disarm (currentWeapon )
396394 TriggerEvent (' ox_inventory:closeInventory' )
397395 Wait (50 )
398396 end
587585
588586RegisterNetEvent (' ox_inventory:inventoryReturned' , function (data )
589587 Utils .Notify ({text = ox .locale (' items_returned' ), duration = 2500 })
590- if currentWeapon then Utils .Disarm (currentWeapon ) end
588+ if currentWeapon then currentWeapon = Utils .Disarm (currentWeapon ) end
591589 TriggerEvent (' ox_inventory:closeInventory' )
592590 PlayerData .inventory = data [1 ]
593591 ox .SetPlayerData (' inventory' , data [1 ])
596594
597595RegisterNetEvent (' ox_inventory:inventoryConfiscated' , function (message )
598596 if message then Utils .Notify ({text = ox .locale (' items_confiscated' ), duration = 2500 }) end
599- if currentWeapon then Utils .Disarm (currentWeapon ) end
597+ if currentWeapon then currentWeapon = Utils .Disarm (currentWeapon ) end
600598 TriggerEvent (' ox_inventory:closeInventory' )
601599 table .wipe (PlayerData .inventory )
602600 ox .SetPlayerData (' weight' , 0 )
605603RegisterNetEvent (' ox_inventory:createDrop' , function (data , owner , slot )
606604 drops [data [1 ]] = data [2 ]
607605 if owner == PlayerData .id and invOpen and # (GetEntityCoords (PlayerData .ped ) - data [2 ]) <= 1 then
608- if currentWeapon ?.slot == slot then Utils .Disarm (currentWeapon ) end
606+ if currentWeapon ?.slot == slot then currentWeapon = Utils .Disarm (currentWeapon ) end
609607
610608 if not IsPedInAnyVehicle (PlayerData .ped , false ) then
611609 OpenInventory (' drop' , data [1 ])
@@ -758,7 +756,7 @@ RegisterNetEvent('ox_inventory:setPlayerInventory', function(currentDrops, inven
758756 end
759757 end
760758
761- if currentWeapon and GetSelectedPedWeapon (PlayerData .ped ) ~= currentWeapon .hash then Utils .Disarm (currentWeapon ) end
759+ if currentWeapon and GetSelectedPedWeapon (PlayerData .ped ) ~= currentWeapon .hash then currentWeapon = Utils .Disarm (currentWeapon ) end
762760 if ox .parachute and GetPedParachuteState (PlayerData .ped ) ~= - 1 then
763761 Utils .DeleteObject (ox .parachute )
764762 ox .parachute = false
@@ -806,13 +804,13 @@ RegisterNetEvent('ox_inventory:setPlayerInventory', function(currentDrops, inven
806804 DisableControlAction (0 , 140 , true )
807805
808806 if not invBusy and currentWeapon .timer ~= 0 and currentWeapon .timer < GetGameTimer () then
807+ currentWeapon .timer = 0
809808 if currentWeapon .metadata .ammo then
810809 TriggerServerEvent (' ox_inventory:updateWeapon' , ' ammo' , currentWeapon .metadata .ammo )
811810 elseif currentWeapon .metadata .durability then
812811 TriggerServerEvent (' ox_inventory:updateWeapon' , ' melee' , currentWeapon .melee )
813812 currentWeapon .melee = 0
814813 end
815- currentWeapon .timer = 0
816814 elseif currentWeapon .metadata .ammo then
817815 local playerPed = PlayerData .ped
818816 if IsPedShooting (playerPed ) then
@@ -832,18 +830,16 @@ RegisterNetEvent('ox_inventory:setPlayerInventory', function(currentDrops, inven
832830 ClearPedTasks (playerPed )
833831 SetCurrentPedWeapon (playerPed , currentWeapon .hash , true )
834832 SetPedCurrentWeaponVisible (playerPed , true , false , false , false )
835- if currentWeapon ?.ammo and ox .autoreload and not Interface .ProgressActive and not IsPedRagdoll (playerPed ) and not IsPedFalling (playerPed ) and currentWeapon .durability > 0 then
833+ if currentWeapon ?.ammo and ox .autoreload and not Interface .ProgressActive and not IsPedRagdoll (playerPed ) and not IsPedFalling (playerPed ) then
834+ currentWeapon .timer = 0
836835 local ammo = Inventory .Search (1 , currentWeapon .ammo )
837836
838837 if ammo [1 ] then
839838 TriggerServerEvent (' ox_inventory:updateWeapon' , ' ammo' , currentWeapon .metadata .ammo )
840- currentWeapon .timer = 0
841839 useSlot (ammo [1 ].slot )
842840 end
843-
844- end
845- end
846- currentWeapon .timer = GetGameTimer () + 400
841+ else currentWeapon .timer = GetGameTimer () + 400 end
842+ else currentWeapon .timer = GetGameTimer () + 400 end
847843 end
848844 elseif IsControlJustReleased (0 , 24 ) then
849845 if currentWeapon .throwable then
@@ -854,6 +850,7 @@ RegisterNetEvent('ox_inventory:setPlayerInventory', function(currentDrops, inven
854850 ClearPedSecondaryTask (playerPed )
855851 RemoveWeaponFromPed (playerPed , currentWeapon .hash )
856852 TriggerServerEvent (' ox_inventory:updateWeapon' , ' throw' )
853+ currentWeapon = nil
857854 TriggerEvent (' ox_inventory:currentWeapon' )
858855 plyState .invBusy = false
859856 end )
@@ -894,7 +891,7 @@ RegisterNetEvent('esx:onPlayerLogout', function()
894891 PlayerData .loaded = false
895892 ClearInterval (interval )
896893 ClearInterval (tick )
897- Utils .Disarm (currentWeapon )
894+ currentWeapon = Utils .Disarm (currentWeapon )
898895end )
899896
900897RegisterNetEvent (' ox_inventory:viewInventory' , function (data )
@@ -975,7 +972,7 @@ RegisterNUICallback('giveItem', function(data, cb)
975972 else return end
976973 if passenger then
977974 TriggerServerEvent (' ox_inventory:giveItem' , data .slot , passenger , data .count )
978- if data .slot == currentWeapon ?.slot then Utils .Disarm (currentWeapon ) end
975+ if data .slot == currentWeapon ?.slot then currentWeapon = Utils .Disarm (currentWeapon ) end
979976 end
980977 end
981978 else
@@ -984,7 +981,7 @@ RegisterNUICallback('giveItem', function(data, cb)
984981 target = GetPlayerServerId (NetworkGetPlayerIndexFromPed (target ))
985982 Utils .PlayAnim (2000 , ' mp_common' , ' givetake1_a' , 1.0 , 1.0 , - 1 , 50 , 0.0 , 0 , 0 , 0 )
986983 TriggerServerEvent (' ox_inventory:giveItem' , data .slot , target , data .count )
987- if data .slot == currentWeapon ?.slot then Utils .Disarm (currentWeapon ) end
984+ if data .slot == currentWeapon ?.slot then currentWeapon = Utils .Disarm (currentWeapon ) end
988985 end
989986 end
990987end )
0 commit comments