I’m making a HUD, and I need to figure out the max amount of ammunition in a magazine to get some scaling right. I’m not creating this for some gamemode so the dynamic acquisition of the max mag. size is pretty important.
LocalPlayer():GetActiveWeapon():GetTable().Primary.ClipSize works well with SWeps, but considering the regular HL2 weapons have nothing but resetbones in their tables it’s not a viable solution if I actually want this thing to work.
Here’s a little snippet from the code, with variable assignments added to avoid any confusion:
local Health = LocalPlayer():Health() local wep = LocalPlayer():GetActiveWeapon() local RemainingAmmo = wep:Clip1() local MaxClipSize = 0 if Health > 0 then if wep:GetTable().Primary == nil then if RemainingAmmo > MaxClipSize then MaxClipSize = RemainingAmmo end else MaxClipSize = wep:GetTable().Primary.ClipSize end else MaxClipSize = 0 end
As you can see I tried to use if RemainingAmmo > MaxClipSize then MaxClipSize = RemainingAmmo end but for some reason Gmod decides to bring the value of MaxClipSize down with RemainingAmmo whenever any ammunition’s spent.
Get out a fully loaded SMG, MaxClipSize will be set to 45. Shoot a bullet and both the RemainingAmmo value and MaxClipSize value decreases to 44.
Is there any reason as to why this happens? Is there any more efficient and dynamic way to get the max clip size (from HL2 guns specifically)?