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

Solved Select Random Player

Comments in 'Plugin Development' started by MineBuilderFR, May 5, 2016.

  1. MineBuilderFR
    Offline

    MineBuilderFR Active Member

    Joined:
    Mar 14, 2015
    Posts:
    56
    Minecraft User:
    MineBuilderFR
    Hi,
    how I could select an random way player on the server and send him a function?

    => The code I tested <=

    PHP:
    foreach($this->getServer()->getOnlinePlayers() as $online){

       
    $r $online[array_rand($online)];

       if(
    $r instanceof Player){

        
    $r->sendMessage("Test Send");
     
       }
     }
    => ERROR <=

    PHP:
    "Cannot use object of type pocketmine\Player as array"

    ==> How I Can fixe This ? Thanks For Your Help:)
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    $online is a player instance, not an array. Simply use $this->getServer()->getOnlinePlayers() as the array, the foreach() is not needed
    MineBuilderFR and HotFireyDeath like this.
  3. MineBuilderFR
    Offline

    MineBuilderFR Active Member

    Joined:
    Mar 14, 2015
    Posts:
    56
    Minecraft User:
    MineBuilderFR
    Thanks :) Now It Work ^^

Share This Page

Advertisement