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

How to add 1/6 chance of getting an effect?

Comments in 'Plugin Development' started by Muqsit, Apr 16, 2016.

  1. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    Question^
    PHP:
                $effect Effect::getEffect(15);
                
    $effect->setDuration(250);
                
    $effect->setVisible(true);
                if (!
    $pl instanceof Player){
                    return;
                }
                
    $p->addEffect($effect);

  2. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    PHP:
    if(mt_rand(0,6) == 1){
    $effect Effect::getEffect(15);$effect->setDuration(250);$effect->setVisible(true);
    if (!
    $pl instanceof Player){
    return;
    }
    $p->addEffect($effect);
    }
  3. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    @korado531m7 I tried that. mt_rand is not random at all. It goes in sequence :/
    mt_rand(1,6) will go like
    1, 2, 3, 4, 5, 6 (in a sequence)
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    rand(06) === 1
    applqpak likes this.
  5. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    What does '===' do?
  6. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Identical to
    Muqsit likes this.
  7. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Use mt_rand, not sure why but even php.net recommends that
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    No, it does not.
    mt_rand() has more entropy than rand().
    xiaoq, Primus and MyNameIsTriXz like this.
  9. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    This did the trick
    PHP:
    rand(06) == 1

Share This Page

Advertisement