Random Generator

Discussion in 'Plugin Development' started by Woodenplanks320, Jul 10, 2013.

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

    Woodenplanks320

    Hello people,
    I want to code a game. Now I want to code a generator, which generate who is a bad guy and who is a nice guy. The nice guys must have more players than the bad guys. Can somebody help me?
     
  2. Offline

    andf54

    You need two HashSet's which contain the names of "teams". Other than that I can't say, because you gave no explanation on how you want people to be assigned those roles.
     
  3. Offline

    Woodenplanks320

    So I want to make 3 Groups the detektivs, the traitors and the innocents. All players are in the array Players i want to get the player who are in the array and some of them will be traitor or detective and he rest be innocent

    sorry for the bad english :D i hope you understand what i want to do

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

    andf54

    You can't start coding a plugin before deciding how it works. How do you want people to be assigned to those teams? Random?
     
  5. Offline

    Woodenplanks320

    Yes sorry i forgot to wrote it i want to write random generator :D
     
  6. Offline

    andf54

    When player joins:
    Code:
    Random rand = new Random();
    double val = rand.nextDouble();
    if(val < 0.1) team1.add(player.getName); // 10% chance the player will be assigned to team 1
    esle if(val< 0.5) team2.add(player.getName); // 0.5-0.1 = 40% chance the player will be assigned to team 2
    else team3.add(player.getName) // 1.0 - 0.5 = 50% chance that the player will end up on team3
    
     
  7. Offline

    Woodenplanks320

    okay thanks i think it will work

    is there a chance that all player will be in one role

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

    andf54

    Yes there is that chance. But then you would need to get rid of random. You should check which team needs members most and then add/reassign players there.

    Also, no matter what you do, there is always that chance, even if not random. What happens if there is only a single player online?
     
  9. Offline

    Techy4198

    yes but it is VERY rare. it depends on the number of players.
    for 8 players there is something like a 1 in 20000000 chance they will all be innocent.

    check that there are at least 3 players online before putting them into teams, and still get rid of random.

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

    andf54

    What about when players quit.

    Oh and if you require 3 players to be online, then what if 1 player constantly joins/quits. The chat will be spammed with "Game has started" and "Game has ended".

    This all depends on how the game should be set up.
     
  11. Offline

    Woodenplanks320

    yes i need 3 players or more but alle role need minimal one player
     
  12. Offline

    Pawnguy7

    I did something that divided people up into two groups. This should be similar. You shouldn't "hope" they get distributed, you should do it correctly yourself. So, for example, you want 1o% detective? (by the way, this sounds similar to Mcpvp Sabotage?) So, you run a loop, such as:

    Code:
    for (int i = 0; i < Math.ceil(Bukkit.getServer().getOnlinePlayers()*0.1); ++i
    Let's imagine you start with four lists. One is the entire online player lists, and the other three are empty, for the three types. For the loop above, add them to the detective list, and remove them from the all players list. That is, add a random index from all the players.

    Now, you have a list of detectives, and none of them are in the other list. Do a loop for innocents (the amount of looping is similar to above). Take a random player from the list that was initially all the players. Remove it from there, and add it to the innocents list.

    The remaining players on the list will all be traitors.
     
  13. Offline

    Woodenplanks320

    i understand what you mean but i dont know to make it in java i dont understand your code
     
Thread Status:
Not open for further replies.

Share This Page