Hello! I was just wondering if you guys have had any experience with timers. Specifically, precise timers. Now, I create a timer for every player and show it to them.
Kinda like this (to keep things short):
[code]timer.Create(stuff_you_should_ignore, function() ply:SetNWFloat("Time", ply:GetNWFloat("Time") - 0.01)
...
draw.SimpleText(string.format("%.2f", ply:GetNWFloat("Time")), stuff_you_should_ignore)[/code]
The timer seems to be a bit off, otherwise there's no problem. I was just wondering if there are any other and possibly better ways of doing this.
Network the end time and then use a think hook with DeltaTime for precise updating.
That's not how you should do it.
You set current value of CurTime() to a value ONCE, like ply.StartTime = CurTime() and show it on HUD like this:
print( ply.StartTime + 5 - CurTime() )
This will count down from 5 to -infinity.
Something like this
[lua]local countdown = 0;
net.Receive( "Countdown Update", function( len )
countdown = net.ReadUInt(32)
end )
hook.Add( "Think", "Super awesome countdown of doom", function()
if ( countdown > 0 ) then
countdown = countdown - FrameTime();
if ( countdown < 0 ) then
countdown = 0
end
end
end)
hook.Add( "HUDPaint", "Magical timer", function()
if ( countdown > 0 ) then
draw.SimpleText( string.format( "%.2f", countdown ), ... )
end
end )[/lua]
Oh. I didn't know I could use CurTime()... silly me
Thanks anyways.
Sorry, you need to Log In to post a reply to this thread.