Hi, I'm looking for how to inflict damage to the opponent's armor that I tappe, but I can not figure out how to do this, do you have a solution? Thank you in advance ! And excuse me for my way English decricre, I am french! : P PHP: public function Tracker(EntityDamageEvent $event){ $player = $event->getEntity(); if($event instanceof EntityDamageByEntityEvent){ $damager = $event->getDamager(); $inv = $player->getInventory(); if($player->getItemInHand()->getId() == 352){ $inv->getHelmet()->setDamage($inv->getHelmet()->getDamage() + 100); } } }
Your code is correct (not. $player->getItemInHand() does not exist), except, you haven't updated the armor slots of the player. PHP: if($inv->getItemInHand()->getId() === 352){ $helmet = $inv->getHelmet(); $helmet->setDamage($helmet->getDamage() + 100); $inv->setHelmet($helmet);}
Last time I checked, PocketMine had a bug where armor didn't take damage. Correct me if I'm wrong though, my info may be outdated.
It still does. But you can code an easy plugin to manage armor durability. Just keep increasing the item's damage by 1.
OK ! it works ! But do you have a solution for that if EntityDamageEvent is canceled in the box then the code has no effect? (I do not understand how isCancelled works, is it buggy ?)
You should really set your plugin at lower priority so that other plugins and pocketmine can change or cancel the event(I think). You could do that with something like this: PHP: /** * @param EntityDamageEvent $event * @priority LOWEST */ public function onDamage(EntityDamageEvent $event) { //Stuff you want to do } or, you can do this: PHP: public function onDamage(PlayerDamageEvent $event) { //Checks if the event is not cancelled, and continues if returns true. if(!$event->isCancelled()) { //Your stuff here } } You may want to check me on the first method, I can't remember all of the priorities.
Hm ... I will try, I keep you informed, and I do not use any plugin, except the "SympCore" which gathers all the functionalities of my server !