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. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Why use strings for numbers... :facepalm:
     
  2. kaliiks

    kaliiks Zombie

    Messages:
    250
    PHP:
    $rand mt_rand(1,4000);
    EconomyAPI::getInstance()->addMoney($player$rand);
     
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    But mt_rand doesn't exist in the PM API.
     
  4. kaliiks

    kaliiks Zombie

    Messages:
    250
    Oh, you can set random number to config and get to player
     
  5. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    ?????????
    Wtf
     
    dktapps, SOFe and kaliiks like this.
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I wanted to point out how people are using PM Forum like there's no stack overflow forum to help them with PHP QnAs.
     
  7. kaliiks

    kaliiks Zombie

    Messages:
    250
  8. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    PHP:
    /** Minium money */
    const MIN_MONEY 100000;

    /** Maximum money */
    const MAX_MONEY 400000;

    /** @var array */
    private $array = array();


    /**
    * @param Player $player
    */
    public function sendMoney(Player $player) {
        
    $money rand(self::MIN_MONEYself::MAX_MONEY);
        
    array_push($this->array$money);
        
    // I didn't had EconomyAPI plugin when writting this so i couldn't check if it was loaded
        
    EconomyAPI::getInstance()->addMoney($player$this->array);
        
    $player->sendMessage("You won {$this->array[0]}$");
        
    array_shift($this->array);
    }
     
    Last edited: Feb 7, 2017
    RoyalMCPE likes this.
  9. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    The second parameter of addMoney() only accepts integers numeric values.

    Why not just do:

    PHP:
    public function payRandomAmount(Player $p){
    Economy::getInstance()->addMoney($p, (mt_rand(100,400)*1000));
    }
     
  10. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    Thank you I just had to make a few changes to it but it works!
     
    Diduhless likes this.
  11. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    wops
    PHP:
    EconomyAPI::getInstance()->addMoney($player$this->array);
    Change $this->array to $this->array[0]
     
  12. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    That is what I did to fix it
     
  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.