(LUA) Random select team, all team die map changes and teams not able to hurt each other

Okay, i have a zombie gamemode,
Team 1 (Big mother zombie)
Team 2 (Humans)
Team 3 (Infected)

Firstly, when humans die they go to Infected, i want to make it so when all of team 2 die, that the map changes
Also, Team 1 and Team 3 can injure each other, and i want them to not be able to hurt each other
also, it would be nice to make it randomly select 1 person for Team 1 when the map loads

Thanks! :slight_smile:

What I would do:

Use Team.GetPlayers to check how many players are alive, I’d use it in a Gamemode.PlayerDeath hook, in the same one you use to swap dead humans to infected.

Use Table.Random on a Player.GetAll when the server initializes (Gamemode.Initialize) to select a random player to join the “Big mamma zombie” team, but I would leave some time for players to finish connecting before you do so, so create a timer.

Gamemode.PlayerShouldTakeDamage would be your best choice for stopping teams 1 and 3 from hurting each other.
function GM:PlayerShouldTakeDamage( v, a )
if a:IsPlayer() then
if ( a:Team() == 1 and v:Team() == 3 ) or ( v:Team() == 1 and a:Team() ==3 ) then return false
else return true