Greetings, I have been searching for a way to develop multiple spawn points for a minigame. So, basically, as you may have played or/and seen HungerGames before ( I am not creating Hunger/SurvivalGames), I want the players to be teleported to different locations, while not being teleported to the same point, where the other player has been located. I will work out a way, if the player leaves (PlayerQuitEvent), so a new player can join at that previous player's location. I am a little confused, as how may I do it. P.S. I do know how to teleport a player, I am just unsure, that how may I find, if the player is located at that position and then teleport the next joining player to the new spawn point. (the minigame and the lobby and located in two different worlds, due to Transferring issues in 0.13) Any assistance appreciated
Create an array of arrays, like this: Spoiler PHP: $this->worlds = new Config($this->getDataFolder()."worlds.yml", Config::YAML, array( "lobby" => "Lobby", "lobbySpawn" => [ 0 => 128, 1 => 70, 2 => 128 ], "mapName" => [ "neededPlayers" => 8, "minplayers" => 6, "maxSlots" => 11, 0 => [ 128, 5, 128, open ], 1 => [ 128, 5, 128, open ]//add more here ] )); Then change one to "taken" when a player joins and "open" when a player leaves PHP: $this->cords = $this->plugin->worlds->getNested($worldName.".".$this->plugin->nextSpawnNumber); You will need to figure out the code for checking if a slot is taken by yourself, but here is an idea: 1. Get the slot at nextSpawnNumber, check if it is open, if not then add 1 to nextSpawnNumber and go to step 2 2. Do it again with nextSpawnNumber and got to step 1
Just put the players as specific Players with specific spawns when the game starts, not when they join. That makes it a loy easier
Try this: PHP: public $x;public $z;public $y;public function onLevelChange(EntityLevelChangeEvent $event) { $player = $event->getEntity(); $level = $event->getTarget(); if($player instanceof pocketmine\Player) { if($player->getLevel()->getName() == /*Target level Name*/) { //Checks if player is leaving the minigame level and sets the spawn to their location $this->x = $player->x; $this->y = $player->y; $this->z = $player->z;} if($level->getName() == "/*Target level Name*/") { if(count($level->getPlayers()) == 1) { $this->x = $x; $this->y = $y; $this->z = $z; } if(count($level->getPlayers()) == 2) { $this->x = $x; $this->y = $y; $this->z = $z; } if(count($level->getPlayers()) == 3) { $this->x = $x; $this->y = $y; $this->z = $z; } // etc... $player->teleport(new Vector3($this->x, $this->y, $this->z); } } public function onQuit(PlayerQuitEvent $event) { // I dont think this would be needed $player = $event->getPlayer(); if($player->getLevel()->getName() == /*Target level Name*/) { //Checks if player is leaving the minigame level and sets the spawn to their location $this->x = $player->x; $this->y = $player->y; $this->z = $player->z;} }} I havent tested this, so if something doesnt work just use ur brain and modify it.
It isnt. It teleports each player that joins the world to a new loacation, and if a player leaves the next player that joins will spawn to that location. This is perfect for minigames like HungerGames & SkyWars.