how do you do it? so far: PHP: class Loader extends PluginBase implements Listener { protected $item; public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); }public function onHit(PlayerItemHeldEvent $heldEvent) { $this->item = $heldEvent->getItem()->getName();}public function onDeath(PlayerDeathEvent $deathEvent) { $cause = $deathEvent->getEntity()->getLastDamageCause(); if ($cause instanceof EntityDamageByEntityEvent) { $player = $deathEvent->getEntity(); $killer = $cause->getDamager(); if ($killer instanceof Player) { if ($this->item != "Unknown") { $player->sendMessage("you were killed by " . $killer->getName() . " with a" . $this->item); } else { $player->sendMessage("you were killed by " . $killer->getName()); } } }}}
That'll work: PHP: $player->sendMessage("You were killed by " . $killer->getName() . " with a " . $killer->getInventory()->getItemInHand()->getName());
okay i made it to this PHP: $this->getServer()->broadcastMessage("you were killed by " . $killer->getName() . " with a" . $killer->getInventory()->getItemInHand()->getName()); but it doesn't say anything when a player kill another
PHP: <?phpclass Loader extends \pocketmine\plugin\PluginBase implements \pocketmine\event\Listener { public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onDeath(\pocketmine\event\player\PlayerDeathEvent $ev) { $cause = $ev->getEntity()->getLastDamageCause(); if ($cause instanceof \pocketmine\event\entity\EntityDamageByEntityEvent) { $player = $ev->getPlayer(); $killer = $cause->getDamager(); if ($killer instanceof \pocketmine\Player) { if ($killer->getInventory()->getItemInHand()->getName() != "Unknown") { $player->sendMessage("You were killed by " . $killer->getName() . " with a" . $killer->getInventory()->getItemInHand()->getName()); } else { $player->sendMessage("You were killed by " . $killer->getName()); } } } }} This should work theororetically
This should work: PHP: $player->sendMessage("You were killed by " . $killer->getName() . ($killer->getInventory()->getItemInHand()->getName() == "Air" ? " with a " . $killer->getInventory()->getItemInHand()->getName() : "by punching"));
If you don't want it to say air PHP: <?phpclass Loader extends \pocketmine\plugin\PluginBase implements \pocketmine\event\Listener { public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onDeath(\pocketmine\event\player\PlayerDeathEvent $ev) { $cause = $ev->getEntity()->getLastDamageCause(); if ($cause instanceof \pocketmine\event\entity\EntityDamageByEntityEvent) { $player = $ev->getPlayer(); $killer = $cause->getDamager(); if ($killer instanceof \pocketmine\Player) { if ($killer->getInventory()->getItemInHand()->getName() != "Unknown") { $itemName = $killer->getInventory()->getItemInHand()->getId() == 0 ? "their fist" : "a " . $killer->getInventory()->getItemInHand()->getName(); $player->sendMessage("You were killed by " . $killer->getName() . " with " . $itemName); } else { $player->sendMessage("You were killed by " . $killer->getName()); } } } }}