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

Get Player position

Discussion in 'Development' started by HittmanA, Nov 23, 2016.

  1. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    My question is simple: How can you get a player's position in a PocketMine plugin?
     
  2. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    The player class is a sub class of Position (Entity extends position, Player is a sub class of Entity) meaning the player itself can be passed as a position object and you can use the x, y, z and level properties.

    Alternatively you can use Player::getPosition() which returns a Position object.
     
    Primus, HittmanA, Irish and 1 other person like this.
  3. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    Does it return it as an array like [1 (x),10 (y),100 (z)]
     
  4. falk

    falk Slime Poggit Reviewer

    Messages:
    75
    GitHub:
    falkirks
    HittmanA, Jack Noordhuis and ifvictr like this.
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Learn OOP. Passing structured data as objects is almost always better than passing as arrays. Although PHP supports associative arrays, it is better to use them as (dynamic size and keySet) maps instead of structured objects.
     
    Michael, HittmanA, falk and 1 other person like this.
  6. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    use this
    PHP:
    round($player->getX()) . " §e/ " round($player->getY()) . " / " round($player->getZ()) . "'");
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    This does not give you the player position. This gives you the human-readable text that reflects the position, but not the position itself. You can't carry out calculations on the position with this.
    What is that?
     
    InspectorGadget likes this.
  8. Reid

    Reid Spider Jockey

    Messages:
    43
    That's like to make the chat colorful?
     
  9. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    use TextFormat!!!
     
  10. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    The thread is asking how to get a position. It is not asking how to display the coordinates. Nor is it asking how to display the coordinates, much less display colorfully, especially when only Y and Z are colored.
     
  11. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    §e is yellow color
     
  12. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Yes, he knows. But this thread is not asking how to get a human readable string with colors. It asks how to get the Position/Vector3 object or the position ints of a player.
     
  13. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Lets say you have to defined $player already
    $x = $player->getX(); Gets X Position
    $y = $player->getY(); Gets Y Position
    $z = $player->getZ(); Gets Z Position
    $level = $player->getLevel(); Gets The Players Current Level
     
    HimbeersaftLP likes this.
  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.