• Help with Countdown GUI (possibly using delta timer)
    5 replies, posted
Hey, I would like to make my GUI show a countdown for the "INNOCENTS HAVE UNTIL 4:00 TO HIDE" instead of just a set string - i.e. "INNOCENTS HAVE " .. time_left .. " LEFT TO HIDE". However, I don't know how to do this. Could anyone help me? Here is the function I have currently below: [CODE]funrounds[2] = function() local function BeginRound() if CLIENT then local showtext = true hook.Add("HUDPaint","FUNROUNDMESSAGE",function() surface.SetDrawColor(0,0,0,255) if LocalPlayer():GetRole() == ROLE_TRAITOR then surface.DrawRect(0,0,surface.ScreenWidth(),surface.ScreenHeight()) end if showtext then surface.SetFont("Bebas70Font") local w = surface.GetTextSize("FUN ROUND") surface.SetTextPos(surface.ScreenWidth()*0.5 - w/2, surface.ScreenHeight()*0.3) surface.SetTextColor( math.sin(2 * RealTime()) * 127 + 128,math.sin(2 *RealTime()+2) * 127 + 128, math.sin(2 *RealTime()+4) * 127 + 128, 255 ) surface.DrawText("FUN ROUND") local w,h = surface.GetTextSize("HIDE AND SEEK - INNOCENTS HAVE UNTIL 4:00 TO HIDE") surface.SetTextPos(surface.ScreenWidth()*0.5 - w/2, surface.ScreenHeight()*0.3+h+5) surface.DrawText("HIDE AND SEEK - INNOCENTS HAVE UNTIL 4:00 TO HIDE") end timer.Simple(60,function() showtext = false end) timer.Simple(60,function() hook.Remove("HUDPaint","FUNROUNDMESSAGE") hook.Add("HUDPaint","FUNROUNDNOTIF",function() surface.SetFont("Bebas30Font") surface.SetTextPos(5, 5) surface.SetTextColor( math.sin(2 * RealTime()) * 127 + 128,math.sin(2 *RealTime()+2) * 127 + 128, math.sin(2 *RealTime()+4) * 127 + 128, 255 ) surface.DrawText("FUN ROUND") local _,h = surface.GetTextSize("HIDE AND SEEK") surface.SetTextPos(5, 5+h) surface.DrawText("HIDE AND SEEK") end) end) end) else tnum = tostring(math.floor(#player.GetAll() / 8)+1) game.ConsoleCommand("ttt_traitor_max "..tnum.."\n") game.ConsoleCommand("ttt_detective_max 0\n") for _,entity in ipairs(ents.GetAll()) do if entity:IsWeapon() then entity:Remove() end end for _,ply in pairs(player.GetAll()) do if ply:GetRole() == ROLE_TRAITOR then game.ConsoleCommand("ulx freeze "..ply:GetName().."\n") timer.Simple(60,function() game.ConsoleCommand("ulx unfreeze "..ply:GetName().."\n") game.ConsoleCommand("ulx god "..ply:GetName().."\n") ply:SetRunSpeed(600) end) end end end hook.Add("Think","FUNROUND_THINK",function() if CLIENT then else for _,ply in pairs(player.GetAll()) do if not(ply:IsGhost() or not ply:Alive()) then if (ply:GetRole() == ROLE_TRAITOR) then ply:Give("weapon_ttt_knife") for _,knife in pairs(ply:GetWeapons()) do knife.SecondaryAttack = function(self) return end knife.AllowDrop = false end end end ply:SetCredits(0) end end end) end local function EndRound() if SERVER then game.ConsoleCommand("ttt_traitor_max 32\n") game.ConsoleCommand("ttt_detective_max 32\n") hook.Remove("Think","FUNROUND_THINK") for _,ply in pairs(player.GetAll()) do if ply:GetRole() == ROLE_TRAITOR then game.ConsoleCommand("ulx unfreeze "..ply:GetName().."\n") game.ConsoleCommand("ulx ungod "..ply:GetName().."\n") ply:SetRunSpeed(500) end end else hook.Remove("HUDPaint","FUNROUNDMESSAGE") hook.Remove("HUDPaint","FUNROUNDNOTIF") end end hook.Add("TTTBeginRound","BEGINFUNROUND",BeginRound) hook.Add("TTTEndRound","ENDFUNROUND",EndRound) end[/CODE]
Assuming [i]time_left[/i] will be a number of seconds left and that you are looking to get the real OS time, you can do something like this: [code] "INNOCENTS HAVE UNTIL" .. os.date( "%H:%M:%S", os.time() + time_left ) .. "TO HIDE" [/code] You can remove the ":%S" part of the format specifier if you don't want the seconds.
[QUOTE=thefreeman193;47327907]Assuming [i]time_left[/i] will be a number of seconds left and that you are looking to get the real OS time, you can do something like this: [code] "INNOCENTS HAVE UNTIL" .. os.date( "%H:%M:%S", os.time() + time_left ) .. "TO HIDE" [/code] You can remove the ":%S" part of the format specifier if you don't want the seconds.[/QUOTE] I don't think you understand what I mean. I wanted it to be a countdown from 60 seconds that changes the text every second.
Oh, right. You can use: [code] local key = HasteMode() && "ttt_haste_end" || "ttt_round_end" local time_left = string.FormattedTime( math.max( 0, GetGlobalFloat( key, 0 ) - CurTime() ), "%02i:%02i" ) [/code] You can then draw the text as follows: [code] local text = "INNOCENTS HAVE " .. time_left .. " LEFT TO HIDE" local w,h = surface.GetTextSize(text) surface.SetTextPos(surface.ScreenWidth()*0.5 - w/2, surface.ScreenHeight()*0.3+h+5) surface.DrawText(text) [/code]
Time: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/time/understanding_time%20and_basic_time_calculations.lua.html[/url] Countdown example: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/hud/sh_hud_countdown.lua.html[/url] - This calls a hook on client when count-down is up, same with server. It has some config options, it networks from server to client... Example Start and ExampleNetwork are examples of how to run it, the concommand will start it too. Basically, you only need to network the start CurTime( ) and the duration. CurTime is synced to clients so with those 2 values you'll be able to easily calculate time remaining to hide.. [ NOTE ] Remove .html to view / copy .Lua ...
Thanks for your responses, I ended up doing it a different way but yeah.
Sorry, you need to Log In to post a reply to this thread.