Hello, I would like to know if there is a way to make a armor more resistant? (Sorry for my english I'm french)
I found a code but when I hit the player with a sword it makes the same number of hearts. Code : PHP: $armor = Item::get(303, 1, 1); if ($damager->getInventory()->getItemInHand() instanceof Sword) { $event->setModifier(-($event->getFinalDamage() * 0.2 * $armor->getLevel())); }
$armor->getLevel shouldn't be valid, because there is no level for items. $event->setModifier requires a parameter for the modifier value, and the modifier type. I'd suggest using 1 for armor. I'd do something like this: PHP: if ($damager->getInventory()->getItemInHand() instanceof Sword) { $event->setModifier(($event->getModifier(EntityDamageEvent::MODIFIER_ARMOR) * 1.2), EntityDamageEvent::MODIFIER_ARMOR); //Should make armor 20% more effective. } I wouldn't use final damage, because that will have an affect on other modifiers, like potions and armor enchantments, which I don't think you intend.
please don't teach them to hardcode magic numbers... use the constants. https://github.com/pmmp/PocketMine-MP/blob/3.5/src/pocketmine/event/entity/EntityDamageEvent.php#L34
You could create your own custom armor class that extends the default and has the properties you want