can't shoot stun gun, when respawn
Describe the bug After firing a stun gun or atomizer and dying immediately, when I respawn, I am unable to shoot stun guns.
Framework QBox v1.18.0
Resource version ox_inventory 2.42.0
To Reproduce
- Equip a stun gun or atomizer.
- Fire the weapon.
- Immediately die after firing (e.g., by being killed or head shot).
- Respawn and attempt to use a weapon that does not use ammunition (e.g., stun gun, atomizer).
- can't shoot gun
Expected behavior After respawning, I should be able to use weapons that do not use ammunition without issues.
Additional context The issue affects only weapons that do not use ammunition (such as stun guns and atomizers). Other types of weapons that use ammunition do not seem to be affected by this bug.
test client respawn code Resurrects 1 second after death
AddEventHandler('gameEventTriggered', function(event, data)
if event == 'CEventNetworkEntityDamage' then
local victim, attacker, victimDied = data[1], data[2], data[4]
if not IsEntityAPed(victim) then return end
if NetworkGetPlayerIndexFromPed(victim) == PlayerId() then
if victimDied and IsEntityDead(victim) then
Wait(1000)
local pos = GetEntityCoords(victim, true)
NetworkResurrectLocalPlayer(pos.x, pos.y, pos.z, GetEntityHeading(victim), true, false)
ClearPedBloodDamage(victim)
SetPlayerSprint(PlayerId(), true)
ResetPedMovementClipset(victim, 0.0)
ClearPedDamageDecalByZone(victim,0,'ALL') -- DZ_Torso
ClearPedDamageDecalByZone(victim,1,'ALL') -- DZ_Head
ClearPedDamageDecalByZone(victim,2,'ALL') -- DZ_LeftArm
ClearPedDamageDecalByZone(victim,3,'ALL') -- DZ_RightArm
ClearPedDamageDecalByZone(victim,4,'ALL') -- DZ_LeftLeg
ClearPedDamageDecalByZone(victim,5,'ALL') -- DZ_RightLeg
SetEntityHealth(victim, GetEntityMaxHealth(victim))
end
end
end
end)
Cannot reproduce.
I tried various things regarding the issue where shooting doesn't work, and we researched this phenomenon extensively. It seems to occur more frequently when aimedFiring is set to true. The charge timer in the top right corner stays at 0 and does not recharge, making it impossible to shoot. Here is the sample code. It doesn't occur every time and requires several attempts to reproduce.
Resource version ox_inventory 2.43.3
Citizen.CreateThread(function()
while true do
local pedId = PlayerPedId()
if (IsPedShooting(pedId) or IsPedInMeleeCombat(pedId)) then
Wait(100)
ApplyDamageToPed(cache.ped, 300, false)
end
Wait(0)
end
end)
AddEventHandler('gameEventTriggered', function(event, data)
if event == 'CEventNetworkEntityDamage' then
local victim, attacker, victimDied = data[1], data[2], data[4]
if not IsEntityAPed(victim) then return end
if NetworkGetPlayerIndexFromPed(victim) == PlayerId() then
if victimDied and IsEntityDead(victim) then
Wait(1000)
local pos = GetEntityCoords(victim, true)
NetworkResurrectLocalPlayer(pos.x, pos.y, pos.z, GetEntityHeading(victim), true, false)
ClearPedBloodDamage(victim)
SetPlayerSprint(PlayerId(), true)
ResetPedMovementClipset(victim, 0.0)
ClearPedDamageDecalByZone(victim,0,'ALL') -- DZ_Torso
ClearPedDamageDecalByZone(victim,1,'ALL') -- DZ_Head
ClearPedDamageDecalByZone(victim,2,'ALL') -- DZ_LeftArm
ClearPedDamageDecalByZone(victim,3,'ALL') -- DZ_RightArm
ClearPedDamageDecalByZone(victim,4,'ALL') -- DZ_LeftLeg
ClearPedDamageDecalByZone(victim,5,'ALL') -- DZ_RightLeg
SetEntityHealth(victim, GetEntityMaxHealth(victim))
end
end
end
end)
I’m not sure if this is the correct fix, but the issue improved after modifying this part of setPlayerInventory in ox_inventory/client.lua
if currentWeapon then
if weaponHash ~= currentWeapon.hash and currentWeapon.timer then
local weaponCount = Items[currentWeapon.name]?.count
if weaponCount > 0 then
SetCurrentPedWeapon(playerPed, currentWeapon.hash, true)
SetAmmoInClip(playerPed, currentWeapon.hash, currentWeapon.metadata.ammo)
SetPedCurrentWeaponVisible(playerPed, true, false, false, false)
SetTimeout(0, function() RefillAmmoInstantly(playerPed) end) --here
weaponHash = GetSelectedPedWeapon(playerPed)
end
if weaponHash ~= currentWeapon.hash then
lib.print.info(('%s was forcibly unequipped (caused by game behaviour or another resource)'):format(currentWeapon.name))
currentWeapon = Weapon.Disarm(currentWeapon, true)
end
end
elseif client.weaponmismatch and not client.ignoreweapons[weaponHash] then
local weaponType = GetWeapontypeGroup(weaponHash)
if weaponType ~= 0 and weaponType ~= `GROUP_UNARMED` then
Weapon.Disarm(currentWeapon, true)
end
end
`
I added SetTimeout(0, function() RefillAmmoInstantly(playerPed) end) below SetPedCurrentWeaponVisible.
Bug in SetAmmoInClip when currentWeapon.metadata.ammo is nil
When a player enters the water while holding a stun gun, the game forces the weapon to be unequipped. However, when the player re-equips the stun gun afterward, it becomes unusable and does not fire.
This issue may be related to how ammo is handled when the weapon is removed. To fix this, SetAmmoInClip should only be executed if currentWeapon.metadata.ammo exists.
if weaponCount > 0 then
SetCurrentPedWeapon(playerPed, currentWeapon.hash, true)
if currentWeapon.metadata.ammo then
SetAmmoInClip(playerPed, currentWeapon.hash, currentWeapon.metadata.ammo)
end
SetPedCurrentWeaponVisible(playerPed, true, false, false, false)
SetTimeout(0, function() RefillAmmoInstantly(playerPed) end) --here
weaponHash = GetSelectedPedWeapon(playerPed)
end