1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Spawn a player in the same world if he's already there

Discussion in 'Development' started by Saxavlax001, Jun 17, 2019.

  1. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    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:
    <?php

    namespace 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");
       }
     }
    }
     
  2. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
    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
     
  3. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    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.
     
  4. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
    upload_2019-6-26_23-26-55.png
    upload_2019-6-26_23-26-52.png
    aren't you tping the player twice ?
     
  5. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    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.
     
  6. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
    Why don’t you just teleport the player to the warps location and send a message ?
     
  7. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
  8. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    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.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.