Give random player item

Discussion in 'Plugin Development' started by Glass_Eater84, Aug 30, 2014.

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

    Glass_Eater84

    Hey Bukkit!
    Today I have a question, on how to give a random player inside a "section" an item.
    So, I have created something where if you get a water bottle and you drink it, it fills your hunger, and heals you, (This is for a small minigame I am working on) How would I go about choosing a random person inside the arena to give them a water bottle? (Do I need an arena to give them a water bottle if not that then that works too!)
    Thanks for any help!
    - Glass
     
  2. Offline

    dchaosknight

    Glass_Eater84

    How are you keeping track of which players are in the arena?
     
  3. Offline

    aguy867867

    I suggest using a Hashmap to store all your player names. Get a random Number (use the Math.random() function and multiply it by 30 and round the number) and iterate through the hashmap that many times. Then give the player selec5ed the item.
     
  4. Offline

    NonameSL

    Take your list/array/hashmap/set or whatever you are storing your players in, use
    String player = list.get(new Random().nextInt(/*SIZE OF THE LIST*/)-1);
    or if it is an array use
    String player = array[new Random().nextInt(/*SIZE OF THE LIST*/)-1];

    Then get the player and do whatever you want.
     
  5. Offline

    teej107

Thread Status:
Not open for further replies.

Share This Page