Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Selecting Random Players

Comments in 'Plugin Development' started by Pman1220, Aug 10, 2015.

  1. Pman1220
    Offline

    Pman1220 Active Member Plugin Developer

    Joined:
    Nov 21, 2013
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Pman1220
    Hi There! Before you start telling me to use the search button let me just say. I have. I used the resources to find out how to select random players, but my problem is that Im trying to select 3 random players and I want to make sure the plugin doesnt randomly select 2 of the same person. How can I do so? Thanks
  2. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,429
    Plugins:
    14
    PHP:
    $players $this->getServer()->getOnlinePlayers();
    $selected = [];
    for(
    $i 0$i 3$i++) {
      
    $r mt_rand(0,count($players) - 1);
      
    $selected[] = array_splice($players,$r,1)[0];
    }
    CraftYourBukkit likes this.
  3. Pman1220
    Offline

    Pman1220 Active Member Plugin Developer

    Joined:
    Nov 21, 2013
    Posts:
    123
    Plugins:
    1
    Minecraft User:
    Pman1220
    Thanks! I was just using $p[array_rand($p)] Thanks for your help again!
    LDX likes this.

Share This Page

Advertisement