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

Get only players in survival

Comments in 'Plugin Development' started by Irish, May 18, 2016.

  1. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    How would I send particles to only players in survival? Right now, it sends particles to everyone, but I'm not sure how to get a list. I tried array_push, with no luck.
  2. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    PluginTask and __construct
    PHP:
    $level $this->plugin->getServer()->getLevelByName("world");
    $players $level->getPlayers();
    foreach(
    $players as $player){
      if(
    $player->getGamemode() === 0){
        
    $level->addParticle(new RedstoneParticle(new Vector3($player->getX(), $player->getY()+1$player->getZ())));
      }
    }
    Last edited: May 18, 2016
  3. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    Well, that doesn't help. To add a particle, you need an array.
    Survingo likes this.
  4. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    maybe try
    PHP:
    foreach($this->getServer()->getOnlinePlayers() as $player){
        if(
    $player->isSurvival()){
            
    //add particle in player's position
        
    }
    }
  5. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Everyone will see it.
  6. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    PHP:
    $level $this->getServer()->getLevelByName("WorldName");
    $pos = new Vector3(000)
    $survivalplayers = array();
    foreach(
    $this->getServer()->getOnlinePlayers() as $player){
      if(
    $player->isSurvival()){
        
    array_push($survivalplayers$player);
      }
    }
    $level->addParticle(new RedstoneParticle($pos), $survivalplayers);
    Last edited: May 19, 2016
  7. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Actually, you dont unless you want certain people to see it :p
  8. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    Read again, I tried array_push. It didn't work.
  9. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Then you did something wrong.
  10. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    Don't say I did something wrong, when you don't know the code. Anyway, it's probably because I made it public. so public $survival_players = array();
  11. AvivShopenCraft
    Offline

    AvivShopenCraft New Member

    Joined:
    Oct 14, 2015
    Posts:
    73
    Minecraft User:
    AvivShopen
    i was thinking he wants everyone in survival mode :p
    EDIT: now i readed again the question and understood that he wants to send it to player so just them can see it lol
    Last edited: May 19, 2016
  12. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    PHP:
    $survival = [];
    foreach(
    Server::getOnlinePlayers() as $p) {
      if(
    $p->isSurvival()) $survival[] = $p;
    }
    Level::addParticle(new Particle(Vector3), $survival);
    Or
    PHP:
    $particle = new Particle(Vector3);
    foreach(
    Server::getOnlinePlayers() as $p) {
      if(
    $p->isSurvival()) $p->dataPacket($particle->encode());
    }
  13. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    Better don't call it via static
  14. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I'm not saying you should call a non static function statically, it's the proper way to show the function usage.
  15. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Also have a look at array_filter() if you want to get the players in survival (for example, for reusing):
    PHP:
    assert($server instanceof \pocketmine\Server);
    $players array_filter($server->getOnlinePlayers(), function(Player $player){
      return 
    $player->isSurvival();
    });
    foreach(
    $players as $player){
      
    // first loop
    }
    foreach(
    $players as $player){
      
    // if you want to use it again
    }

Share This Page

Advertisement