• Someone can help me with CurTime()?
    8 replies, posted
Hello everyone. I'm scripting the HUD of my gamemode, and I have different rounds that work in this order: pre round (30 seconds) --> round 1 (3 minutes 20 seconds, or 200 seconds) --> round 2 (7 minutes, or 420 seconds), then round 1 --> round 2 --> round 1 --> round 2. Every duration is based on timers, but as far as I know we can't just display the time remaining of the timer on the HUD, so we must use CurTime() (right?). This is the HUD script (keep in mind that the timers are countdowns): function drawHUD(f, x, y, c) if PreRound then hook.Add("HUDPaint" , "PreRoundHUD", function() draw.DrawText(string.ToMinutesSeconds(30 - CurTime()), f, x, y, c) end) elseif Round1 then hook.Add("HUDPaint" , "Round1HUD", function() draw.DrawText(string.ToMinutesSeconds(200 - CurTime()), f, x, y, c) end) elseif Round2 then hook.Add("HUDPaint" , "Round2HUD", function() draw.DrawText(string.ToMinutesSeconds(420 - CurTime()), f, x, y, c) end) end The problems are: In the "Pre Round" the timer starts from 25 or less, and when it reach 00:00 it restarts from 59:59, and keeps counting down until the 30 seconds (of the other timer, created with Timer.Create) are elapsed When the "Round 1" starts, the timer starts from about 2:45 (instead of 3:20). It seems like it counts also the previous 30 seconds and the initial delay. How can I solve this?
Thank you, I did not use "timer.RepsLeft("name_of_the_timer")" because the timer is called serverside and for some reasons it can't be seen clientside, and in the HUD is shown at 00:00. And, if I don't ask you too much, could you please explain me that code? I really don't understand it (specially why you use the modulus % sign). It would be much appreciated.
Thank you, your code is working, but there's another thing that i did not mention before. Before "Pre Round", there's another round, the round that waits for players, that has an undefined duration. So, with SecondsLeftBeforeNextPhase = CurrentPhaseMaxDuration - CurTime() the "Pre Round" countdown shows 30 seconds minus the duration of "Wait Round". How can I solve this problem?
Thank you, but I have a new problem now. I have implemented what you said like this: function preRound() timer.Create("preroundtime", 30, 1, beginRound) timer.Create("preroundtimeleft", 0.5, 30, UpdatePreTime) end function UpdatePreTime() SetGlobalFloat("PreRoundTimeLeft", timer.TimeLeft("preroundtime")) end function beginRound() -- Here the real round stuff end and, in the "cl_hud.lua" file: function drawHUD() if PreRound then hook.Add("HUDPaint" , "PreRoundHUD", function() draw.DrawText(string.ToMinutesSeconds(GetGlobalFloat("PreRoundTimeLeft")), "font" --[[etc etc]]) end) --etc etc end end Basically, every 0.5 seconds i'm updating the global float "PreRoundTimeLeft". Apart from being asynchronized, the timer stops right after 15 seconds. The more seconds I update the variable, the more seconds it will last, the less synchronization with timer seconds (if I update the variable every 1 second, i get: 30 --> 28 --> 26 --> 24 every second because it is not synchronized). How can I do?
Thank you! It worked wonderfully!
Sorry, you need to Log In to post a reply to this thread.