Hello, I'm learning php I would like to know how to count height of blocks that the player has dropped. this is not working PHP: public function onDamage(EntityDamageEvent $event){ $player = $event->getEntity(); $this->jump[$player->getY()] = new Position(round($player->getY())); if($event->getCause() === EntityDamageEvent::CAUSE_FALL){ $this->fall[$player->getY()] = new Position(round($player->getY())); $result = $this->fall[$player->getY()] - $this->jump[$player->getY()]; $player->sendMessage("You fell out of ".$result." blocks");}}
In addition, according to https://github.com/pmmp/PocketMine-...c8b70a/src/pocketmine/entity/Entity.php#L1166, $entity->fallDistance should not have been reset yet when EntityDamageEvent has bee ncalled.
I tried that but it doesn't work PHP: public function onMove(PlayerMoveEvent $event){ $player = $event->getPlayer(); $this->fall[$player->getFloorY()] = new Position(round($player->getFloorY())); } public function onDamage(EntityDamageEvent $event){ $player = $event->getEntity(); if($event->getCause() === EntityDamageEvent::CAUSE_FALL){ $result = $player->getY() - $this->fall[$player->getFloorY()]; $player->sendMessage("§8[§cBritz§8] ".$result." ."); }} the following error: object of class pocketmine\level\Position could not be converted to int in /plugins/hab/src/brendo/EventListener.php on line 85 :
Firstly, you clearly have no idea what you are doing because you don't know the proper parameters for the Position class. Secondly, you are trying to set an invalid position(as stated firstly) to an array by it's Y level which is incorrect logic due to more than one player being able to have the same y level. Thirdly, you will not need to use the EntityDamageEvent for what you are trying to do. Have you though through exactly how you want to calculate the player's falling height? How will you set their damage cause through an event that only triggers after they take damage which won't occur?
Why measure it twice? It's already measured internally. Why make an extra handler and waste CPU? Just use the fallDistance.