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

Teleporting a player to a position error

Discussion in 'Development' started by rektpixel, Oct 5, 2017.

  1. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    I'm trying to teleport the $sender to the cords displayed in the code below:
    PHP:
    <?php
    namespace itsmemes\ipe;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\utils\Config;

    class 
    Main extends PluginBase implements Listener{
        private 
    $config;
     
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args) : bool{
            switch (
    $command->getName()) {
                case 
    "bcastle":
                if(
    $sender->hasPermission("bcastle.use"));
                
    $sender->sendMessage("§e[NPC] §7: §eManager: §fHave fun bouncing!");
                
    $x = [-26];
                
    $y = [53];
                
    $z = [863];
                
    $sender->teleport($x$y$z);
            }
        }
    }
    but when I run the command /bcastle this error apears in console:
    Code:
    [22:11:59] [Server thread/CRITICAL]: Unhandled exception executing command 'bcastle' in bcastle: Argument 1 passed to pocketmine\Player::teleport() must be an instance of pocketmine\math\Vector3, array given, called in C:\Users\Admin\Creative Cloud Files\Desktop\PrymePE Test Server\plugins\BoucyCastleCheck\src\itsmemes\ipe\Main.php on line 32
    [22:11:59] [Server thread/CRITICAL]: TypeError: "Argument 1 passed to pocketmine\Player::teleport() must be an instance of pocketmine\math\Vector3, array given, called in C:\Users\Admin\Creative Cloud Files\Desktop\PrymePE Test Server\plugins\BoucyCastleCheck\src\itsmemes\ipe\Main.php on line 32" (EXCEPTION) in "src/pocketmine/Player" at line 3596
    [22:11:59] [Server thread/DEBUG]: #0 BoucyCastleCheck/src/itsmemes/ipe/Main(32): pocketmine\Player->teleport(array Array(), array Array(), array Array())
    [22:11:59] [Server thread/DEBUG]: #1 src/pocketmine/command/PluginCommand(58): itsmemes\ipe\Main->onCommand(pocketmine\Player object, pocketmine\command\PluginCommand object, string bcastle, array Array())
    [22:11:59] [Server thread/DEBUG]: #2 src/pocketmine/command/SimpleCommandMap(241): pocketmine\command\PluginCommand->execute(pocketmine\Player object, string bcastle, array Array())
    [22:11:59] [Server thread/DEBUG]: #3 src/pocketmine/Server(1966): pocketmine\command\SimpleCommandMap->dispatch(pocketmine\Player object, string bcastle)
    [22:11:59] [Server thread/DEBUG]: #4 src/pocketmine/Player(2151): pocketmine\Server->dispatchCommand(pocketmine\Player object, string bcastle)
    [22:11:59] [Server thread/DEBUG]: #5 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(219): pocketmine\Player->chat(string /bcastle)
    [22:11:59] [Server thread/DEBUG]: #6 src/pocketmine/network/mcpe/protocol/CommandRequestPacket(47): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleCommandRequest(pocketmine\network\mcpe\protocol\CommandRequestPacket object)
    [22:11:59] [Server thread/DEBUG]: #7 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(91): pocketmine\network\mcpe\protocol\CommandRequestPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    [22:11:59] [Server thread/DEBUG]: #8 src/pocketmine/network/mcpe/protocol/BatchPacket(115): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\CommandRequestPacket object)
    [22:11:59] [Server thread/DEBUG]: #9 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(91): pocketmine\network\mcpe\protocol\BatchPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    [22:11:59] [Server thread/DEBUG]: #10 src/pocketmine/Player(3023): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    [22:11:59] [Server thread/DEBUG]: #11 src/pocketmine/network/mcpe/RakLibInterface(143): pocketmine\Player->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    [22:11:59] [Server thread/DEBUG]: #12 src/raklib/server/ServerHandler(97): pocketmine\network\mcpe\RakLibInterface->handleEncapsulated(string 192.168.8.105:51981, raklib\protocol\EncapsulatedPacket object, integer 0)
    [22:11:59] [Server thread/DEBUG]: #13 src/pocketmine/network/mcpe/RakLibInterface(82): raklib\server\ServerHandler->handlePacket()
    [22:11:59] [Server thread/DEBUG]: #14 src/pocketmine/network/Network(89): pocketmine\network\mcpe\RakLibInterface->process()
    [22:11:59] [Server thread/DEBUG]: #15 src/pocketmine/Server(2498): pocketmine\network\Network->processInterfaces()
    [22:11:59] [Server thread/DEBUG]: #16 src/pocketmine/Server(2252): pocketmine\Server->tick()
    [22:11:59] [Server thread/DEBUG]: #17 src/pocketmine/Server(2131): pocketmine\Server->tickProcessor()
    [22:11:59] [Server thread/DEBUG]: #18 src/pocketmine/Server(1713): pocketmine\Server->start()
    [22:11:59] [Server thread/DEBUG]: #19 src/pocketmine/PocketMine(556): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string phar://C:/Users/Admin/Creative Cloud Files/Desktop/PrymePE Test Server/PocketMine-MP.phar/, string C:\Users\Admin\Creative Cloud Files\Desktop\PrymePE Test Server\, string C:\Users\Admin\Creative Cloud Files\Desktop\PrymePE Test Server\plugins\)
    [22:11:59] [Server thread/DEBUG]: #20 C:/Users/Admin/Creative Cloud Files/Desktop/PrymePE Test Server/PocketMine-MP.phar(1): require(string phar://C:/Users/Admin/Creative Cloud Files/Desktop/PrymePE Test Server/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
    
    I have no idea what to do I'm not great at php, please help
    thanks
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    :facepalm: did you even read the error??
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Player.php#L3626
     
    WinterBuild7074 and Thunder33345 like this.
  3. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    :facepalm:
    "Argument 1 passed to pocketmine\Player::teleport() must be an instance of pocketmine\math\Vector3, array given"
     
    iiFlamiinBlaze likes this.
  5. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Don't put coordinates to array :D
     
  6. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    You must do:
    PHP:
     $player->teleport(new \pocketmine\math\Vector3(-2653863)); 
    teleport() needs an Vector3, not an Array ;D
     
    Levi and rektpixel like this.
  7. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    If everyone gives up on writting plugins because of one error, would we still be in the place we were?
     
  8. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    There isn't any need to put $x, $y and $z in an array, they can just be plain integers.
    PHP:
    $x = -26;
    $y 53;
    $z 863;
    $player->teleport(new Vector3($x$y$z));

    //OR

    $coords = [-2653863];
    $player->teleport(new Vector3(...$coords));
     
    rektpixel and jasonwynn10 like this.
  9. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    stop telling him to learn the php seen you made lots of mistakes you must yourself learn the php.
     
    Levi, EdwardHamHam, Kyd and 4 others like this.
  10. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    agreed ;)
     
    rektpixel and Marabou like this.
  11. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    I would love to learn but where or how do I learn. I learn alot by posting threads like these because of helpful people who take the time to answer them. I do understand that a lot of people on pmmp are full plugin developers and ones who fully understand what they're doing but is it not ok to ask about some nooby errors from people like me who aren't as capable and as knowledgable as others at php?
     
    Last edited: Oct 6, 2017
    Kyd, QuiverlyRivalry and Marabou like this.
  12. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    By writing plugins he's learning php and pocketmine api
     
  13. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    Rude... you learn something by doing it!
     
  14. iiFlamiinBlaze

    iiFlamiinBlaze Witch

    Messages:
    59
    GitHub:
    iiflamiinblaze
    Look at other people’s plugins, don’t copy but learn the methods and such. Also look at PocketMine-MP’s code for methods as well. You could also learn part of OOP.
     
  15. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Rude? Why was that rude?
     
  16. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    I already know the php. Now everyone thinks I'm the rude person? :mad:
     
    GodWeedZao likes this.
  17. iiFlamiinBlaze

    iiFlamiinBlaze Witch

    Messages:
    59
    GitHub:
    iiflamiinblaze
    Yep, because the way you said it was rude
     
    EdwardHamHam likes this.
  18. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    How was it not?
    You started off as not knowing much, and asked me and others for help a lot. Almost all of us do, and you can't blame others for doing the same thing.
     
  19. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    I'm very sorry for my rude reply, I'll be more careful next time.
     
    Last edited: Oct 6, 2017
    GodWeedZao 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.