Solved [Help!] How do I make chances!

Discussion in 'Spigot Plugin Development' started by iRealize, Jun 21, 2016.

  1. So I was working on a plugin but I stumbled across a problem I was going to make so when you mine an emerald block it would give you effects but I wanted to have a 25% chance of getting it but I could NOT figure it out so I need help from a pro. Here is the code:

    public class BlockEvents implements Listener{

    public void onBlockBreak(BlockBreakEvent event) {
    Player player = event.getPlayer();

    Block block = event.getBlock();
    Material material = block.getType();

    if(material == Material.EMERALD_BLOCK) {
    player.addPotionEffect(new PotionEffect (PotionEffectType.CONFUSION , 1500 , 1));
    player.addPotionEffect(new PotionEffect (PotionEffectType.BLINDNESS , 250 , 1));
    player.sendMessage(ChatColor.RED + " Shortend down messaage! ");
    player.addPotionEffect(new PotionEffect (PotionEffectType.HUNGER , 30000 , 1 ));
    player.addPotionEffect(new PotionEffect (PotionEffectType.POISON , 10000 , 0));
    player.sendMessage(ChatColor.RED + "If you dont find treatment you will get closer to death!");

    Please copy this and add the chances thing to make it easier for me
  2. Use a random integer to generate a number between 0 and 100.
    If the number is less then 25, (25 chance),
    give them the block.
    • Like Like x 1
  3. Code (Text):
    if (random number between 0 and 100) is less than 25
         give effects
    • Like Like x 1
  4. Random.nextFloat...
  5. Code (Text):
    if (random number from 0 to 3 == 0)
         give effects
  6. Thanks!
  7. I might sound like a noob which I am but where do i put since it always gives me a red line....
  8. Maybe I'm misunderstanding, but if you're just copy and pasting, the red line is because that isn't valid code. It's placeholder code representing the core ideas which you need to replace with functioning code (see: Random).
  9. if you thought if (random number between 0 and 100) is less than 25 was actually code.. take a step back, stop working on this, and learn basic java.
    • Winner Winner x 1