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

random items

Discussion in 'Development' started by Zuruki, May 7, 2017.

  1. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    I have 5 functions. Each function uses the variable $player for Player. They each give the player a kit: how can I make it so these function are random? like so it will give random kits
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    mt_rand() with a switch
     
  3. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    Need sample code, please.
     
  4. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    mt_rand( function 1, function 2) etc?
    switch($func->getName());
    case "function 1":
    //blah
     
  5. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    try this:
    PHP:
    $random mt_rand(1,5);
            switch(
    $random){
                case 
    1:
                
    $this->onefunction;
                break;
                case 
    2:
                
    $this->twofuncton;
                break;
                case 
    3:
                
    $this->treefunction;
                break;
                case 
    4:
                
    $this->fourfunction;
                break;
                case 
    5:
                
    $this->fivefunction;
                break;
            }
    It may not be the best way to do this, but it should work.
     
    Zuruki likes this.
  6. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    thanks duuude!!
     
    DanielYTK 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.