1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

[SOLVED] Getting a Random outcome

Discussion in 'Development' started by RoyalMCPE, Feb 5, 2017.

  1. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    I am making a plugin that gives a player a random amount of money, and I want to send the player a message of how much money they won.
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    if you want true randomness, it is better to hitch a ride on webAPI nothing can like mt rand can achive true randomness like a actual true random generator
    maybe using crypto currency for no rate limit
    but if you are just a normal developer who dont even know what true randomness is, just use mt_rand for if they won OR how much they would get
     
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    PHP:
    switch(mt_rand(1,number){
    case 
    1:
    u won $500
    *give money here*
    case 
    2etc
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    but the 500 is not random tho?
     
  5. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    tis just an example
     
  6. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    I did that originally but it wasn't how I wanted it. The code that I'm using now is.

    PHP:
    $money =rand(100000400000);

    EconomyAPI::getInstance()->addMoney($p$money);
    $p->sendMessage("You won ".$money);
     
  7. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Well you already solved your problem?
     
    applqpak likes this.
  8. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    No because it will send a message with a number 100000 - 400000 intead of getting the money that they won.
     
  9. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Well you gave the player the money of $money, which is the same number you sendMessage to your player, so whats the problem?
     
  10. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    It doesn't work like that.
    If the player won $125,630 it will send a message but it will just randomize again and send a different number like 365,443
     
  11. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Wtf? When you call a function and assign it to a variable it stores the value that the function returns, not the function.
     
  12. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Did you even test the code you wrote lol
     
  13. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    Yes I did it gave me $275,893 but the message said that I won $432,932
     
  14. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Is the code you posted the same with the one you tested?
     
  15. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    Yup
     
  16. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    No, it certainly isn't unless Economy is fucked up big time
     
  17. kaliiks

    kaliiks Zombie

    Messages:
    250
    PHP:
    public function addMoney(){
    $prize mt_rand(1,3);
    switch(
    $prize){
    case 
    1:
    EconomyAPI::getInstance()->addMoney($player"50");
    break;
    case 
    2:
    EconomyAPI::getInstance()->addMoney($player"150");
    break;
    case 
    3:
    EconomyAPI::getInstance()->addMoney($player"200");
    break;
     
    Last edited: Feb 7, 2017
  18. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    I would do this but I want it to add a random amount form 100,000 to 400,000
     
  19. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    can you try to do
    PHP:
    EconomyAPI::getInstance()->addMoney($player300000);
    and see if you really received 300,000
     
  20. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    crypto is not true randomness either.
    I still think that connecting a beta radiation source next to a GM counter with data logger is the best randomness generator.
     
    HimbeersaftLP likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.