Closed ghost closed 8 years ago
You need the subevent EntityDamageByEntityEvent in the EntityDamageEvent public funktion knockbackChicken(EntityDamageEvent $event){ $entity = $event->getDamager; If($event instanceof EntityDamageByEntityEvent){ $damager = $event->getDamager; //knockbackChicken code here }}
*function
I will try it!
`
if ($event->getEntity()->getLevel()->getName()=="ProjektA"){
if ($event instanceof EntityDamageByEntityEvent) {
if ($event->getEntity() instanceof \pocketmine\entity\Living){
if ($event->getEntity()->getName()=="Chicken"){
$damager = $event->getDamager();
$this->getLogger()->info("YES");
$event->getEntity()->setMotion(new Vector3(2 * (-sin($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_PI)), -sin($damager->pitch / 180 * M_PI), 2 * (cos($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_1_PI))));
}
}
`
i have also this :c
you need to get the entity before the EntityDamageByEntityEvent
`$entity = $event->getEntity(); if ($entity instanceof \pocketmine\entity\Living){ if ($event instanceof EntityDamageByEntityEvent) {
if ($event->getEntity()->getName()=="Chicken"){
$damager = $event->getDamager();
$this->getLogger()->info("YES");
$entity->setMotion(new Vector3(2 * (-sin($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_PI)), -sin($damager->pitch / 180 * M_PI), 2 * (cos($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_1_PI))));
}
}`
It does not work. :/
you need to get the entity before the EntityDamageByEntityEvent
`if ($event->getEntity() instanceof \pocketmine\entity\Living) { if ($event->getEntity()->getName() == "Chicken") { $entity = $event->getEntity(); if ($event instanceof EntityDamageByEntityEvent) {
$damager = $event->getDamager();
$this->getLogger()->info("YES");
$entity->setMotion(new Vector3(2 * (-sin($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_PI)), -sin($damager->pitch / 180 * M_PI), 2 * (cos($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_1_PI))));
}
}`
I don't understand what you mean. It works by a player but not by the chicken. I also don't understand what you mean with "$entity = $event->getDamager;" Because the entity who should get the knockback is not the Entity who hit the chicken.
I should delete method 'setMotion()' because it affects moving
Wow that is a good bugfixing!
How can I set motion to the Entities. I want use a chicken as a football, so i must raise the knockback. A player gets knockback, but not the chicken :c I used the EntityDamageEvent
$event->getEntity()->setMotion(new Vector3(2 * (-sin($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_PI)), -sin($damager->pitch / 180 * M_PI), 2 * (cos($damager->yaw / 180 * M_PI) * cos($damager->pitch / 180 * M_1_PI))));