Higher integer, greater chance

Discussion in 'Plugin Development' started by JjPwN1, Jul 7, 2013.

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

    JjPwN1

    A quick question, really.

    I am creating a plugin where you can rank up in levels by mining stone and such. There are random chances you can get special stuff from mining, but I can't think of any way to tie in the player's level directly into the chance of getting special stuff. Currently,
    Code:java
    1. int chance = 1 + (int)(Math.random() * ((50 - 1) + 1));
    2. if(chance == 1){
    3. player.getWorld().dropItem(player.getLocation(), new ItemStack(event.getBlock().getType()));
    4. prplayer.sendMessage(player, "You have received double drops from mining!");
    5. }

    is what I use to do the chance, which has nothing to do with their level.

    So, to get their level, I just do "prplayer.getSkillLevel(player.getName(), Skill.Mining)". How would I tie that into the chance, so the higher the skill level, the greater the chance they get "double drops"?
     
  2. Offline

    microgeek

    Random.nextInt(level) == 0
    nextInt is not static, you need to make an instance of Random.
     
  3. Offline

    Chinwe

    What about generating a random int between 0 and 99 (for example), and then award double drops if it is below their level?

    eg. Level 5 - only double drops if random int < 5
    Level 30 - double drops if random int <30 : higher chance
     
Thread Status:
Not open for further replies.

Share This Page