Hello i have a question. I want to get all players in the Variable players because i want to teleport each player to a spawnpoint. How i can make it ? Please with a Code thanks!
Code: $players = $this->getServer()->getOnlinePlayers(); foreach($players as $player) { $player->teleport($this->getServer()->getDefaultLevel()->getSafeSpawn()); } ^^
and again... PHP: $c = 0;foreach($players as $p){$c++; if($c == 1){// 1. spawnpunkt}if($c == 2){// 2. spawnpunkt}// or create an array like this: [1 => new Position()..., 2 => new Pos()];// and do $p->teleport($pos[$c]);}
Hi, is this needed, and does it really fix tp glitches? In Player.php on line 84 it says for teleportImmediate(): * This method may not be reliable. Clients don't like to be moved into unloaded chunks. * Use teleport() for a delayed teleport after chunks have been sent
There you have right but i want this method only for 5 players xD . If you have a method could you post it here please ? ^^
Something like @MyNameIsTriXz said in the comment PHP: # Init positions$spoints = [ 0 => [ "free" => true, "pos" => new Position(0, 0, 0); ] 1 => [ "free" => true, "pos" => new Position(0, 0, 0); ] 2 => [ "free" => true, "pos" => new Position(0, 0, 0); ] 3 => [ "free" => true, "pos" => new Position(0, 0, 0); ] 4 => [ "free" => true, "pos" => new Position(0, 0, 0); ]];# Teleport$tped = false;foreach($spoints as $i => $sp){ // You could also use '&$sp' here if($sp["free"] === false) continue; $player->teleport($sp["pos"]; $tped = true; $spoints[$i]["free"] = false;}if(!$tped){ throw new \RuntimeException("No free spawn points left."); // Of course you don't have to 'throw' anything :D}
Thanks for it ! Can i do it like this PHP: public function onMet(){$players = $this->getServer()->getOnlinePlayers();foreach($players as $player){$player[0]->teleport(new position($this->x1 , $this->y1 , $this->z1) ;$player[1]->teleport(new position($this->x2 , $this->y2 , $this->z2) ;$player[2]->teleport(new position($this->x3 , $this->y3 , $this->z3) ;$player[3]->teleport(new position($this->x4 , $this->y4 , $this->z4) ;$player[4]->teleport(new position($this->x5 , $this->y5 , $this->z5) ;}}}
PHP: $pos = [new Position(), new Positon(), new Position()];$c = 0;foreach($this->getServer()->getOnlinePlayers() as $p){$p->teleport($pos[$c]);$c++}
So i can make it like this : PHP: $pos = [new Position($this->x1 , $this->y1 , $this->z1), new Positon($this->x2 , $this->y2 , $this->z2), new Position($this->x3 , $this->y3 , $this->z3)];$c = 0;foreach($this->getServer()->getOnlinePlayers() as $p){$p->teleport($pos[$c]);$c++}