PHP: foreach($this->getServer()->getOnlinePlayers() as $p){$p[1]->teleport($x, $y, $z);$p->[2]->teleport($x1, $x1, $z1);$p->[3]->teleport($x2, $x2, $z2);}
Uhhh, I don't think that code will work lol. What you could do is, on player join, teleport them to a random position from an array. For example: PHP: public function onJoin(PlayerJoinEvent $event) { $positions = []; // Fill this in with the positions you want them to spawn at $event->getPlayer()->teleport($positions[array_rand($positions)]);}
Just wtf? why do you try to use the language construct foreach, which as the name implies does something for each item just to the try to access the array directly? also $p->[1] is totally wrong and you should know why. This is one of the few cases where you really have to JUST learn php/general oop first. please
you need to learn PHP you can teleport the players with this: PHP: //define coords (x, y, z)$coords = [[5,98,11],[46,84,4],[2,4,89]];foreach($this->getServer()->getOnlinePlayers() as $p){ //get coords index by getting the index of Server::getOnlinePlayers(); if(isset($coords[array_search($p, $coords)])){ //define coords data for the player $data = $coords[array_search($p, $coords)]; $x= $data[0]; $y= $data[1]; $z= $data[2]; $p->teleport($x, $y, $z); } else { $p->sendMessage("no coords found at index " . array_search($p, $coords)); }}//not tested but if it does not work then try this:$coords = [[5,98,11],[46,84,4],[2,4,89]];$index = 0;foreach($this->getServer()->getOnlinePlayers() as $p){ //get coords if(isset($coords[$index])){ //define coords data for the player $data = $coords[$index]; $x= $data[0]; $y= $data[1]; $z= $data[2]; $p->teleport($x, $y, $z); } else { $p->sendMessage("no coords found at index " . $index); } $index++;}