1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Alex was killed by Steve using (item used to kill alex)

Discussion in 'Development' started by Levi, Jul 4, 2017.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    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());
                }

            }
        }
    }
    }
     
  2. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    PHP:
    use $Item->getName() to get the name and $item->getId() for the item id
     
  3. xZeroMCPE

    xZeroMCPE Witch

    Messages:
    67
    GitHub:
    xZeroMCPE
    That'll work:

    PHP:
    $player->sendMessage("You were killed by " $killer->getName() . " with a " $killer->getInventory()->getItemInHand()->getName());
     
    Miste likes this.
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    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
     
  5. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    <?php
    class 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
     
  6. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    legend! but when i kill someone with my fist. it says "air"
     
    Last edited: Jul 5, 2017
  7. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    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"));
     
    Levi and Irish like this.
  8. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    If you don't want it to say air

    PHP:
    <?php
    class 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() == "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());
                    }
                }
            }
        }
    }
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.