Skip to content

Commit

Permalink
fix: janky disarm function
Browse files Browse the repository at this point in the history
At one point, that -1 was useful (I swear).
  • Loading branch information
thelindat committed Dec 30, 2021
1 parent 200ce8a commit 90898e1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ local function useSlot(slot)
local playerPed = PlayerData.ped
if data.throwable then item.throwable = true end
ClearPedSecondaryTask(playerPed)
if currentWeapon then Utils.Disarm(currentWeapon, data.slot) end
if currentWeapon then Utils.Disarm(currentWeapon) end
local sleep = (PlayerData.job.name == ox.police and (GetWeapontypeGroup(data.hash) == 416676503 or GetWeapontypeGroup(data.hash) == 690389602)) and 400 or 1200
local coords = GetEntityCoords(playerPed, true)
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)
Expand Down Expand Up @@ -369,7 +369,7 @@ function OnPlayerData(key, val)
end
table.wipe(nearbyMarkers)
elseif key == 'dead' and val then
Utils.Disarm(currentWeapon, -1)
Utils.Disarm(currentWeapon)
TriggerEvent('ox_inventory:closeInventory')
Wait(50)
end
Expand Down Expand Up @@ -569,7 +569,7 @@ end)
RegisterNetEvent('ox_inventory:createDrop', function(data, owner, slot)
drops[data[1]] = data[2]
if owner == PlayerData.id and invOpen and #(GetEntityCoords(PlayerData.ped) - data[2]) <= 1 then
if currentWeapon?.slot == slot then Utils.Disarm(currentWeapon, -1) end
if currentWeapon?.slot == slot then Utils.Disarm(currentWeapon) end
if not IsPedInAnyVehicle(PlayerData.ped, false) then
OpenInventory('drop', data[1])
else
Expand Down Expand Up @@ -717,7 +717,7 @@ RegisterNetEvent('ox_inventory:setPlayerInventory', function(currentDrops, inven
end
end

if currentWeapon and GetSelectedPedWeapon(PlayerData.ped) ~= currentWeapon.hash then Utils.Disarm(currentWeapon, -1) end
if currentWeapon and GetSelectedPedWeapon(PlayerData.ped) ~= currentWeapon.hash then Utils.Disarm(currentWeapon) end
if ox.parachute and GetPedParachuteState(PlayerData.ped) ~= -1 then Utils.DeleteObject(ox.parachute) ox.parachute = false end
end, 200)

Expand Down Expand Up @@ -833,7 +833,7 @@ RegisterNetEvent('esx:onPlayerLogout', function()
PlayerData.loaded = false
ClearInterval(interval)
ClearInterval(tick)
Utils.Disarm(currentWeapon, -1)
Utils.Disarm(currentWeapon)
end)

RegisterNetEvent('ox_inventory:viewInventory', function(data)
Expand Down Expand Up @@ -911,7 +911,7 @@ RegisterNUICallback('giveItem', function(data, cb)
else return end
if passenger then
TriggerServerEvent('ox_inventory:giveItem', data.slot, passenger, data.count)
if data.slot == currentWeapon?.slot then Utils.Disarm(currentWeapon, -1) end
if data.slot == currentWeapon?.slot then Utils.Disarm(currentWeapon) end
end
end
else
Expand All @@ -920,7 +920,7 @@ RegisterNUICallback('giveItem', function(data, cb)
target = GetPlayerServerId(NetworkGetPlayerIndexFromPed(target))
Utils.PlayAnim(2000, 'mp_common', 'givetake1_a', 1.0, 1.0, -1, 50, 0.0, 0, 0, 0)
TriggerServerEvent('ox_inventory:giveItem', data.slot, target, data.count)
if data.slot == currentWeapon?.slot then Utils.Disarm(currentWeapon, -1) end
if data.slot == currentWeapon?.slot then Utils.Disarm(currentWeapon) end
end
end
end)
Expand Down
2 changes: 1 addition & 1 deletion modules/player/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ do
PlayerData.cuffed = not PlayerData.cuffed
LocalPlayer.state:set('busy', PlayerData.cuffed, false)
if PlayerData.cuffed then
Utils.Disarm(currentWeapon, -1)
Utils.Disarm(currentWeapon)
if invOpen then TriggerEvent('ox_inventory:closeInventory') end
end
end)
Expand Down
6 changes: 3 additions & 3 deletions modules/utils/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function Utils.Disarm(currentWeapon, newSlot)
local ammo = currentWeapon.ammo and GetAmmoInPedWeapon(PlayerData.ped, currentWeapon.hash)
SetPedAmmo(PlayerData.ped, currentWeapon.hash, 0)

if newSlot ~= -1 then
if not newSlot then
ClearPedSecondaryTask(PlayerData.ped)
local sleep = (PlayerData.job.name == ox.police and (GetWeapontypeGroup(currentWeapon.hash) == 416676503 or GetWeapontypeGroup(currentWeapon.hash) == 690389602)) and 450 or 1400
local coords = GetEntityCoords(PlayerData.ped, true)
Expand All @@ -78,7 +78,7 @@ function Utils.Disarm(currentWeapon, newSlot)

RemoveWeaponFromPed(PlayerData.ped, currentWeapon.hash)

if newSlot ~= false then
if newSlot then
TriggerServerEvent('ox_inventory:updateWeapon', ammo and 'ammo' or 'melee', ammo or currentWeapon.melee, newSlot)
end

Expand All @@ -87,7 +87,7 @@ function Utils.Disarm(currentWeapon, newSlot)
end

function Utils.ClearWeapons(currentWeapon)
Utils.Disarm(currentWeapon, -1)
Utils.Disarm(currentWeapon)
RemoveAllPedWeapons(PlayerData.ped, true)
if ox.parachute then
local chute = `GADGET_PARACHUTE`
Expand Down
2 changes: 1 addition & 1 deletion server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ ServerCallback.Register('swapItems', function(source, cb, data)
fromInventory.weapon = data.toSlot
fromInventory.weapon = data.fromSlot
if fromInventory.type == 'otherplayer' then movedWeapon = false end
TriggerClientEvent('ox_inventory:disarm', fromInventory.id, -1)
TriggerClientEvent('ox_inventory:disarm', fromInventory.id)
end

if toData and ((toData.name ~= fromData.name) or not toData.stack or (not table.matches(toData.metadata, fromData.metadata))) then
Expand Down

0 comments on commit 90898e1

Please sign in to comment.