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

How to make "randomly" $reward?

Comments in 'Plugin Development' started by Asidert, Apr 2, 2015.

  1. Asidert
    Offline

    Asidert Active Member Plugin Developer

    Joined:
    Oct 21, 2014
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Asidert
    Hi, me need "random" $reward, I make code:
    PHP:
       $itemreward rand(13);

       if(
    $itemreward 1){
       
    $reward = new Item(rand(256321));
       }

       if(
    $itemreward 2){
       
    $reward = new Item(rand(122));
       }

       if(
    $itemreward 3){
       
    $reward = new Item(rand(4152));
       }
    It not works and my plugin use last $reward value...
    Who knew how to make working "random" values?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use === to compare, not =.
    Also, use Item::get($id) not new Item($id).
    Also, use mt_rand() rather than rand(); that's faster.
  3. Asidert
    Offline

    Asidert Active Member Plugin Developer

    Joined:
    Oct 21, 2014
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Asidert
    Thanks, I try it...
  4. Asidert
    Offline

    Asidert Active Member Plugin Developer

    Joined:
    Oct 21, 2014
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Asidert
    I use compare with === and server told me:
    Undefined variable: itemreward...
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    = for variable assignment
    === for comparing whether they are equal.
    Asidert likes this.
  6. Asidert
    Offline

    Asidert Active Member Plugin Developer

    Joined:
    Oct 21, 2014
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Asidert
    Ok, I try it too...
  7. Asidert
    Offline

    Asidert Active Member Plugin Developer

    Joined:
    Oct 21, 2014
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Asidert
    Thanks a lot!
    I have done LuckyBlocks plugin <3 Screenshot_2015-04-03-07-09-45.png
    PEMapModder likes this.

Share This Page

Advertisement