Solved Splitting players into two teams

Discussion in 'Plugin Development' started by cray_Z, Dec 30, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    cray_Z

    What I'm looking for is a good way to go about splitting a server of 30 people into two teams. One team of 25 and one team of 5. I thought that I could use a sync repeating task to increment a counter, and if the counter was equal to a number if would put the player into a team. What is the best way to do this?

    Thanks.
     
  2. Offline

    reider45

    Code:java
    1. Player[] players = Bukkit.getServer().getOnlinePlayers();
    2. Collections.shuffle(Arrays.asList(players));


    So basically i'd shuffle all the online players, then get the first 5
    Code:java
    1. Player p = players[0];
    2. Player l = players[1];


    Etc.
    Then loop through all the players and if they're not one of the first 5 then do something else with them
     
  3. Offline

    Garris0n

    Put the first 5 people in one team and the rest in another...
     
  4. Offline

    zzienzz

    What he said

    if team 1 < 5, put player in team 1
    else put player in team 2


    Or, use a random number generator to add 80% of players in team 1, and the rest in team 2.
    I personally use random number because its best when you have a varying player number.
    For example, the first method i mentioned is really bad if only say, 8 people are playing.

    Alternatively you could do something more complicated

    if team 1 <1, put player in team 1
    else if team 1 ==1 && team 2 < 5 put player in team 2
    else if team 1 ==1 && team 2 >5, put player in team 1, etc
     
  5. Offline

    cray_Z

    Yeah I figured out a better way. Thanks guys
     
  6. Offline

    Dread9Nought

    I always just did it like this:

    Code:java
    1. public Team getNextTeam() {
    2. int max = 60000;
    3.  
    4. Team[] teams = new Team[2];
    5. teams[0] = getRedTeam();
    6. teams[1] = getBlueTeam();
    7.  
    8. Team res = teams[0];
    9.  
    10. for(Team team : teams) {
    11. if (team.getMembers().size() < max) {
    12. res = team;
    13. max = team.getMembers().size();
    14. }
    15. }
    16.  
    17. return res;
    18. }
     
Thread Status:
Not open for further replies.

Share This Page