Splitting players

Discussion in 'Plugin Development' started by Cool_Nick_Name, May 4, 2015.

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

    Cool_Nick_Name

    Hello, i ake a minegame plugin and need to spil the player in groups to divide them into teams. but the problem is I need the teams not divided ecually, it need to be something that 1 of 3 players will be in team 1 and the other 2 in team 2. Can someone help me with this?

    btw: sorry for my spelling and grammar mistakes, i'm dutch. And i set my server to online mode.
     
  2. I don't know if this really could work
    Code:
    //Our teams
    Team team1;
    Team team2;
    
    public final List<Player> players = new ArrayList<>(); //This is just a example don't use a list of players
    
    double divided = players.size() / 3;
    
    for(int i = 0; players.size() > i; i++) {
       Player player = players.get(i);
       if(i <= divided * 2) {
          team1.add(player);
       } else {
          team2.add(player);
    }
    
     
  3. Offline

    mine-care

    @MaTaMoR_ prefer to give sudo code please to avoid the simple copy paste with -most of the time- no knowledge gain for the op.


    @Cool_Nick_Name you can loop through 1 / 3 of online players, add them in team 1 and then add the rest to team 2 :- )
     
  4. Yes you prefer that.
     
  5. Offline

    mine-care

    @MaTaMoR_ just saying and I thin a lot of bukkit helpers would agree. From that point and beyond its up to you to decide :- )
     
  6. I really don't care who would agree with that.
     
  7. Offline

    Cool_Nick_Name

    I'm terrible with math in Java and have NO IDEA what that code means, could you explain it a bit?
     
  8. with the for we're just looping a integer , so while int I is lowe than players.size() (amount of players) the int I will be increased, so it will do the action inside the loop X times, X = amount of players, after i check if the int I is lower than divided * 2 (divided * 2 = 66% of players) so if the int I is lower thand divide * 2 i just add the player to team 1, and the else check simply add the other 33% of players in the team 2.

    PD: Sorry for my english.
     
    Last edited: May 5, 2015
  9. Offline

    Cool_Nick_Name

    I got the first bit... luckely I don't need to use that much math in Java. Thanks for explaining:D
     
Thread Status:
Not open for further replies.

Share This Page