Hello, How could i detect when a player is not using PlayerMoveEvent? whitout using some coordinates and higher, lower etc..
PHP: private $movePlayers = [];public function onMove(PlayerMoveEvent $event) : void{ $player = $event->getPlayer(); $this->movePlayers[$player->getName()] = time();}public function isMoveExecuted(Player $player) : bool{ if(!isset($this->movePlayers[$player->getName()])){ return false; } $timeDiff = time() - $this->movePlayers[$player->getName()]; if($timeDiff > 0.1){ return false; } return true;}
This I would also like to know, I was looking for a function like isMoving but how complicated it is, I do not know.. ty
sorry my english is not so good.. I asked if there was any way to detect if a player is not moving but I used the event as the word, I'm sorry
Use Entity::$lastYaw and Entity::$lastPitch and test them against the current yaw and pitch via a task. Pocketmine certainly isn't rocket science.
Can you tell us why you want to check that? The answer can differ based on time difference between two movements.
What I'd suggest is have an array to store the player's ticksLived during a movement (and don't forget to remove the entries on player quit). PHP: /** @var int[] */private $playerMovements = []; Then update the property whenever player moves: PHP: public function onPlayerMove(PlayerMoveEvent $event) : void{ if(!$event->getFrom()->equals($event->getTo())){ $player = $event->getPlayer(); $this->playerMovements[$player->getId()] = $player->ticksLived; }} And have a function that returns whether the player moved during the last tick. PHP: public function isMoving(Player $player, int $tick_diff = 1) : bool{ $id = $player->getId(); return isset($this->playerMovements[$id]) && $player->ticksLived - $this->playerMovements[$id] <= $tick_diff;} Reverse the retval to check whether the player is not moving.