Issue with HUD ammo bar

Hello.

Currently I am trying to make a HUD with moving bars, and 2 of them work, the armor and hp one, but the ammo bar doesn’t(at least correctly)

The bar doesn’t fill up the entirely with a full mag:

Any idea why?

Here is the code:


				draw.RoundedBox(3, 16, ScrH() - 15 - 36, 100 * 2.6, 23, Color(25,25,25,255))
				draw.RoundedBox(3, 16, ScrH() - 15 - 35, LocalPlayer():GetActiveWeapon():Clip1() * 2.6, 21, Color(255,145,0,255))
				draw.SimpleText( "Ammo: "..ply:GetActiveWeapon():Clip1().." / "..ply:GetAmmoCount( wep:GetPrimaryAmmoType() ), "Trebuchet24", ScrW() - 1875, ScrH()-52, Color(255, 255, 255,255) )

Thanks

LocalPlayer():GetActiveWeapon():Clip1() * 2.6 This is why.

What you want to do with dynamic widths is this:



local number = LocalPlayer():GetActiveWeapon():Clip1() -- Current ammo
local MaxNumber = 45 -- Max ammo

local maxWidth = 500 // Max box width

local realWidth = maxWidth * ( number / MaxNumber ) -- The actual box width you use in the draw.RoundedBox

is there a way to make it get the default amount of bullets in the clip of your current weapon, and then have the bar width change depending on the clip size?

Yes, by accessing the SWEP table and looking for ClipSize variable.

You’d need to add exceptions for HL2 sweps though.