So I am trying to draw a time meter. Its a bar that slowly depletes as time passes similar to the cloaking meter in TF2 . I have my math function done and working, and I have my hudpaint function done as well. The only problem is I can't get the bar to slowly go down as time passes. I have so many hours into this it is driving me crazy haha. Any help with this would be greatly appreciated!
[code]
Duration = 20 --Total time for the event.
staticDuration = 20 --Never changes, need it to do math later on.
TotalBarLength = 149 --How Long we want our drawRect to be.
staticTotalBarLength = 149
function cTimeHandler() --This gets called every second.
Duration = Duration - 1
TimeLeft = Duration
Percentage = (TimeLeft / staticDuration)
TotalBarLength = (staticTotalBarLength * Percentage)
if TimeLeft <=0 then
timer.Destroy( "CloakingTimer" )
end
end
function DrawCloakBar(ply)
--Background Color
surface.SetDrawColor( 255, 0, 0, 255)
surface.DrawRect(ScrW()/2-74 , ScrH()/2+75, 149, 22 )
--Outline
surface.SetDrawColor( 0, 0, 0, 255 )
surface.DrawOutlinedRect(ScrW()/2-75 , ScrH()/2+75, 150, 22 )
surface.DrawOutlinedRect(ScrW()/2-76 , ScrH()/2+76, 152, 20 )
--CloakBar
surface.SetDrawColor( 0, 0, 255, 255 )
surface.DrawRect(ScrW()/2-75 , ScrH()/2+77, TotalBarLength, 18 )
hook.Add( "HUDPaint", "DrawCloakBar", DrawCloakBar, ply )
end
function SWEP:DrawHUD()
DrawCloakBar(ent) --Did it this way so it wouldn't remove my hud when the player switches weapons.
end
[/code]