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:
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!
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.
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!
When you enter a vehicle with a weapon that has no ammo the weapon still dissapears from your hand, any solutions for this?
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.
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.