Help with a timer...please

Basically I’m attempting to make a timer show up on the screen where then something occurs after the timer has ended, could you help?

So far I’m using ‘surface.DrawText’ and ‘draw.DrawText’.

Post your code you have so far.

All I do have is a simple;

draw.DrawText( "10:27", "DermaLarge", 850, 5, Color( 255, 0, 0, 255 ), TEXT_ALIGN_CENTER )

I’ve tried making it show as a timer.Simple or so, however it just doesn’t work. I just wanted to require a bit of help or even better a code written, however explain a bit as I’m interested in how it works for the future.

There’s probably a better way to do it, but here’s how I’d go about it.

timer.Create("Timer name", 10, 1, function()
	--do stuff

hook.Add("HUDPaint", "Paint_DrawTimer", function()
	if timer.Exists("Timer name") then
		draw.DrawText( string.ToMinutesSeconds(timer.TimeLeft("Timer name")), "DermaLarge", 850, 5, Color( 255, 0, 0, 255 ), TEXT_ALIGN_CENTER )

That will check your timer to see how many seconds it has before running, then formats it so it’s in the MM:SS format.

Thanks hahah, that helped me so much. Just one question, how would I restart/reset the timer and how would I make it function something at a certain time on the clock?


timer.Start to start/restart it, and where it says “–do stuff” is where you put the stuff you want to run when the time is up.
For a certain time on the timer you probably want to make a new timer with shorter time on it and run them parallel.