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.
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
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);
I'll try it! I was trying PHP: $player = $this->getServer()->getPlayer($sender->getName()); $player->teleport(new Vector3(263, 64, 789)); $sender->sendMessage(TextFormat::GREEN."Welcome to the hub!"); $sender->sendPopup(TextFormat::YELLOW."Teleporting...");
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.
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.
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!)
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.