Let's say, I have an area - PHP: $x = [100,200];$z = [300,400]; How do I get the Entities within this area? I do know how to check whether a player is in the area - that is by using events. I'm trying to count the Entities in this area and display it in a FloatingTextParticle.
tried this (ps: i don't tested) PHP: $entities = 0;foreach($level->getEntities() as $ent){ if($this->isInSide($ent)){ // check if entity is in area $entities++; }}
I don't think that'll work. But you might have helped me there! This might work: PHP: <?php$lvl = Server::getInstance()->getDefaultLevel();$ents = $lvl->getEntities();foreach ($ents as $ent) {$x = $ent->getX();$z = $ent->getZ();$xx = [100,200];$zz = [300,400];if ($x() >= min($xx) && $x() <= max($xx) && $z >= min($zz) && $z <= max($zz)) {//How can I count the number of Entities INSIDE this region?//doing count($ent); would return 1, right?}}?>
PHP: public (int) $counter = 0;If ($ent instanceof \pocketmine\Player) { while ($this->counter = count($ent)) { $this->counter++; }}Echo "Entities in the region: ".$this->counter; Would this work SOF3? Thanks for helping me
look this: PHP: $entities = 0;foreach($level->getEntities() as $ent){ $entities++; // its is same that: $entities = $entities+1;}