Bar that goes down like a timer?

What I want to create is a bar that’s width would go down with a timer making a bar timer sort of thing
I tried making a function with timer.Create then calling it so it would go down then had the width of the roundedbox set to the timer’s identifier but that did not seem to work?

I tried using this… I got this error:

[ERROR] addons/darkrpmodification/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:259: bad argument #4 to ‘Create’ (function expected, got nil)

  1. Create - [C]:-1
  2. fn - addons/darkrpmodification/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:259
    3. unknown - addons/ulib/lua/ulib/shared/hook.lua:110

This is the code I added:

if LocalPlayer():isWanted() then
		timer.Create("wantedtime", CONFIG_WANTEDTIME,1,PrintNoArguments )
		local timerleft = timer.TimeLeft("wantedtime")
		draw.RoundedBox(5, ScrW() - 596, ScrH - 105,timerleft, 13 )

CONFIG_WANTEDTIME is a variable I setup as obviously a configuration file for server owners in case they changed there wanted time.

The last argument is meant to be a function, you have a variable that is undefined.
Just add [lua]function() end[/lua] as the last argument for timer.Create.

Will you read the errors yourself?
Its saying the 4th argument of timer.Create is not valid!
Its not a function as it should be!

And for what you are trying to acomplish it should be better to compare a variable of CurTime

Okay it seems to only call the timeleft once how would I make it do it multiple times?

[editline]3rd August 2016[/editline]

Any ideas on making it call timer.TimeLeft multiple times so it changes the width?

[editline]3rd August 2016[/editline]


No, it isn’t, as he is only trying to run it once.

I dont understand the hostility and anger coming from geferon. He’s just asking a question. It doesnt look like you have your roundedbox in a paint. You can add a HUDPaint hook, or make a derma panel and have the time update in the panels paint function. Also, Lerp() comes in handy in this situation for making smooth transitions.


if LocalPlayer():isWanted() then
timer.Create(“wantedtime”,CONFIG_WANTEDTIME,1,function() end)


Or doing it the PANEL way, you can do something like this:

local PANEL = {}
function PANEL:Init()
local time = 8
timer.Create(“numTimer”,time,1,function() end)

self.Paint = function(s,w,h)

if timer.TimeLeft("numTimer") != nil then
  time = Lerp(16*FrameTime(),time,timer.TimeLeft("numTimer"))


local bar = vgui.Create(“numBar”)

Run DoProgressThing in console to see its output.

Pretty much all your posts should be in “Problems that don’t need their own thread”, so please post them there

I tried the HUDPaint you provided and what happened was it when the player was wanted it would show but it would not change size. Once you are not wanted it goes down then once the bar has disappeared afer reaching 0 width the HUD disappears and states this code in console

[ERROR] lua/includes/extensions/math.lua:188: attempt to perform arithmetic on local ‘num’ (a nil value)

  1. Round - lua/includes/extensions/math.lua:188
  2. RoundedBox - lua/includes/modules/draw.lua:189
    3. fn - addons/darkrpmodification/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:287
    4. unknown - addons/ulib/lua/ulib/shared/hook.lua:110