I set enemy on fire when they attack me. It set them on fire but it also set me on fire. $seconds = 5; $damager->setOnFire($seconds); $victim->extinguish(); i even tried extinguish but it doesnt work :/
Can I see the rest of your event handler? EDIT: Actually, you just need to handle EntityDamageEvent when the attacking entity is on fire. By default, it will set the player on fire, as seen here.
For me what happened was i made it so if players eqiup diamond chestplate someone hit them it set them on fire. When i hit my friend with diamond chestplate i was set on fire (my friend wasn't on fire he just only h as the chestplate on)
if($e instanceof EntityDamageByEntityEvent){ $damager = $e->getDamager(); $victim = $e->getEntity(); if(!$damager instanceof Player || !$victim instanceof Player) return; if($victim->getArmorInventory()->getChestplate()); if(mt_rand(1, 10) === 1){ $seconds = 5; $damager->setOnFire($seconds); } break; }
PHP: /*** @param EntityDamageEvent $event*/public function onDamage(EntityDamageEvent $event): void { $player = $event->getEntity(); $cause = $player->getLastDamageCause(); if($player instanceof Player and $cause instanceof EntityDamageByEntityEvent and $cause->getDamager() instanceof Player and $player->getArmorInventory()->getChestplate()->getId() == Item::DIAMOND_CHESTPLATE and mt_rand(1, 10) == 1) { $player->setOnFire(5); }} I've not tested it but im sure it works, if it doesn't then one of the things given in if() might not be true (as the rand) so I'd delete it for testing. By the way you can use 'and' instead of putting multiple if's
the code u gave me make it so when player equip a diamond chestplate it have a chance of setting an attacker on fire right?
will it have the same problem as my code? cuz as u know mine set the attacker on fire when attacking player with diamond chestplate
Object comparison isn't as straightforward, possibly because PHP does an spl hash comparison when you do object === object[citation needed]. PHP: $item1 = Item::get(Item::DIAMOND);$item2 = Item::get(Item::DIAMOND);$item1 === $item1; //true$item2 === $item2; //true$item1 === $item2; //false But you can do $item->getId() === Item::DIAMOND to check whether an item is a diamond, since that will be an integer comparison.