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.
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);
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
Tss1410 Yes but I need to check how many values. Notch:good Randy:Bad Jeb:Good int goods = 2; int bad = 1;
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
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 == 5 && ARRAYLISTNAME.size == 5){//start game}
it should do, just write what you want to do out logically first when trying to do something then code it