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

Point compass on the next player

Discussion in 'Development' started by McpeBooster, May 30, 2017.

  1. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    How can i point a compass to the nearest player in the world? I dont know how to do that...
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    this shall help you
    http://forums.pocketmine.net/threads/point-compass.8630/
    to others, is there a more UPDATED method that does not require using packets directly?
    for the nearest, you can try
    PHP:
    $player getCurrentPlayer();
    $dist null;
    $closest null;
    foreach(
    getPlayersInLevel($player) as$other){
    if(
    $dist == null OR ($tmpdist $player->dist($other))<$dist){
    $closest $other
    $dist 
    $tmpdist
    }else continue;
    }
    pointCompass($player,$closest);
    Putting it in a task if you want it to update frequently
     
    NakiFx, HimbeersaftLP, Muqsit and 3 others like this.
  3. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    thx I will try
     
  4. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    the function $player->dist(); doesn't exist
     
  5. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    It's distance
     
  6. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Neither is getPlayersInLevel. It's pseudo code, which means it's more of an outline or prototype. It's not designed to be a working example.
     
    HimbeersaftLP likes this.
  7. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    He shouldve mentioned its pseudo
     
  8. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    it's my way to catching people who only know how to copy code, without UNDERSTANDING it yet not hard to be understand
    i thought getPlayersInLevel() and pointCompass() should already make it very clear since these method clearly dont exist
    my fault should have make it more obvious it's pseudo code next time
     
  9. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    I have seen that for example "point compass" pseudocode is ... but I thought that there is in Pocketmine perhaps a function with $player->dist()
     
  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.