Get Players between 2 Positions

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

1. Offline

JackboyPlayActive Member

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

SvileActive Member

Joined:
Mar 30, 2015
Posts:
239
Minecraft User:
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 areif (\$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. Offline

JackboyPlayActive Member

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

PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,230
Plugins:
11
Minecraft User:
"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. Offline

JackboyPlayActive Member

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

JackboyPlayActive Member

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

PEMapModderNotable MemberPlugin Developer

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

JackboyPlayActive Member

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

PEMapModderNotable MemberPlugin Developer

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

JackboyPlayActive Member

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

PEMapModderNotable MemberPlugin Developer

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

JackboyPlayActive Member

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

JackboyPlayActive Member

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

PEMapModderNotable MemberPlugin Developer

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

JackboyPlayActive Member

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

PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,230
Plugins:
11
Minecraft User:
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. Offline

JackboyPlayActive Member

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