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

Solved mt_rand()???

Comments in 'Plugin Development' started by Legoboy0215, Aug 2, 2015.

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

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I tried this:
    PHP:
    $vip mt_rand(110000);
    $this->getServer()->broadcastMessage($vip);
    It broadcasted nothing. What did I do wrong?
  2. asyven
    Offline

    asyven New Member

    Joined:
    Jan 17, 2015
    Posts:
    29
    Minecraft User:
    asyven
    on command broadcasting?
    i think need some correct

    Code:
    $vip = mt_rand(1, 10000);
    $this->getServer()->broadcastMessage("".$vip."");
    Legoboy0215 likes this.
  3. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    no need
  4. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    actually i don't see anything wrong..
    Legoboy0215 likes this.
  5. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    There is completely no need for the quotes. $vip is already a string by itself. Please provide solutions that are valid. By the way, the problem might be the plugin not being loaded at all, so you should check that.
    CrazedMiner and Legoboy0215 like this.
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    It is valid. It worked after that :)
  7. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Oooooo, a miracle happened...
  8. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Yeah... It was a coupon plugin.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    VIP is not a string itself. It is an int.
    Anyway, that's not the right way to cast int to string. Just (string) it.
    PHP:
    $server->broadcastMessage((string) $int);
  10. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    WOW...
    Code:
    /me Needs to learn php and read their docs.
  11. TonyDroide
    Offline

    TonyDroide Active Member Plugin Developer

    Joined:
    Jun 5, 2015
    Posts:
    122
    Plugins:
    1
    Minecraft User:
    TonyDroidd
    It works for me:

    PHP:
    $vip mt_rand(110000);
    $this->getServer()->broadcastMessage(implode($vip));
  12. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    implode()??
    LDX likes this.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Implode implode array with a glue ("" as glue if not given). By calling implode($int), PHP implicitly does this:
    1. Convert the value into array by making a new array and pushing your value into the array.
    2. Construct a new native string for appending contents into it.
    3. For each of the contents in the array (there is just one item in our case), convert it into a string (from your int) and append it into the string.
    4. Return the string to you.
    This is obviously much more work required. A lot of redundant code is executed. Keep in mind that coding isn't merely to make it work. For instance, reading the code confuses a lot of people (why do you implode an int instead of converting if into a string?). It is just like, you can natural log the power of e to your integer before passing it. Or maybe multiply it by 100 times and minus its 99 times. But this is redundant code.
    TonyDroide likes this.
  14. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Thanks for pointing that out.
  15. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Thanks! THAT was the problem... lol
Thread Status:
Not open for further replies.

Share This Page

Advertisement