Timer duration bar

Is it possible to create a timer and using draw.RoundedBox to show how long is left in the timer? So if my timer is 30 seconds long then I want the bar to shrink as the time decreases. Can I get an example or explanation of how to do that with lua?

You seem to have a basic understanding. This function will return the amount of time left in the timer.

Here’s how to calculate time-remaining, elapsed time, and display it on the hud: https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/sh_hud_countdown.lua.html

Everything in this can be done using timer.TimeLeft as StonedPenguin suggested, but here is the traditional way it had to be done before timer.TimeLeft was added.

Alright that works fine and dandy but for whatever reason math.Round isnt working, at all… It prints the long string of numbers no matter how many integer places I choose. I even tested with another variable I made up and could not get that to round either



local timeleft = timer.TimeLeft("CloakingTime") 
math.Round(timeleft, 2)
print("Time left " .. timeleft)


Edit: I am a moron…



local rounded = math.Round(timeleft)


Got it