hey, i need help. How to make a zombie and when the player gets close, the zombie moves and hits the player by code ?
PHP: if ($zombie->distance($player) < 1) { $packet = new AnimatePacket(); $packet->action = AnimatePacket::ACTION_SWING_ARM; $packet->entityRuntimeId = $zombie->getId(); $player->dataPacket($packet); $player->setHealth($player->getHealth() - 1); }
Instead of setting the player's health, a better way could be actually making the zombie entity attack the player by calling entity damage event. PHP: $zombie->attack(new EntityDamageEvent($zombie, EntityDamageEvent::CAUSE_CUSTOM, $damageValue)); This will cause the player to take knockback, which I think is better.