how to start next round with lua

i am wondering how to start next round with lua. i know maybe it’s a simple question and easy to be searched,but i really try this and find nothing.i guess it because my express is not accuracy,so i post a question here.thanks in advance.

What do you mean ‘start next round’? Are you working on your own game-mode and need to learn how to handle rounds, or are you using an existing game-mode?

i’m working on my own game mode,i don’t know when next round start how can i clean up maps and respawn players

Create a function:



function NewRound()

    game.CleanUpMap() -- thanks ScarehGhoost

    for _, ply in pairs(player.GetAll()) do
        -- do stuff to players, set positions, give weapons, etc.
        ply:Spawn()
        ply:SetPos(Vector(x,y,z))
        ply.score = 0
    end

    -- anything else that needs doing when the round starts like resetting score, placing down pickups etc.
end



Whenever you want a new round to start, run NewRound()

This is general coding, there’s no special indicator as to when a new round starts, that’s up to you to program.

Using above example, if you had a score on ply.score and you wanted to start a new round when a player reached score 10 :



hook.Add("PlayerDeath", "HandlePlayerDeath", function( victim, inflictor, attacker )
    attacker.score = attacker.score + 1
    if attacker.score == 10 then
        NewRound()
    end
end )




timer.Create("RoundTimer", 60, 0, function()
   
   game.CleanUpMap()

   for k,v in pairs(player.GetAll()) do
      v:ChatPrint("New Round Started")
      v:Kill()
      v:Spawn()
   end
end)


I know dev discussion typically doesn’t like ppl to spoonfeed code, so read over this. basically, every 60 seconds, the server will clean up the map and respawn all players.

Basic shit, not hard to make, hopefully this helps.

edit: i guess the above works too.

edit 2: could also make a ticker timer to run every second and increment a var +1 each time, once it gets to x, start a new round.

thank you very much,it works.

[editline]5th April 2016[/editline]

it helps me a lot,i really appreciate it