hud healthbar and armour at 0

I’m guessing it has something to do with math.Clamp?
I researched it and actually don’t even know if it has anything at all to do with math.Clamp but even if it does, I’ve no idea how to use it in this context.
Both the armour and health bar look completely stuffed when they’re at 0


surface.CreateFont( "font1", {
	font = "Arial", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
	extended = false,
	size = 15,
	weight = 500,
	blursize = 0,
	scanlines = 0,
	antialias = true,
	underline = false,
	italic = false,
	strikeout = false,
	symbol = false,
	rotary = false,
	shadow = false,
	additive = false,
	outline = false,
} )

hook.Add("HUDPaint", "lubatronhud" , function()

	local health = LocalPlayer():Health()
	draw.RoundedBox(6,6,ScrH() - 125,210,80,Color(60,60,60, 225))

	draw.RoundedBox(6,10,ScrH() - 100,200,15,Color(255,120,120,100))
	draw.RoundedBox(6,10,ScrH() - 100,health * 2,15,Color(255,80,80))

	draw.SimpleText(health,"font1",50 + 50,ScrH() - 93,Color(0,0,0),1,1)

	local armor = LocalPlayer():Armor()

	draw.RoundedBox(6,10,ScrH() - 80,armor * 2,15,Color(255,200,4))
	draw.RoundedBox(6,10,ScrH() - 80,200,15,Color(230,180,0,100))


This is because of draw.RoundedBox.

One solution would be adding a check to only draw it if its above 0 (which you should do even without this problem tbh)

First argument = math.min( 6, width of the box )

Just do some simple value checks:

if (health > 0) then
   draw.RoundedBox(6,10,ScrH() - 100,health * 2,15,Color(255,80,80))

You can do the same with armour.


[editline]18th October 2016[/editline]

Not sure if this a more suitable idea than doing value checks but, I did try this and I miserably failed. I’m sorry :c
Update: After the second try, I just ended up with the same result.

	draw.RoundedBox(math.min(6,15),10,ScrH() - 100,200,15,Color(255,120,120,100))
	draw.RoundedBox(math.min(6,15),10,ScrH() - 100,health * 2,15,Color(255,80,80))

I’m not sure if that’s how it’s meant to be done.

Update#2: So I decided to research math.min and actually got it working, you sir are a genius.
:goodjob: good job me.
Thank you very much.

Although I’ve got to say that, it ruins the circular ends of the rectangles

[editline]18th October 2016[/editline]

Thanks for the idea, much appreciated.

	local health = LocalPlayer():Health()
	local myValue = 6
	local roundness = math.min( myValue, health )

	draw.RoundedBox(myValue ,10,ScrH() - 100,200,15,Color(255,120,120,100))
	draw.RoundedBox(roundness ,10,ScrH() - 100,health * 2,15,Color(255,80,80))

Thank you.