teleport not work in PlayerRespawnEvent

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

  1. iBa4x

    iBa4x Silverfish

    Messages:
    24
    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:
    30
    GitHub:
    xenophilicy
    Vector3 takes exactly 3 arguments, you gave it 4. If you want a level, use the Position class.
     
  3. iBa4x

    iBa4x Silverfish

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

    Xenophilicy Spider Jockey

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

    iBa4x Silverfish

    Messages:
    24
    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 Spider Jockey

    Messages:
    33
    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 Silverfish

    Messages:
    24
    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 Silverfish

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

    wolfdale Zombie Pigman

    Messages:
    403
    GamakCZ likes this.
  10. iBa4x

    iBa4x Silverfish

    Messages:
    24
    GitHub:
    iBa4x
  11. wolfdale

    wolfdale Zombie Pigman

    Messages:
    403
    No need to replace anything, $event is PlayerRespawnEvent
     

Share This Page

  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.