Time in fretta.

Whats the best way to keep track of time ?

With a fretta gamemode I need 3 rounds with different timing like 2 min 3 min and 15 min so I am making a custom round system.

**[G.CurTime

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=G.CurTime)**

[editline]06:28PM[/editline]

All things time related, including timers and rounds use CurTime.

I’m having a bit of a problem, the first round time shows fine only when it switches to the second round
the round time shows 3600 minutes :S

Shared :
[lua]
MaxRounds = 3
Round = 1
Roundtime = {2,13,5}
StartTime = 0

RoundText = {
“Think”,
“Build”,
“Compete”
}
[/lua]
init :
[lua]
function GM:CheckRoundEnd()

if ( !GAMEMODE:InRound() ) then return end 

if(StartTime-CurTime() > (Roundtime[Round]*60)) then
	if(Round != MaxRounds) then
		Round = Round + 1
		StartTime = CurTime()
	end
end

end
function GM:OnRoundStart()
StartTime = CurTime()
end
[/lua]
draw :
[lua]
draw.SimpleTextOutlined(
RoundText[Round]…"
"…"Timeleft : "…string.FormattedTime((Roundtime[Round]*60)-StartTime-CurTime(), “%02i:%02i”),
“Trebuchet24”,
ScrW() / 2,
25,
Color(255,255,255,255),
TEXT_ALIGN_CENTER,
TEXT_ALIGN_CENTER,
1,
Color(0,0,0,255)
);
[/lua]

Oke, I found out that CheckRoundEnd isn’t called every second so I added a think hook and added a printing function to see if its working :

[lua]
function RoundEnd()
print(CurTime()-StartTime…" “…(Roundtime[Round]*60)…”
")
if(CurTime()-StartTime > (Roundtime[Round]*60)) then
if(Round != MaxRounds) then
Round = Round + 1
StartTime = CurTime()
end
end
end
hook.Add(“Think”,“RoundCheck”,RoundEnd())
[/lua]
still it only prints it on the beginning of the server.

Line 10 shouldn’t have the brackets (parenthesis) after RoundEnd. The hook.Add function expects the third argument to be a function, you are passing the return value of the function.

Do you have a idea why the GM:CheckRoundEnd won’t run every second ?

btw I’m testing the think hook right now.

I have no idea, sorry.

I also tried to remove the

[lua]
if ( !GAMEMODE:InRound() ) then return end
[/lua]
still no luck :frowning:

you can make a timer that runs every second…
[**[URL=“http://wiki.garrysmod.com/?title=Timer.Create”]Timer.Create

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Timer.Create)**

Well, I got it working, kinda only do I need a nwvar to sync the rounds ? Because currently it is updating on the server but no on the client.