Hello! So im drawing blanks on how i can make this work... Let me explain what im trying to do.. I have 2 teams.. I need a way to have set a player to a random team EVERY time BUT keep the teams even.. Heres my code
[code]
for k, v in pairs(player.GetAll()) do
if v.LastTeam == nil then
v:SetTeam(math.random(1, 2))
if #team.GetPlayers(1) > #team.GetPlayers(2) then
v:SetTeam(2)
elseif #team.GetPlayers(2) > #team.GetPlayers(1) then
v:SetTeam(1)
end
v.LastTeam = v:Team()
v:ChatPrint("Round starting.. You are a " .. team.GetName(v:Team()) .. "!")
elseif v.LastTeam == 1 then
v:SetTeam(2) v.LastTeam = v:Team()
elseif v.LastTeam == 2 then
v:SetTeam(1) v.LastTeam = v:Team()
end
end
[/code]
Now yes this does make fair even teams however it just makes it so you go to the opposite team every round... the issue is you will always play with the same people i want it to be random but also fair...
Thanks for the help!
Note: This is for a custom gamemode
[QUOTE=tgandrew2468;52137093][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/team/BestAutoJoinTeam]team.BestAutoJoinTeam[/url][/QUOTE]
I can see how that can help balance but how can i make EVERY player join a random team EVERY round but also keep it balanced...
[QUOTE=XxLMM13xXx;52137102]I can see how that can help balance but how can i make EVERY player join a random team EVERY round but also keep it balanced...[/QUOTE]
Re-frame the problem. Instead of picking a team at random and assigning a known player to it, pick a player at random and assign them to a known team.
Here's an untested mockup of how that might work.
[code]
local playerpool = players.GetAll()
for i = 1, #playerpool do
local teamno = i % 2 + 1
local picked = math.random(1, #playerpool)
local ply = playerpool[picked]
ply:SetTeam(teamno)
table.remove(playerpool, picked)
end
[/code]
You can still do RandomPairs for randomize it order
[QUOTE=Jcw87;52146222]Re-frame the problem. Instead of picking a team at random and assigning a known player to it, pick a player at random and assign them to a known team.
Here's an untested mockup of how that might work.
[code]
local playerpool = players.GetAll()
for i = 1, #playerpool do
local teamno = i % 2 + 1
local picked = math.random(1, #playerpool)
local ply = playerpool[picked]
ply:SetTeam(teamno)
table.remove(playerpool, picked)
end
[/code][/QUOTE]
I ended up just using this.. This seems to work thanks!
Sorry, you need to Log In to post a reply to this thread.