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

Solved Teleportation using Position.php sucks :/

Discussion in 'Development' started by Kyd, Aug 20, 2017.

  1. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    I have class Arena.php and Main.php in Main.php I am registering
    spawns etc
    PHP:
    public function onEnable(){
    $this->setArenasData();
    }

    public function 
    setArenasData(){
        
    $this->areny["TowerFall"] = ['lobby' => new Position(-161810$this->getServer()->getLevelByName("mm-towerfall")),
            
    'level' => $this->getServer()->getLevelByName("mm-towerfall"),
            
    '1spawn' => new Vector3(7142, -4),
            
    '2spawn' => new Vector3(2314210),
            
    '3spawn' => new Vector3(915113),
            
    '4spawn' => new Vector3(2115121),
            
    '5spawn' => new Vector3(161516)];
    }
    in class Arena.php
    I have in constructor
    PHP:
    /** var Main $plugin */
    $this->data $plugin->areny[$id];
    It make me able to get something from $this->areny in Arena.php
    now I trying to teleport player like this:
    PHP:
    $player->teleport($this->data['lobby']); // new Position(-16, 181, 0, $this->getServer()->getLevelByName("mm-towerfall");
    Player get teleported, but he dont move to world "mm-towerfall" it only teleport him to coords -16, 181, 0

    I tried to teleport player using Position.php without getting position from $this->data and it worked perfectly, so what is bad?
    PHP:
    $player->teleport(new Position(-161810Server::getInstance()->getLevelByName("mm-towerfall"))); //Working :v
    Level mm-towerfall is 100% loaded.
     
    Last edited: Aug 20, 2017
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You suck at passing a Position parameter to Entity::teleport() :/
    Send the output of var_dump($this->data["lobby"])
     
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Code:
    object(pocketmine\level\Position)#11192 (4) {
      ["level"]=>
      NULL
      ["x"]=>
      int(-16)
      ["y"]=>
      int(181)
      ["z"]=>
      int(0)
    }
    
    I do not understand why level is null, it is loaded
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Before calling setArenasData(), var_dump(Server::getInstance()->isLevelLoaded("mm-towerfall"))
     
  5. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Ah, it happened because I called $this->setArenasData() before I loaded the world :D
     
  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.