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

teleport not work in PlayerRespawnEvent

Discussion in 'Development' started by iBa4x, Mar 24, 2020.

  1. iBa4x

    iBa4x Spider Jockey

    Messages:
    32
    GitHub:
    iBa4x
    PHP:
            public function onRespawn(PlayerRespawnEvent $event){
                
    $player $event->getPlayer();
                if(
    $this->isInGame($player->getName()) == true && $this->getState() == true){
                    echo 
    "\n It's ok!";
                    
    $TeamFile = new Config($this->getDataFolder()."Game/team.yml",Config::YAML);
                    
    $team $this->getTeam($player->getName());
                    
    $number $this->getNumberOfTheTeam($player->getName());
                    
    $x $TeamFile->getNested($team "." $number ".pos.x");
                    
    $y $TeamFile->getNested($team "." $number ".pos.y");
                    
    $z $TeamFile->getNested($team "." $number ".pos.z");
                    
    $player->teleport(new Vector3($x,$y,$z,$this->getLevel()));
                }
            }
    I tried numbers rather than get it from data folder but it doesn't work at all just " echo " line work the teleport part not work and I don't know why!
    Is it exist to teleport when press respawn?
     
  2. Xenophilicy

    Xenophilicy Spider Jockey

    Messages:
    31
    GitHub:
    xenophilicy
    Vector3 takes exactly 3 arguments, you gave it 4. If you want a level, use the Position class.
     
  3. iBa4x

    iBa4x Spider Jockey

    Messages:
    32
    GitHub:
    iBa4x
    rather that it also doesn't work!
     
  4. Xenophilicy

    Xenophilicy Spider Jockey

    Messages:
    31
    GitHub:
    xenophilicy
    Are you getting an error in console? Are the coordinates you're giving it actually valid?
     
  5. iBa4x

    iBa4x Spider Jockey

    Messages:
    32
    GitHub:
    iBa4x
    No, no error in console. and I tried give coordinates are actually valid and also not work.
    maybe teleport can't code in PlayerRespawnEvent I don't know
     
  6. tungstenvm

    tungstenvm Witch

    Messages:
    54
    i remembered i got this issue before, when playerrespawnevent get called, player will be teleport, so i couldnt teleport player in this function.My way was canceled the deathevent and teleport the player in that funcion, otherwise you can try calling a delayed task to teleport player after few ticks
     
  7. iBa4x

    iBa4x Spider Jockey

    Messages:
    32
    GitHub:
    iBa4x
    so if that might true I should make spawnpoint rather than teleport
    I'll see if no-one help I'll do that
     
  8. iBa4x

    iBa4x Spider Jockey

    Messages:
    32
    GitHub:
    iBa4x
    how if i want it for the player who dead and want to respawn
     
  9. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    GamakCZ likes this.
  10. iBa4x

    iBa4x Spider Jockey

    Messages:
    32
    GitHub:
    iBa4x
  11. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    No need to replace anything, $event is PlayerRespawnEvent
     
  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.