Round timer and display timer

Well, I am making a gamemode and I want to have rounds. I do not know how to make a round. I know you make a timer, but where would it go and maybe a basic layout of what it should look like? I want it where at the end of each round, it kills everyone, then starts a new timer for a new round to start. Also, how would I display the timer?

[lua]RoundLength = 300 --5 minutes

function ResetRound()
–The round just ended, kill players and do whatever so they can start over.
end

timer.Create(“RoundTimer”, RoundLength, 0, ResetRound) --timer.Create(uniqueID, delay, reps, func, arguments)[/lua]

That’s probably the most simple way, it gives you the idea of how to make rounds so just work off of it.

I was going to say create a timer with the round limit as the time, but I thought I would get shot down by someone better

I got it to work. Now, how would I make a timer that spawns the player after the round timer ends? So, the round timer ends, everyone dies, then let’s say, 10 seconds later, everyone spawns again and a new round is started?

You’d have to create another timer, and run it when the other one has stopped.
But after the first one has stopped, you run the console command kill on everybody.

[lua]for k, v in pairs{ player.GetAll()} do
v:ConCommand(‘kill’)
end[/lua]

And then when the second timer is over you do the same for loop just with spawn instead:

[lua]for k, v in pairs{ player.GetAll()} do
v:Spawn()
end[/lua]

This should work.

[editline]10:03PM[/editline]

I was tired when I did this, but I think this should work.

[lua]function FirstRound()
RoundTime = 300 //Round Time in seconds
SpawnTime = RoundTime + 10 //Delay of 10 seconds, change the value for a longer or shorter delay
timer.Create( “FirstRound”, RoundTime, 1, function() // Run the function once after RoundTime Value has elapsed
for k, v in pairs{ player.GetAll() } do
v:ConCommand(‘kill’) //Kill everyone
end
end )

timer.Create( “SpawnDelay”, SpawnTime, 1, function() // Run the function 10 seconds after the RoundTime has elapsed
for, k, v in pairs{ player.GetAll() } do
v:Spawn() //Spawn everyone
end
end )
end[/lua]

Commented and whatnot.

Remember if it’s wrong, it’s because I’m tired and y’know.

[editline]10:04PM[/editline]

You can do a usermessage.Hook and run the function serverside if you want at certain points during the game.

So… It would look like this?:
[lua]timer.Create( “RoundTimer”, 300, 0, function()
for k, v in pairs( player.GetAll() ) do
v:Kill()
end
end )[/lua]

Then, how would I tell if the other one has stopped?

They both only run once, unless called on again.

The second one you know will stop when you spawn again.

Then, you restart them everytime they all spawn.

Ok, but also, what if I want to have the timers keep running for ever? I know i’d put the reps at 0, but wouldn’t that keep spawning me every 5 seconds? ( What I would have the spawn timer set at )

What you would want to do is have the timer only set to run once, and when it ends, make the spawn timer only run once, then repeat.
[lua]
function Round()
for k, v in pairs( player.GetAll() ) do
v:Kill()
end
timer.Destroy(“RoundTimer”)
timer.Create(“SpawnTimer”, 10, 1, Spawn)
end

function Spawn()
for k, v in pairs(player.GetAll()) do
v:Spawn()
end
timer.Destroy(Spawn)
timer.Create(“RoundTimer”, 300, 1, Round)
end[/lua]

[editline]09:40PM[/editline]

It’s an endless timer loop

Also you could just use timer.Simple, unless you want to be able to interrupt the game in the middle of the round.

No dont run a console command to kill the players use KillSilent() or Kill()

Ok, I am a little confused, but can figure it out. Now, how would I display the round timer in the HUD?

EDIT:
What Jo The Shmo gave me didn’t work. It does nothing.

In that case, make a timer that runs 300 times with 1 second intervals. In the function that the timer calls, subtract 1 from a variable called RoundTime or something, and if it is 0, call RoundEnd()
Also in that timer function, send all clients a usermessage or datastream with RoundTime in it, and have them update their HUD to display that variable.

I’m confused Jo. Can you maybe show me an example? Besides your first one, because, well, it didn’t work.

That’s because you probably never made the timer in the first place.
Just create the timer on GM:Initialize()
And sorry, but I don’t really want to make a whole example right now, see if someone else will.
If nobody does, Ill give you one later.

So far noone has given me an exmaple. If someone can, please do.

Creating an example is not that complex Joe, it took me roughly 3 minutes to make. I just made you what you need so work up from that and actually try and learn from it and not just copy/paste.

[lua]
-snip-
[/lua]

Thanks find me. Will look at that when I get home from school. I appreciate that you didn’t give me all of the code.

Ok, I have a problem. It spawns the player, even if the round is still going. So how would I disable it to where it only spawns the player if the round is over?