I tried many things to make that possible for my server,to spawn on the kitpvp map I have,if a player dies there,but all codes I used don't do anything. PHP: <?phpnamespace gofightcore\events;use pocketmine\event\Listener;use pocketmine\event\entity\EntityDamageEvent;use pocketmine\event\entity\EntityDamageByEntityEvent;use pocketmine\event\player\PlayerRespawnEvent;use pocketmine\Server;use pocketmine\utils\TextFormat;use pocketmine\math\Vector3;use pocketmine\level\Position;class Events implements Listener { public function noDelayBug(EntityDamageEvent $event){ if($event instanceof EntityDamageByEntityEvent){ $entity = $event->getEntity(); if($entity->getLevel()->getName() === "KitPvP4"){ $event->setCancelled(false); } } } public function onPlayerRespawn(PlayerRespawnEvent $ev){ if(Server::getInstance()->getLevelByName("KitPvP3")->getPlayers()){ $ev->getPlayer()->teleport(Server::getInstance()->getLevelByName("KitPvP3")->getSafeSpawn()); Server::getInstance()->dispatchCommand($ev->getPlayer(), "warp KitPVP3"); {else } } if(Server::getInstance()->getLevelByName("KitPvP4")->getPlayers()){ $ev->getPlayer()->teleport(Server::getInstance()->getLevelByName("KitPvP4")->getSafeSpawn()); Server::getInstance()->dispatchCommand($ev->getPlayer(), "warp KitPVP4"); } }}
Not sure what you're trying to do, if you want when a player dies to teleport him to the level he died into : - listen to player respawn event - get the player level and store it - teleport the player to the level with the level you stored Send what you tried I'll help you fix it
PHP: public function onPlayerRespawn(PlayerRespawnEvent $ev){ if($ev->getPlayer()->getLevel()->getName() === "KitPvP3"){ $ev->getPlayer()->teleport(Server::getInstance()->getLevelByName("KitPvP3")->getSafeSpawn()); Server::getInstance()->dispatchCommand($ev->getPlayer(), "warp KitPVP3");} else { } }} I used the if($ev->getPlayer()->getLevel()->getName() == "KitPvP3"){ And now the teleport code and the warp command (I added the command to be sure that it works) execute only if I died in that world,but the server teleports me back to main spawn again.
Yes I did that to see if the tp works and I see in game the "teleporting to warp KitPVP3" but I'm still on server's main spawn if I die on the KitPvP map.
https://github.com/pmmp/PocketMine-MP/blob/389e7767d1c491dc783a64c8052bc4804801782c/src/pocketmine/event/player/PlayerRespawnEvent.php Use the setRespawnPosition by the way.
Ok I found some codes about setRespawnPosition() from a plugin in github and I added and edited the codes to make that I want and it worked,and I don't need the warp command or the teleport code.