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

Hello

Discussion in 'Requests' started by fipteam, Mar 25, 2017.

  1. fipteam

    fipteam Spider

    Messages:
    14
    GitHub:
    ThePlastus
    Hi !
    How get random online player on server?
    Code?
    Thanks
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Are you asking for code? This is the plugin requests section. Next time, use the Plugin Development section for that.

    You can use array_rand or mt_rand(or rand()?).

    array_rand:
    PHP:
     $randomPlayer array_rand($this->getServer()->getOnlinePlayers());
     
    $this->getServer()->broadcastMessage($randomPlayer->getName() . " is the randomly picked player!"); 
    mt_rand:
    PHP:
     $playerArray $this->getServer()->getOnlinePlayers();
     
    $chosen mt_rand(0count(array_keys($playerArray)) - 1);
     
    $this->getServer()->broadcastMessage($playerArray[$chosen] . " is the randomly chosen player!");
    I suggest the first method due to how much easier it is.
     
    fipteam likes this.
  3. fipteam

    fipteam Spider

    Messages:
    14
    GitHub:
    ThePlastus
    ok sorry and thanks for code
     
  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.