Random player

Discussion in 'Bukkit Help' started by Ezrab_, Jul 21, 2016.

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

    Ezrab_

    I've made a minigame plugin, but I want to make it so that when the countdown timer = 0. 1 Player gets chosen and will be the seeker and the rest of the players will be the hiders

    for example
    Me and 3 friends are in the minigame, and the countdown has ended 1 of us gets teleported to a different location and will get a message like "You're the seeker". And then the other 3 get teleported to a different location and get the message "You're the hider" I hope this is understandable
     
  2. @Ezrab_
    Generate a random number between 0 and however many players you have. Put all the players in a list. Then use the number you generated to get one of the players. Assign him the role of "seeker" and the others "hiders".
     
  3. Offline

    Ezrab_

    Could you give me an example?
     
  4. @Ezrab_
    Code:
    Random rand = new Random();
    List<UUID> players = new ArrayList<>();
    players.get(rand.nextInt(players.size());
    First what we do is make a list with all of the players we want, you would obviously need to add players to it. Then we get an entry from the list using an index. This index is a random number between 0 and the amount of entries in the
    List.
     
Thread Status:
Not open for further replies.

Share This Page