How to use curtime so setup a kind of round timer

I have been trying to retrieve my timer’s time left. only to just give up and search the internet.

Turns out it is better to do something with curtime().

But I haven’t been able to display an accurate timer.

Here is the code I have right now. (running in /lua/autorun/client/roundtimer.lua)


hook.Add( "HUDPaint", "drawroundtext", function()
	local roundtimer = timer.TimeLeft( "mapvotestart" )
	local timeleft = string.ToMinutesSeconds ( 2700 - CurTime() )
	surface.SetFont( "CloseCaption_Bold" )
	surface.SetTextColor( 255, 255, 255, 255 )
	surface.SetTextPos( ScrW()/2, 0 ) 
	surface.DrawText( timeleft )
end )

Anybody can help?

Wait, so why are you using TimeLeft AND using CurTime()? If TimeLeft works, then just use that.

I am trying to print the remaining time to the client.
I have gone with the simple way. make a duplicate of the timer on the client and have its timeleft - curtime() printed on HUD


timer.Create( "leftroundtimer", 2700, 0, function() end )
	hook.Add( "HUDPaint", "drawroundtimer", function()
	local roundtimer = timer.TimeLeft( "roundtimer" )
	local timeleft = string.ToMinutesSeconds ( roundtimer - CurTime() )
	surface.SetFont( "CloseCaption_Bold" )
	surface.SetTextColor( 255, 255, 255, 255 )
	surface.SetTextPos( ScrW()/2, 0 ) 
	surface.DrawText( timeleft )
end )

[editline]21st August 2016[/editline]

I finally ended up recreating the timer on the client with the exect name and time.
and used its timer.Timeleft() reduced by CurTime() to make it countdown.

Keep in mind that this code is to execute a map vote every 45 mins not on a per round basis.

well hope it helps someone else out there!


timer.Create( "roundtimerz", 2700, 0, function() end )
	timer.Create( "refreshderma", 1, 0, function()
	local roundtimer = timer.TimeLeft( "roundtimerz" )
	local timeleft = string.ToMinutesSeconds ( roundtimer - CurTime() )
	local Panel = vgui.Create( "DPanel" )
	Panel:SetPos( 10, 10 )
	Panel:SetSize( 200, 50 )
	Panel:SetPos( ScrW()/2 - 100, 0 )
	local DLabel = vgui.Create( "DLabel", Panel )
	DLabel:SetPos( 35, 15 )
	DLabel:SetTextColor( Color( 0, 0, 0, 255))
	DLabel:SetFont("Trebuchet18")
	DLabel:SetText( "Round" )
	local DLabel2 = vgui.Create( "DLabel", Panel )
	DLabel2:SetPos( 75, 15 )
	DLabel2:SetTextColor( Color( 0, 0, 0, 255))
	DLabel2:SetFont("Trebuchet18")
	DLabel2:SetText( "ends in:" )
	local DLabel3 = vgui.Create( "DLabel", Panel )
	DLabel3:SetPos( 130, 15 )
	DLabel3:SetTextColor( Color( 0, 0, 0, 255))
	DLabel3:SetFont("Trebuchet18")
	DLabel3:SetText( timeleft )
	end)