• Team Autobalance
    1 replies, posted
Ok, I'm trying to make a gamemode and I want to have an autobalance for having players join the teams. Right now I'm using a slightly modified version of team.BestAutoJoinTeam() and all I'm changing in it is what teams can be passed. This is my problem; I'm testing with 4 players and only sometimes it works correctly and its 2 blue against 2 red, but sometimes it does 3 blue and 1 red or 1 blue and 3 red, and I don't understand. It seems super simple but I guess I've been working on this all day and I'm just getting tired?? I don't know. I think I'm just being really dumb and the answer is probably right in front of me. Here's the code I'm using; [CODE] function GM:GetLeastPlayers() local useteams = self.useallteams or false local SmallestTeam = TEAM_UNASSIGNED local SmallestPlayers = 1000 for id, tm in pairs( team.GetAllTeams() ) do if ( id == TEAM_BLUE or id == TEAM_RED or (useteams and id == TEAM_GREEN) ) then local PlayerCount = team.NumPlayers( id ) if ( PlayerCount < SmallestPlayers || (PlayerCount == SmallestPlayers && id < SmallestTeam ) ) then SmallestPlayers = PlayerCount SmallestTeam = id end end end return SmallestTeam end [/CODE] This is the order of the teams: [CODE] TEAM_BLUE = 1 TEAM_RED = 2 TEAM_GREEN = 3 [/CODE] Thanks in advance!
Looks like it was getting the player count for each team and so when it did mess up, it was until it was reset. To fix this at the end of the round I set the player back to the Spectator team, and, sets the player counts of the teams back to 0, obviously and makes a fair balance.
Sorry, you need to Log In to post a reply to this thread.