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

Teleport player to coordinates in different level/world

Discussion in 'Development' started by BouncyJeffer, Apr 20, 2017.

  1. BouncyJeffer

    BouncyJeffer Spider Jockey

    Messages:
    39
    GitHub:
    bouncyjeffer
    I have a command registered as "/hub", and whenever the command is ran it'll teleport the player to preset coordinates, however if a player is in a different world it'll just teleport them to the coordinates in the same level. Does anyone know how to teleport the player to the coordinates in a specific level?
    Thank you in advance.
     
  2. ICU

    ICU Silverfish

    Messages:
    15
    Try

    PHP:
    'world' => $location->getLevel()->getFolderName(),
    It is likely that you're using:

    PHP:
    'world' => $location->getLevel()->getName(),
    But Idk cuz no code lol, but I hope that helps :)
     
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    What have you attempted?
     
  4. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    PHP:
    //$level can be gotten by two method
    //1
    $level $player->getLevel();
    //2
    $level $this->getServer()->getLevelByName("WORLDNAME");
    $pos = new Position($x $y $z $level);
    $player->teleport($pos);
     
  5. BouncyJeffer

    BouncyJeffer Spider Jockey

    Messages:
    39
    GitHub:
    bouncyjeffer
    I'll try it! I was trying
    PHP:
                $player $this->getServer()->getPlayer($sender->getName());
                
    $player->teleport(new Vector3(26364789));
                
    $sender->sendMessage(TextFormat::GREEN."Welcome to the hub!");
                
    $sender->sendPopup(TextFormat::YELLOW."Teleporting...");
     
  6. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    $player is useless
    IF you have check $sender is an instanceof Player
     
  7. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    It's not useless and you DO NOT have to check if it is instanceof player, but it is recommended though because the player might be offline.
     
    jasonwynn10 likes this.
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    This thread is missing context, and the above debate is based on much assumption.
     
    jasonwynn10 likes this.
  9. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Have you tried it yet? In PocketMine, there are several different Objects you can use to define where to teleport the player. I'll try to give you a description of each.

    Vector3- This is a simple X, Y, Z coordinate. I hope I don't need to explain it too much. Vector3 is the base of many of the options I'll explain below.
    Position- A Position is defined with 4 parameters instead of the 3 in Vector3. Position has a Level parameter that can allow you to define not only the coordinates, but also the Level that those coordinates are in.
    Location- Location has 6 parameters: X, Y, Z, Yaw, Pitch, and Level. Yaw and Pitch are the vertical and horizontal angles that players are looking. With Location, you can teleport players not only to a certain position in a Level, but also set the angle they are looking.

    In this case, I believe Position is the best option.
     
  10. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    A Location is a Position, and a Position is a Vector3.
    You also do not have to unnecessarily use Vector3, since there is an extra cost of getting a level and having PocketMine to parse it. While the performance cost is low, also take debugging cost into consideration -- you just increase the chance of having bugs by doing unnecessary things.
    (Gaming is unnecessary. Uninstall MCPE and PocketMine, and no plugins no bugs no worries!)
     
    Last edited: Apr 24, 2017
  11. BouncyJeffer

    BouncyJeffer Spider Jockey

    Messages:
    39
    GitHub:
    bouncyjeffer
    Ahh, thanks for the explanation! Really appreciated!
     
  12. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    teleport() does account for Locations
     
  13. Jakobxae@1

    Jakobxae@1 Creeper

    Messages:
    1
    to teleport the player to the coordinates in a specific level or locatiom here is the command
    /tp [target player] <x> <y> <z>
    here you need to replace [target player] with your username
    and the x, y and z set of coordinates must be typed with a space in between each.
     
  14. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Could you not? This thread is from THREE years ago.
     
    Agent likes this.
  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.