Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Teleport API

Comments in 'Plugin Development' started by deot, Oct 18, 2015.

  1. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    Hi, I wanted to teleport player in PlayerMoveEvent
    PHP:
    $player->teleport(new Vector3(123456789));
    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
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    use
    PHP:
    $event->setTo();
    PEMapModder and deot like this.
  3. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    PHP:
    $player->teleport($event->setTo(new Vector3(123456789)));
    Like this? ;)
  4. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No, don't teleport. Just setTo.
    PHP:
    $event->setTo($vector3);
    deot and Taha_The_Hacker like this.
  6. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Sure xD sorry i didnt notice it
  7. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    Wait... just setTo? Then.... where can I place $player? Like this?
    PHP:
    $player->setTo($vector3)
    Sorry, im quite new to teleport API... xD
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    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.
    deot likes this.
  9. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    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);
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Teleport will be reverted/overwritten if you cancel PlayerMoveEvent.
    CrazedMiner likes this.
  11. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    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(-111860, -997);
                    
    $e->setTo($pos);
                    }
  12. deot
    Offline

    deot Active Member Plugin Developer

    Joined:
    Apr 22, 2015
    Posts:
    219
    Plugins:
    1
    Minecraft User:
    deot
    PHP:
                    if($e instanceof Vector3){
                    
    $pos = new Vector3(-111860, -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...
  13. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Change it to:
    PHP:
    if($e instanceof Vector3){
                    
    $pos = new Position(-111860, -997$level); //$level is a level INSTANCE, not name
                    
    $e->setTo($pos);
                    }
    Read the error next time ;)
  14. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    An event is not an instance of Vector3.
    zombie_Power likes this.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Pass a Location? That's obvious.
    $event->setTo(new Location($x, $y, $z, $yaw, $pitch, $level));

Share This Page

Advertisement