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

Teleportation using Position

Discussion in 'Development' started by rimmada16, Apr 27, 2020.

  1. rimmada16

    rimmada16 Creeper

    Messages:
    3
    GitHub:
    rimmada16
    Hello, I'm kinda new to plugin development and I have come across a problem within the plugin I am creating.

    Basically when I run the command /Mine-A ingame it's supposed to teleport the user to the set coordinates within the level "flat"
    But whenever I run the command it teleports me to the set coordinates within the level I am in

    Here is the code

    $x = 243;
    $y = 29;
    $z = 241;
    $level = $this->getServer()->getLevelByName("flat");
    $sender->teleport(new Position($x, $y, $z, $level));
    Any help would be greatly appreciated. :)
     
  2. Muhammed0232

    Muhammed0232 Spider Jockey

    Messages:
    38
    GitHub:
    Muhammed0232
    Could your level be flat?
     
  3. Muhammed0232

    Muhammed0232 Spider Jockey

    Messages:
    38
    GitHub:
    Muhammed0232
    $level = $this->getServer()->getLevelByName("flat");
    pls use load level func
     
  4. rimmada16

    rimmada16 Creeper

    Messages:
    3
    GitHub:
    rimmada16
    What is the load level function?
     
  5. Muhammed0232

    Muhammed0232 Spider Jockey

    Messages:
    38
    GitHub:
    Muhammed0232
    $this->getServer()->loadLevel("worldname");
     
  6. kriskotooBG

    kriskotooBG Spider Jockey

    Messages:
    46
    GitHub:
    kriskotoobg
    If the level ware to be unloaded, running position->getLevel() should give you a warning in your console. As shown here:
    PHP:
    /**
         * Returns the target Level, or null if the target is not valid.
         * If a reference exists to a Level which is closed, the reference will be destroyed and null will be returned.
         *
         * @return Level|null
         */
        
    public function getLevel(){
            if(
    $this->level !== null and $this->level->isClosed()){
                
    MainLogger::getLogger()->debug("Position was holding a reference to an unloaded world");
                
    $this->level null;
            }

            return 
    $this->level;
        }
    (https://github.com/pmmp/PocketMine-...100bcd0/src/pocketmine/level/Position.php#L59)
     
  7. rimmada16

    rimmada16 Creeper

    Messages:
    3
    GitHub:
    rimmada16
    So I changed it to

    $x = 243;
    $y = 29;
    $z = 241;
    $this->getServer()->loadLevel("flat");
    $level = $this->getServer()->getLevelByName("flat");
    $sender->teleport(new Position($x, $y, $z, $level));
    Yet it still doesn't work, it just teleports me to the coordinates within the level I am not to the set coordinates in the level flat. Additionally no error appears in the console so I guess it successfully loads the level "flat"
     
  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.