Weapon gets removed from hand

Hello everyone, I am having this issue where my weapon dissapears from my hand whenever I have no more bullets left.
I add a weapon to my hand like this:

GiveWeaponToPed(PlayerPedId(), GetHashKey("WEAPON_PISTOL"), 12, false, true)

Then I waste all of the bullets and the weapon simple just dissapears from hy hand. What I would like to happen is that the weapon stays in my hand but I am not sure if this is even possible.

Does anyone have a solution for this? Thank you in advance!

1 Like

You might be able to stop it from switching to your hands after you run out of ammo by using the GetAmmoInPedWeapon function with the GetCurrentPedWeapon function. Then using an if statement so when the ammo in the gun reaches 0 either using the SetPedCanSwitchWeapon to false and then back to true or deleting and re-spawning a gun with no ammo into the player’s hands.
I don’t know for sure this will work, but maybe this will help point you in the right direction.

1 Like

I fixed it partly. Once I have no more bullets in the clip I remove the weapon from my hand and wait 1 frame before adding it back to my hand again using the RemoveWeaponFromPed and GiveWeaponToPed function.

So now I can hold my weapon in my hand even when it is empty but this does not work when you enter a vehicle! :frowning:

When you enter a vehicle with a weapon that has no ammo the weapon still dissapears from your hand, any solutions for this?

1 Like

Yes. I believe when you are in a vehicle, you need to use GetCurrentPedVehicleWeapon instead of theGetCurrentPedWeapon function. You have to use this different function because GTA treats the guns in the car differently then guns in your hands. Note using this function would also affect things like car-mounted machine guns and rocket launchers unless you excepted them.

Anyone got a solution for what you can do?

I ended up realizing that it only auto stores the weapon if there is literally zero ammo in the gun at all, meaning in the clip… or in GTAs imaginary magazine store that each weapon has.

So all I needed to do was ensure there was at least 1 bullet left (not in the magazine, but the weapon itself using SetPedAmmo) and the weapon stays out when the current magazine empties.

Could you show me how you added this

Using the SetPedAmmo native.

Just recently a new native was added also that sounds very applicable to this scenario:

SET_WEAPONS_NO_AUTORELOAD

See: feat(extra-natives-five): SET_WEAPONS_NO_AUTORELOAD · citizenfx/fivem@de1d7c5 · GitHub

… except in this case you’d probably want the AUTOSWAP native instead. :stuck_out_tongue:

1 Like

Ah yes, that is the one I was looking for lol

Hi! Is this native works? Need to call a thread?

Thank you for answers.