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

teleport() with args

Discussion in 'Development' started by b3st_Thunder78, Jul 4, 2019.

  1. b3st_Thunder78

    b3st_Thunder78 Spider Jockey

    Messages:
    38
    Hello,
    I would like to have the player entered after the command (/ trolltp <player>) so that the player is teleported to the specific location / position.
    PHP:
                        $playername $args[0];
                        
    $pos = new Position(2432310023);
                        
    $playername->teleport($pos);
    Can plz help me?

    Sry for my bad english xD
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    $playername is a string. Use $server->getPlayerExact($playername) to get the Player instance. Then you can call teleport() on that Player instance.
     
  3. b3st_Thunder78

    b3st_Thunder78 Spider Jockey

    Messages:
    38
    how do I have to define $ server? -
     
  4. b3st_Thunder78

    b3st_Thunder78 Spider Jockey

    Messages:
    38
    ^the console eczeption
    Code:
    Error: "Call to a member function teleport() on string" (EXCEPTION) in "plugins/Troll Plugin/src/bymbc/Main" at line 137
     
  5. Gianluxx

    Gianluxx Slime

    Messages:
    94
    GitHub:
    Gianluxx
    if(($player = $this->getServer()->getPlayer($args[0])) !== null){
    $pos = new Position(24323, 100, 23);
    $player->teleport($pos);
    }else{
    #player is not online
    }
     
  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.