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

how to use random generator

Comments in 'Plugin Development' started by Wantedkillerss, Aug 31, 2014.

  1. Wantedkillerss
    Offline

    Wantedkillerss Active Member Plugin Developer

    Joined:
    May 9, 2014
    Posts:
    142
    Plugins:
    1
    Minecraft User:
    Wantedkillers
    L|OK I want to use random generator for a O|Plugin I'm making ex:
    O|Case: "test"
    O|$rand//?
    L|$p-sendmessage("lol");
    $rand
    $p->sendmessage("lols")
    So basically I've never used random stuff and I know this is 100% wrong
  2. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    PHP:
    $m = array("lol","lols");
    $r mt_rand(0,count($m) - 1);
    $p->sendMessage($m[$r]);
  3. Wantedkillerss
    Offline

    Wantedkillerss Active Member Plugin Developer

    Joined:
    May 9, 2014
    Posts:
    142
    Plugins:
    1
    Minecraft User:
    Wantedkillers
    Oh thx so if I put four messages it'll be 25% chance each
    LDX likes this.
  4. Tuff
    Offline

    Tuff Active Member

    Joined:
    Jan 25, 2014
    Posts:
    203
    Minecraft User:
    Roboroug2
    Theoretically yes.
    LDX likes this.
  5. Wantedkillerss
    Offline

    Wantedkillerss Active Member Plugin Developer

    Joined:
    May 9, 2014
    Posts:
    142
    Plugins:
    1
    Minecraft User:
    Wantedkillers
    Well I have 7 so
    100 divided by 7 = 14.2857142857
  6. Tuff
    Offline

    Tuff Active Member

    Joined:
    Jan 25, 2014
    Posts:
    203
    Minecraft User:
    Roboroug2
    Is that right? Huh.
  7. Wantedkillerss
    Offline

    Wantedkillerss Active Member Plugin Developer

    Joined:
    May 9, 2014
    Posts:
    142
    Plugins:
    1
    Minecraft User:
    Wantedkillers
    If u can guess what it's for I'll post the plugin
  8. Wantedkillerss
    Offline

    Wantedkillerss Active Member Plugin Developer

    Joined:
    May 9, 2014
    Posts:
    142
    Plugins:
    1
    Minecraft User:
    Wantedkillers
    Do u have to
    Use\pocketmine\?\?
  9. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    [​IMG]
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You want to get a random value from an array, or you want to get a fair random integer from a range!
  11. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    What??
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    array_rand($m);

    As for weighted randomness, it is harder. You may refer to the BlockList class in WorldEditArt, although it hasn't been tested yet.
  13. Wantedkillerss
    Offline

    Wantedkillerss Active Member Plugin Developer

    Joined:
    May 9, 2014
    Posts:
    142
    Plugins:
    1
    Minecraft User:
    Wantedkillers
    OK so what's mt
  14. Wantedkillerss
    Offline

    Wantedkillerss Active Member Plugin Developer

    Joined:
    May 9, 2014
    Posts:
    142
    Plugins:
    1
    Minecraft User:
    Wantedkillers
    I tried to test the plugin and it just says couldn't load in what cases does it say that
  15. Wantedkillerss
    Offline

    Wantedkillerss Active Member Plugin Developer

    Joined:
    May 9, 2014
    Posts:
    142
    Plugins:
    1
    Minecraft User:
    Wantedkillers
    If someone does ex:
    /test hello how are
    How do u get the hello and make two answers if hello is there like(I know I'm way off):
    If there's hello
    $m =array("black","white");
    $r what ldx did
    $P what he did
    If there's bye
    $m=array("green","yellow");
    $r what ldx did
    $p what ldx did
    ....}
    ..}
    }
  16. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    You're not saying anything... anyways, you can use what @LDX said (easier)
    LDX likes this.
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Then you are switch case or if elseif else. It is obvious, and we aren't doing every tiny part of a plugin for you. If you don't know how to use if statements and switch-case blocks, learn PHP.
    Tuff likes this.
  18. Wantedkillerss
    Offline

    Wantedkillerss Active Member Plugin Developer

    Joined:
    May 9, 2014
    Posts:
    142
    Plugins:
    1
    Minecraft User:
    Wantedkillers
    Thank u

Share This Page

Advertisement