GetAmmoInClip and fix 'Auto-Reload' when switching weapons

So how can I get amount of ammo in clip when weapon not selected (not in hands but in inventory). GetAmmoInClip can only get amount when weapon is selected otherwise it will return 0. I need this to fix feature or bug which happens when you are switching weapons and it reloads clip.

2 Likes

Reviving this ancient thread to say that I’ve tried to solve the same issue to no avail: manipulating the ammo in clip always causes unpredictable ammo loss for some reason. So my approach was to force the player to fake reload with TaskReloadWeapon instead, but this task prevents moving, so I only applied it when you switch weapons fast (< 5 seconds, to only punish those who do it on purpose during pvp to skip reloading). Still searching for a better solution, ideally, force reloading while allowing movement would be the best outcome.

If people still encounter this issue, I solved it by storing the weapon ammo in clip when switching to another weapon then calling this in order:

currentAmmo = GetAmmoInPedWeapon(PlayerPedId(), weapon);
SetAmmoInClip(PlayerPedId(), weapon, {{stored_clip_count}});
SetPedAmmo(PlayerPedId(), secondaryWeapon, currentAmmo);