how to make 25% of the players on a server go on one team
3 replies, posted
I can't really think of a way to do this but I want to put 25% of people onto one team and the rest on the other. how would I do this? I was thinking of altering GM:TeamHasEnoughPlayers (this is fretta btw) to make it only have enough players when it reaches 25% of the server population. anyone have any ideas?
[lua]for k, v in pairs(player.GetAll()) do
if math.random( 1, 4 ) == 1 then
v:SetTeam(1)
end
end[/lua]
I'm no Lua whiz so this probably wont work.
Ryan, that won't work. It could be from 0 to 100%.
You want something like this -- untested, but it's the general idea:
[lua]-- fillTeams(TEAM_RED,TEAM_BLUE,75) will fill TEAM_RED with 75 percent of players
function fillTeams(team1,team2,percent)
local t,n = player.GetAll(), math.floor(percent/100 * #player.GetAll());
for i=1,#t do
local pl = table.Random(t);
pl:SetTeam(total < i and team1 or team2);
for k,v in pairs(t) do if v==pl then t[k] = nil; end end
end
end[/lua]
It would be impossible to get EXACTLY 75% unless the amount of players were in powers of 4: 4, 8, 12, 16, 20.
Although it wouldn't be a fourth always, you would still get a majority to one team.
Sorry, you need to Log In to post a reply to this thread.