Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How make chance drop items?

Comments in 'Plugin Development' started by Player7221, Mar 2, 2016.

  1. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
    Hi!
    I have questions, because I write plugin on the drop items with stone, but I dont know how make %.

    My config:
    Code:
    drops:
      items:
        diamond:
          chance: 3.5
    
    You can help me?
    I want make %..
  2. TheDeibo
    Offline

    TheDeibo Notable Member Plugin Developer

    Joined:
    Sep 8, 2014
    Posts:
    692
    Plugins:
    1
    Minecraft User:
    TheDeibo
    can you also put the plugin's PHP up too? ( just so we can see that too? )
  3. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
    I want % drop items with stone.
    Example
    Code:
    if(getChance(3.5))
    {
    //drop diamond.
    }
    
    How create %?
    Last edited: Mar 2, 2016
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
  5. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
  6. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    mt_rand(min, max) returns a pseudo-random integer between min and max inclusively.

    That means, if you do mt_rand(1, 100), it has a chance to be 1, 2, 3, ..., 99 or 100. Then the chance of it being less than or equal to 0 (<= 0) is 0%. It has 1% chance to be 1, so mt_rand(1, 100) <= 1 has 1% chance to be true. If you check it against 2, it has 2% chance to be true since both outputs of 1 and 2 match the condition. mt_rand(1, 100) <= 99 has 99% chance to be true, because it has 99 numbers that are valid and 1 number that is not valid, hence 99/(99+1) = 99%. mt_rand(1, 100) <= 100 is obviously always true, hence 100%.

    Now you understand how to do it?
    PocketKiller and Player7221 like this.
  8. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
    Yes thanks

Share This Page

Advertisement