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

Getting a random player from a config

Discussion in 'Development' started by RoyalMCPE, Apr 22, 2017.

  1. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    I want to know how I could get a random player from a config, any ideas?
     
  2. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    You can safe all players in an array an use this code:
    PHP:
    $input = array("Player1""Player2""Player3""Player4");
    $rand_keys array_rand($input2);
    $end $input[$rand_keys[0]];
    $end is the output :D
     
  3. RoyalMCPE

    RoyalMCPE Slime

    Messages:
    87
    It would be simpler to use a config. Because what I'm doing is when a player types in chat it will add their name to the config, then when a command is executed it will choose a player that typed the message
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    why not just user a var doe?
     
  5. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    I think an array would be much simpler than adding a player to a config each time. Just add their name to an array when using whatever command, and then use $this->exampleArray[array_rand($this->exampleArray, 1) to get the name.
     
  6. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    This is exactly the same as I said above: D
     
    Kyd likes this.
  7. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    You made the output of array_rand an array, that and I was replying to his post saying that using configs would be simpler.

    This post. :p
     
  8. Aviv

    Aviv Baby Zombie

    Messages:
    156
    PHP:
    $players $config->get("Players");
    if(
    is_array($players)){
      
    $player $players[array_rand($players)];
    }
     
    corytortoise 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.