How to teleport to an other world? I used this code but it did not work: PHP: public function onInteract(PlayerInteractEvent $this, $event){ $player = $event->getPlayer(); $name = $player->getName(); $item = $player->getInventory()->getItemInHand(); $itemid = $item->getID(); $block = $event->getBlock(); $level = $this->owner->getServer()->getLevelByName("$lvname"); if($item->getName() == C::BOLD.C::GREEN."Teleporter"){ $this->TeleportItems($player); } elseif ($item->getName() == C::BOLD . C::GREEN . "KitPvP"){ $this->MainItems($player); $lvname = KitPvP; $player->teleport($level->getSafeSpawn()); } I get this error: Code: [11:38:01] [CRITICAL]: ParseError: "syntax error, unexpected '$this' (T_VARIABLE)" (EXCEPTION) in "/plugins/Core_v0.0.1.phar/src/Core/Main" at line 123 Line 123: PHP: $level = $this->owner->getServer()->getLevelByName("$lvname");
PHP: public function onInteract(PlayerInteractEvent $event){ $player = $event->getPlayer(); $name = $player->getName(); $item = $player->getInventory()->getItemInHand(); $itemid = $item->getID(); $block = $event->getBlock(); $level = $this->owner->getServer()->getLevelByName("$lvname"); //what is $levname? Have you store any value?
PlayerInteractEvent $this, $event??? Please learn a bit of PHP. It should be: PHP: public function onInteract(PlayerInteractEvent $event) { } $this is a reserved variable in PHP, and can not be re-assigned, because it refers to the current object.
Same result. And yes I have stored: PHP: elseif ($item->getName() == C::BOLD . C::GREEN . "KitPvP"){ $this->MainItems($player); $lvname = KitPvP; $player->teleport($level->getSafeSpawn()); }
PHP: <?phpnamespace Core;use pocketmine\event\player\PlayerMoveEvent;use pocketmine\level\particle\FlameParticle;use pocketmine\plugin\PluginBase;use pocketmine\scheduler\PluginTask;use pocketmine\math\Vector2;use pocketmine\math\Vector3;use pocketmine\nbt\tag\IntTag;use pocketmine\event\Listener;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\utils\TextFormat as C;use pocketmine\Player;use pocketmine\Server;use pocketmine\event\player\PlayerDeathEvent;use pocketmine\utils\Config;use pocketmine\event\player\PlayerChatEvent;use pocketmine\event\player\PlayerJoinEvent;use pocketmine\event\player\PlayerQuitEvent;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\event\player\PlayerItemHeldEvent;use pocketmine\event\player\PlayerDropItemEvent;use pocketmine\event\block\BlockBreakEvent;use pocketmine\event\block\BlockPlaceEvent;use pocketmine\item\Item;use pocketmine\utils\TextFormat;use pocketmine\event\entity\EntityTeleportEvent;class Main extends PluginBase implements Listener { public $prefix = TextFormat::GRAY."[".TextFormat::AQUA."Lobby".TextFormat::GRAY."] "; public function onEnable(){ $this->getLogger()->info($this->prefix.C::GREEN."Enabled!"); $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->ZMusicBox = $this->getServer()->getPluginManager()->getPlugin("ZMusicBox"); } public function MainItems(Player $player){ $player->getInventory()->clearAll(); $player->getInventory()->setItem(0, Item::get(345)->setCustomName(C::BOLD.C::GREEN."Teleporter")); $player->getInventory()->setItem(2, Item::get(339)->setCustomName(C::BOLD.C::GOLD."Info")); $player->getInventory()->setItem(6, Item::get(280)->setCustomName("§l§eHide §aPlayers")); $player->getInventory()->setItem(8, Item::get(360)->setCustomName(C::BOLD.C::GREEN."Next Song")); $player->removeAllEffects(); $player->getPlayer()->setHealth(20); $player->getPlayer()->setFood(20); } public function killm(PlayerDeathEvent $event) { $event->setDeathMessage(""); } public function TeleportItems(Player $player){ //Teleport $player->getInventory()->clearAll(); $player->getInventory()->setItem(0, Item::get(399)->setCustomName(C::BOLD.C::BLUE."SkyWars")); $player->getInventory()->setItem(8, Item::get(355)->setCustomName(C::BOLD.C::RED."Back")); $player->getInventory()->setItem(4, Item::get(378)->setCustomName(C::BOLD.C::RED."Plots")); $player->getInventory()->setItem(2, Item::get(381)->setCustomName(C::BOLD.C::GREEN."KitPvP")); $player->removeAllEffects(); $player->getPlayer()->setHealth(20); $player->getPlayer()->setFood(20); } public function onJoin(PlayerJoinEvent $event){ //OnJoin $player = $event->getPlayer(); $name = $player->getName(); $ds = $this->getServer()->getDefaultLevel()->getSafeSpawn(); $player->setGamemode(0); $player->teleport($ds); $event->setJoinMessage(""); $this->MainItems($player); $player->setGamemode(0); if($player->isOP()){ $event->setJoinMessage(C::RED.$name.C::AQUA." joined the game"); } } public function onQuit(PlayerQuitEvent $event){ $player = $event->getPlayer(); $event->setQuitMessage(""); } public function onDeath(PlayerDeathEvent $event){ //OnDeath $player = $event->getPlayer(); $this->MainItems($player); $player->setGamemode(0); } public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){ $name = $sender->getName(); switch ($cmd->getName()){ case "info": if(!empty($args[0])){ if($args[0] == "ranks"){ $sender->sendMessage($this->prefix . "§aYou can buy a rank in our server website"); return true; } if($args[0] == "server"){ $sender->sendMessage($this->prefix . "§aWelcome to our server! Our server has the following MiniGames: SkyWars, KitPvP, Survival, Plots and 1vs1!"); return true; }else{ $sender->sendMessage($this->prefix. "§a/info ranks|server"); return true; } } }} public function onInteract(PlayerInteractEvent $event){ $player = $event->getPlayer(); $name = $player->getName(); $item = $player->getInventory()->getItemInHand(); $itemid = $item->getID(); $block = $event->getBlock(); $level = $this->owner->getServer()->getLevelByName("$lvname"); if($item->getName() == C::BOLD.C::GREEN."Teleporter"){ $this->TeleportItems($player); } elseif ($item->getName() == C::BOLD . C::GOLD . "Info"){ $player->sendMessage($this->prefix . "§aUsage: /info ranks|server"); } elseif ($item->getName() == C::BOLD . C::RED . "Back"){ $this->MainItems($player); } elseif ($item->getName() == C::BOLD . C::GREEN . "KitPvP"){ $this->MainItems($player); $lvname = KitPvP; $player->teleport($level->getSafeSpawn()); } elseif ($item->getName() == C::BOLD.C::RED."Plots"){ $this->MainItems($player); $lvname = Plots; $player->teleport($level->getSafeSpawn()); } elseif ($item->getName() == C::BOLD.C::BLUE."SkyWars"){ $this->MainItems($player); $lvname = SkyWars; $player->teleport($level->getSafeSpawn()); } elseif ($item->getName() == "§l§eHide §aPlayers") { $player->getInventory()->remove(Item::get(280)->setCustomName("§l§eHide §aPlayers")); $player->getInventory()->setItem(6, Item::get(369)->setCustomName("§l§eShow §aPlayers")); $player->sendMessage($this->prefix . "§cDisabled Player Visibility!"); $this->hideall[] = $player; foreach ($this->getServer()->getOnlinePlayers() as $p2) { $player->hideplayer($p2); } } elseif ($item->getName() == "§l§eShow §aPlayers"){ $player->getInventory()->remove(Item::get(369)->setCustomName("§l§eShow §aPlayers")); $player->getInventory()->setItem(6, Item::get(280)->setCustomName("§l§eHide §aPlayers")); $player->sendMessage($this->prefix . "§aEnabled Player Visibility!"); unset($this->hideall[array_search($player, $this->hideall)]); foreach ($this->getServer()->getOnlinePlayers() as $p2) { $player->showplayer($p2); } } elseif ($item->getName() == C::BOLD.C::GREEN."Next Song"){ $this->ZMusicBox->StartNewTask(); } } public function onItemHeld(PlayerItemHeldEvent $event){ $player = $event->getPlayer(); $name = $player->getName(); $item = $player->getInventory()->getItemInHand()->getID(); switch($item){ case 10: $player->getInventory()->setItemInHand(Item::get(Item::AIR, 0, 0)); $player->sendMessage($this->prefix.TextFormat::RED." You cannot use lava"); return true; case 11: $player->getInventory()->setItemInHand(Item::get(Item::AIR, 0, 0)); $player->sendMessage($this->prefix.TextFormat::RED." You cannot use lava"); return true; } }}
My problem is not $lvname yet. My problem is $this in line 123: $level = $this->owner->getServer()->getLevelByName("$lvname");
So that's why this was moved to facepalm. Can't help you much further if you don't at least know the basic syntax of PHP.