Random Teams

Discussion in 'Plugin Development' started by TehVoyager, Nov 3, 2013.

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

    TehVoyager

    I am making a mini game plugin with two teams,, basically bad guys and good guys. I have made code so there needs to be four players to start. I want at least two bad guys per game and then good guys/5 = number of badguys. I have a hashmap of players and their teams so I would want to change the null to teams randomly
    Code:
    Players Teams
    -------------
    Notch null
    Jeb null
    TehVoyager null
    Random Null
     
    //to
     
    Notch bad
    Jeb good
    TehVoyager good
    Random bad
    
    I know i should probably use a Random() but how do I make sure there's two bad guys. Also I don't want it to be in alphabetical order or anything.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  2. Offline

    Tss1410

    save the players in hashmaps
    public HashMap<Player> good = new HashMap<Player>();
    public HashMap<Player> bad = new HashMap<Player>();

    if(good.size => bad){
    good.add(player);
    } else {
    bad.add(player);
     
  3. Offline

    TehVoyager

    I could use the same concept but is there a way to check how many of each value is in a hashmap (all players in one hashmap and their team as their value) to see how many are on each team. Thanks
    Tss1410
     
  4. Offline

    Tss1410

    good.size checks how many players there is in the hashmap
     
  5. Offline

    TehVoyager

    Tss1410
    Yes but I need to check how many values.

    Notch:good
    Randy:Bad
    Jeb:Good

    int goods = 2;
    int bad = 1;
     
  6. Offline

    hugo1005

    TODO:
    1. to run the random generator twice to randomly pick to bad guys.
    2. then set the rest to good.

    If you want it dynamic for the number of players eg. 2/5 of them our bad guys then:
    eg. 10 people
    10/5*2 = 4 bad guys
    Then run random generator 4 times to pick 4 bad guys (remember each time you run it remove previously selected bad guys).

    Then the rest are good guys.

    Like:)
     
    TehVoyager likes this.
  7. Offline

    TheUpdater

    just do


    PHP:
    int missingp 5;//TEAM SIZE 5
     
    if(ARRAYLISTNAME.size missingp){
    ARRAYLISTNAME.add(p.getName);
    }
    if(
    ARRAYLISTNAME2.size missingp){
    ARRAYLISTNAME2.add(p.getName);
    }
     
    if(
    ARRAYLISTNAME2.size == && ARRAYLISTNAME.size == 5){
    //start game
    }
     
  8. Offline

    TehVoyager

    hugo1005
    Thank You, I think that will work, I'll tell you if it does
     
  9. Offline

    hugo1005

    it should do, just write what you want to do out logically first when trying to do something then code it
     
Thread Status:
Not open for further replies.

Share This Page