Hi, I wanted to teleport player in PlayerMoveEvent PHP: $player->teleport(new Vector3(123, 456, 789)); I wanted to teleport to same level (For example coordinates is 123, 456, 789. Is this code correct? I think it's wrong... I think maybe i need to call out level first... but how? Pls help
Wait... just setTo? Then.... where can I place $player? Like this? PHP: $player->setTo($vector3) Sorry, im quite new to teleport API... xD
You don't need to place $player. The $event itself is about $player. PocketMine will teleport $player away after the event has finished being handled.
Also, if you wanted to use the teleport() function its: PHP: $level = $player->getLevel()->getName();$pos = new Position($x, $y, $z, $this->getServer()->getLevelByName($level));$player->teleport($pos);
Code: Argument 1 passed to pocketmine\event\player\PlayerMoveEvent::setTo() must be an instance of pocketmine\level\Location, instance of pocketmine\math\Vector3 given, called in phar:///plugins/MinedoxCore-MegaPvP_v1.0.0.phar/src/MinedoxCore/MinedoxCore.php on line 195 and defined" (E_RECOVERABLE_ERROR) in "/src/pocketmine/event/player/PlayerMoveEvent" at line 52 I got this error in console... Is it mean I need to code it like this?: PHP: if($e instanceof Vector3){ $pos = new Vector3(-1118, 60, -997); $e->setTo($pos); }
PHP: if($e instanceof Vector3){ $pos = new Vector3(-1118, 60, -997); $e->setTo($pos); } Hmmm, I coded and tested this code, it doesn't show any error again... but it doesn't teleport player... LOL I confirm there's something wrong here... pls help...
Change it to: PHP: if($e instanceof Vector3){ $pos = new Position(-1118, 60, -997, $level); //$level is a level INSTANCE, not name $e->setTo($pos); } Read the error next time