Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Get Players between 2 Positions

Comments in 'Plugin Development' started by JackboyPlay, Feb 14, 2016.

  1. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Hello how can I get the Player Count between 2 Positions?
  2. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    You should loop into online players.
    example:

    PHP:
    $pos1 = \pocketmine\level\Position;
    $p1x $pos1->getFloorX();
    $p1y $pos1->getFloorY();
    $p1z $pos1->getFloorZ();

    $pos2 = \pocketmine\level\Position;
    $p2x $pos2->getFloorX();
    $p2y $pos2->getFloorY();
    $p2z $pos2->getFloorZ();

    //this is to make sure the 2 positions are in the same level, you can also delete this if you already know they are
    if ($pos1->getLevel()->getName() != $pos1->getLevel()->getName())
        return;

    /** var int */
    $count 0;

    foreach (\
    pocketmine\Server->getOnlinePlayers() as $p/** var \pocketmine\Player */) {

        
    $x $p->getFloorX();
        
    $y $p->getFloorY();
        
    $z $p->getFloorZ();

        if (
    $p->getLevel()->getName() == $pos1->getLevel()->getName() and (($x <= max($p1x$p2x)) and ($x >= min($p1x$p2x))) and /*same thing for Y*/ and /*same thing for Z*/)
            
    $count++;
    }
    Last edited: Feb 14, 2016
    JackboyPlay likes this.
  3. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Thanks :D
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    "Between two positions" can mean a lot. It can mean an aligned cuboid. It can mean a sphere where the positions are the two poles. It can also mean two players who are directly between thosetwo positions.
    applqpak likes this.
  5. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Between 2 Positions in a Quadrat
  6. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    The \pocketmine\Level\Position doesnt work with what must I replace that?
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    https://php.net/new
  8. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Read that page. It helps you fix it.
  10. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Ok I didn't think so... Can you specified a line number or so on?
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You should change it to
    PHP:
    $position = new \pocketmine\level\Position;
  12. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Oh xD
  13. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Is whats getLeve->getName() right?
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What @Svile meant is that $pos1 and $pos2 are instances of Position. Level->getName() is a string.
  15. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    But the Server crashes
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Don't tell me that it crashes. Tell me how it crashes, and point out the lines around the error.
    Hotshot_9930 likes this.
  17. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Where I must put the coordinates and how can I get the Players?

Share This Page

Advertisement