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

Not working with tp players

Discussion in 'Development' started by Hoyee, Jun 11, 2020.

  1. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    Code:
    $player->teleport(new Vector3($this->L["Location"]));
    Code:
      $this->L["Location"] = array('x'=>(int)$player->getX(),'y'=>(int)$player->getY(),'z'=>(int)$player->getZ());
    Error: "Unsupported operand types" (EXCEPTION) in "src/pocketmine/entity/Entity" at line 706

    TypeError: "Argument 2 passed to pocketmine\nbt\tag\DoubleTag::__construct() must be of the type float, array given, called in phar... . . . .src/pocketmine/entity/Entity.php on line 887" (EXCEPTION) in "vendor/pocketmine/nbt/src/tag/DoubleTag" at line 40
     
  2. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    Vector3 needs 3 optional arguments: X, Y, and Z
    You only give the X (which is an array and only one argument), and the Y and Z default to 0
    https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/math/Vector3.php#L37-L41
    Now, Pocketmine does something like this (the example array comes from the first argument is):
    Code:
    ethaniccc@ethaniccc-idot:~$ php -r 'var_dump(["x" => 0, "y" => 0, "z" => 0] - 1);'
    PHP Fatal error:  Unsupported operand types in Command line code on line 1
    
    https://github.com/pmmp/PocketMine-MP/blob/stable/src/pocketmine/entity/Entity.php#L706
    What you can do is make "$this->L["Location"]" be a Vector3 instance:
    PHP:
    $this->L["Location"] = new Vector3($player->getX(), $player->getY(), $player->getZ());
    And then teleport like this:
    PHP:
    $player->teleport($this->L["Location"]);
     
    Last edited: Jun 11, 2020
  3. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    there is no error but it doesn't work

    here is the yaml of $this->L["Location"].
    Code:
    Location: !php/object "O:23:\"pocketmine\\math\\Vector3\":3:{s:1:\"x\";d:110.9058;s:1:\"y\";d:109;s:1:\"z\";d:121.6894;}"
     
  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.