Hi, im wondering how to set ammo on a weapon due to SetPedAmmo not working?
Hi, SetPedAmmo works, but it only seems to increase the ammo value, not lower it.
I found this while working on my resource. In my case, I needed to save how much ammo the player had before starting an event. During the event, the player has unlimited ammo, which I do not save to the database.
After the player leaves the event, I wanted to restore their previous ammo amount. However, the game kept leaving the ammo at the maximum value from the event.
The solution I found is:
-
Save the player’s ammo amount.
-
Remove all ammo from the ped.
-
Set the ammo back to the saved value (or the one u wanted).
You can use RemoveAllPedAmmo(ped), which has the client-side hash 0x1B83C0DEEBCBB214, or use a similar native.
This allows SetPedAmmo to correctly set a lower ammo value.
SetPedAmmo only works if the ped already has the weapon, try this
GiveWeaponToPed(PlayerPedId(), `WEAPON_PISTOL`, 0, false, true)
SetPedAmmo(PlayerPedId(), `WEAPON_PISTOL`, 250)
SetAmmoInClip(PlayerPedId(), `WEAPON_PISTOL`, 12)
its an example with weapon_pistol, try it