Hello, I would like to do something like a Pitchout game, but I don't know how to set the knockback: PHP: public function onDamage(EntityDamageEvent $ev) { $damaged = $ev->getEntity(); if($ev instanceof EntityDamageByEntityEvent){ $player = $ev->getDamager(); $entity = $ev->getEntity(); $level = $player->getLevel(); if($entity instanceof Player && $player instanceof Player){ if($ev->getEntity()->getLevel()->getName() == "pitchout") { if($player->getInventory()->getItemInHand()->getId() == 269){ $ev->setDamage(0); $ev->setKnockBack(0); } } } } } By using this, the player is sending in the air How to do to don't get send in the air ? Thanks
Why not just cancel the event if you don't want the player to be damaged or knocked back? PHP: public function onDamage(EntityDamageEvent $ev) { $damaged = $ev->getEntity(); if($ev instanceof EntityDamageByEntityEvent) { $player = $ev->getDamager(); $entity = $ev->getEntity(); $level = $player->getLevel(); if($entity instanceof Player && $player instanceof Player){ if($ev->getEntity()->getLevel()->getName() == "pitchout") { if($player->getInventory()->getItemInHand()->getId() == 269){ $ev->setCancelled(true); } } } } }
May thoughts exactly and then if he still wants to damage the player just use like $entity->setHealth($entity->getHealth - 1);
Do you know PushMe game? I want to the player get knockback just on x or on z, not on y, i don't know if you understand me
I see what you're saying, you want to throw them out of the arena when they get hit by a wood shovel. My advice would be to teleport them out.
Hmm, the only thing I can think of is to set the player's motion. PHP: public function onDamage(EntityDamageEvent $ev) { $damaged = $ev->getEntity(); if($ev instanceof EntityDamageByEntityEvent) { $player = $ev->getDamager(); $entity = $ev->getEntity(); $level = $player->getLevel(); if($entity instanceof Player && $player instanceof Player){ if($ev->getEntity()->getLevel()->getName() == "pitchout") { if($player->getInventory()->getItemInHand()->getId() == 269){ $player->setMotion(new Vector3($player->motionX + 2, $player->motionY + 0, $player->motionZ + 2)); } } } } } Make sure you include this as well: PHP: use pocketmine\math\Vector3;
That's probably better since it makes the game feel more realistic, instead of having the player teleported out. I think the next step would be to somehow send the player that was hit off in the direction that they were hit instead of moving them two blocks over.
dont forget to cancel the event too if you don't want the players to be damaged or have the normal knockBack
Hum.. this code is fonctionnal but your code is fonctionnal only that in one sense can you help me for use this code for it to be all the senses ??
for you'r pitchOut i recommanded you to use in PlayerDeathEvent $player->teleportImmediate(Vector3 $pos, $yaw, $pitch);
$from = $event->getFrom(); $to = $event->getTo(); $entity->setMotion((new Vector3($to->x - $from->x, $to->y - $from->y, $to->z - $from->z))->multiply(5));