Random Picker

Discussion in 'Plugin Development' started by galbatoo, Jun 20, 2012.

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

    galbatoo

    How can i make a random Picker for Potions with codes like these?
    Code:
      event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 400, 20));
    I want that that the picker picks a random potioneffect.

    push/ i need quick help

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

    ProFatal

    Code:
    Random num = new Random();
    int gotNum = num.nextInt(5)
    
    This will generate a number from 0->5 and then from this just have
    Code:
    if(gotNum==1)
      //Potion 1
    if(gotNum==2)
      //Potion 2
     
    galbatoo likes this.
  3. Offline

    galbatoo

    Thanks man
     
  4. PotionEffectType is an enum, right?
    You can use .values() to get an array of all values, that's way more simple (but you ca neither weight the results nor only take specific ones).
    Code:
    PotionEffectType[] allTypes = PotionEffectType.values();
    PotionEffectType type = allTypes[yourRandom.nextInt(allTypes.length)];
     
    galbatoo likes this.
  5. Offline

    galbatoo

    But with the other solution i can add other things like sendmessage etc... I will give you a like too because your solution works too ;D
     
Thread Status:
Not open for further replies.

Share This Page