Randomized Team System/Map Help

I’m having trouble making the code for this… :C

Basically I need it to be so that out of 24 players, 2 are randomly selected to be on one team and the other 22 remain on the other team. (Sortof like Deathrun but this gamemode is not deathrun ;))

I’ve looked plenty of places on how to do this and I can’t seem to find a good source of help. So I’ve turned to the wonderful community of Facepunch to help me. :smiley:

Also, another thing is how do I get my gamemode to be on a specific map? Like I have the map name but I don’t know how to like implement it into my gamemode and how to make the game keep it on that map.

Thanks. :slight_smile:

random = nil
function GM:PickRandomPlayer()
srandom = math.random(1,#player.GetAll())
if (srandom ~= random) then
random = srandom

Looks pretty messy but would probably work.

Actually, it’s not, the random variable keeps track of the last randomized player so it doesn’t pick the same player twice. If it does, it repeats the same function again until it finds a suitable player. It’s not messy, it’s the best way to do it.
Plus, i wrote this in a short amount of time in the time-span of 30 seconds, so obviously it wouldn’t be perfect, but the idea behind it is pretty much good enough

Well, you might use what Kuro suggested you, but I suggest you turn “random” variable into local, instead of leaving it as global.