Solved How do you make someone teleport using PlayerMoveEvent?

Discussion in 'Help' started by esh123cookie, Sep 23, 2021.

  1. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    103
    GitHub:
    esh123cookie
    PHP:
        public function TeleportToArea($player) {
               
    $world $this->getPlugin()->getServer()->getLevelByName("Location");
               
    $player->teleport($world->getSafeSpawn());
          
    $player->teleport(new Vector3(34415532900));
        }
        
        public function 
    onPlayerMove(PlayerMoveEvent $event) : void{
            
    $player $event->getPlayer();
            
    $level $player->getLevel();
            
    $X $player->getX();
            
    $Y $player->getY();
            
    $Z $player->getZ();
     
            if(
    23 == $X and "-19" == $Z and $this->getPlugin()->getServer()->getLevelByName("world") == $level) {
               
    $this->TeleportToArea($player);
          }
    }
    This is the code I have, but when I run this code nothing happens.
     
  2. minijaham

    minijaham Zombie Pigman

    Messages:
    749
    GitHub:
    minijaham
    XYZ can be a float. (https://github.com/pmmp/PocketMine-...dc9/src/pocketmine/level/Location.php#L35-L38)

    Try dumping $X, $Y, and $Z.
     
    Agent likes this.
  3. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    103
    GitHub:
    esh123cookie
  4. minijaham

    minijaham Zombie Pigman

    Messages:
    749
    GitHub:
    minijaham
    What did you get from dumping them?
     
    Agent likes this.
  5. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    103
    GitHub:
    esh123cookie
    I got my xyz cords, but as soon as put that into an if statement to check for the specific cords, nothing happens
     
  6. minijaham

    minijaham Zombie Pigman

    Messages:
    749
    GitHub:
    minijaham
    Answer my question please.
    From what I’m assuming, you got a float which you put for your coordination, but you can’t access it again because the float was too intense
     
    Agent and Axon like this.
  7. Axon

    Axon Zombie

    Messages:
    274
    Try changing your If statement to this
    PHP:
    if($X == 23 and $Z == -19 and $level->getName() == "world")
     
    Agent likes this.
  8. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    103
    GitHub:
    esh123cookie
    Yes
     
  9. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    103
    GitHub:
    esh123cookie
    Just tried, didn't work
     
  10. Axon

    Axon Zombie

    Messages:
    274
    Add echo statements every where.
    Eg:
    Echo(“1”) and so on.
    Add one before the if statement
    After the if statement
    And so on
     
  11. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    103
    GitHub:
    esh123cookie
    I've already tried that using logger, it just doesn't run the part of the code because the if statement is never triggered.
     
  12. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    103
    GitHub:
    esh123cookie
    PHP:
       public function TeleportToWorld(Player $player) {
               
    $world $this->getPlugin()->getServer()->getLevelByName("TeleportWorld");
               
    $player->teleport($world->getSafeSpawn());
          
    $player->teleport(new Vector3(34415532900));
        }
        
        public function 
    warpFromSpawn(Player $playerfloat $xfloat $z) {
            
    $X $player->getX();
            
    $Y $player->getY();
            
    $Z $player->getZ();
            
    $level $player->getLevel();
            if(
    $X == $x and $Z == $z and $level->getName() == "world") {
               
    $this->TeleportToWorld($player);
            }
        }
        
        public function 
    onPlayerMove(PlayerMoveEvent $event) : void{
            
    $player $event->getPlayer();
            
            
    $player->sendMessage($player->getX() . $player->getZ());
     
            
    $this->warpFromSpawn($player23, -19);
            
    $this->warpFromSpawn($player24, -19);
            
    $this->warpFromSpawn($player25, -19);
            
    $this->warpFromSpawn($player26, -19);
            
            
    $this->warpFromSpawn($player23, -18);
            
    $this->warpFromSpawn($player24, -18);
            
    $this->warpFromSpawn($player25, -18);
            
    $this->warpFromSpawn($player26, -18);
        }
    This is the code for the process
     
  13. Axon

    Axon Zombie

    Messages:
    274
    Separate your if functions.
    Eg:
    If(XOne){
    Echo(“1”);
    If(ZTwo){
    echo(“2”);
    }
    }

    This is going to tell us which if function isn’t working
     
  14. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    103
    GitHub:
    esh123cookie
    Ill run it again and send you the console message
     
    Axon likes this.
  15. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    103
    GitHub:
    esh123cookie
    PHP:
    [18:31:45] [Server thread/NOTICE]:
    [
    18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81
    [18:31:47] [Server thread/NOTICE]: line 81

    PHP:
            $this->plugin->getServer()->getLogger()->notice("line 81");
            if(
    $X == $x and $Z == $z and $level->getName() == "world") {
            
    $this->plugin->getServer()->getLogger()->notice("line 83");
               
    $this->TeleportToPvP($player);
            
    $this->plugin->getServer()->getLogger()->notice("line 85");
    This is what happens, no 83 or 85 line was noticed, only 81 was
     
  16. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    103
    GitHub:
    esh123cookie
    ^
     
  17. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    103
    GitHub:
    esh123cookie
    This was while walking ontop of those cords that should teleport me
     
  18. Axon

    Axon Zombie

    Messages:
    274
    Separate the if function, Instead of if(X and Y)
    Type
    If(x){
    echo(“h”)
    If(y){
    Echo(“z”)
    }}
     
  19. minijaham

    minijaham Zombie Pigman

    Messages:
    749
    GitHub:
    minijaham
    Thats not the answer I wanted. I asked what you got from dumping the coordinates?
     
    Axon likes this.
  20. Axon

    Axon Zombie

    Messages:
    274
    If your coords are correct, Are you sure you are on the correct world?
     
    Kyd likes this.

Share This Page

  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.