HUD: Making a progress bar.

Hey everyone.

I am in the process of making some HUD indication that has to show the progress of a given action.

My aim is basically the same as the lockpick from DarkRP - which has a progress bar as you pick a lock.

My initial thinking was something like this:


function progressBar ()

	draw.RoundedBox(0,ScrW()/2,ScrH()/2,200,50,Color(40,40,40))
	
	local lastTime = CurTime()
	
	while CurTime()-lastTime < 199 do
		
		draw.RoundedBox(0,ScrW()/2,ScrH()/2+1,CurTime()-lastTime,48,Color(255,0,0))
		
	end

end
hook.Add("HUDPaint", "progress bar HUD element", progressBar)

That, however, doesn’t seem to work. Has anyone got any nice way of doing something like this?

Sorry if you don’t understand my aim here.

Regards

  • Puster

That code won’t work because you’re redefining lastTime every time the function is called. You can fix that by placing “local lastTime = CurTime()”, but you’ll probably also want to change the arguments you’re passing to draw.RoundedBox for width.

Thanks, and glory for Cobrastan!