Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Get ItemInHand of Killer

Comments in 'Plugin Development' started by iDirtPlayzMC, Aug 9, 2015.

  1. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    PHP:
    $lastDmg $p->getLastDamageCause();
            if (
    $lastDmg instanceof EntityDamageEvent) {
                if (
    $lastDmg instanceof EntityDamageByEntityEvent) {
                    
    $killer $lastDmg->getDamager();
                    if (
    $killer instanceof Player) {
                        
    $item $this->getDamager()->getInventory()->getItemInHand();
                        
    //?????
                        
    return;
                    }
                }
            }

    How will I echo it out that player got killed by the killer using the items
  2. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    Try this
    PHP:
    public function onPlayerDeathEvent(PlayerDeathEvent $event){
        
    $lastDmg $event->getPlayer()->getLastDamageCause();
        if(
    $lastDmg instanceof EntityDamageByEntityEvent){
            
    $victim $lastDmg->getEntity()->getName();
            
    $killer $lastDmg->getDamager()->getName();
            if(
    $killer instanceof Player){
                
    $item $killer->getInventory()->getItemInHand();
                
    $event->setMessage($killer." killed ".$victim." using ".$item);
            }
        }
    }
    iDirtPlayzMC likes this.
  3. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    Thnx
    Legoboy0215 likes this.
  4. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    Glad i could help :)
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Can class Item be converted to string?
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    getItemInHand()->getId() returns an Item class, not plain getItemInHand I think.
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Ow i see. It can be converted to String :p :D
  8. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I am not sure. I am on vacation so do not have easy access to the docs. Sorry if I am wrong :):):)
  9. Xenturio
    Offline

    Xenturio Active Member

    Joined:
    Sep 19, 2014
    Posts:
    333
    Minecraft User:
    Xenturio

    and $lastDmg = $event->getPlayer()->getLastDamageCause(); this cant work... its an Entity Event
  10. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    PlayerDeathEvent is not an Entity Event. EntityDeathEvent it, but we're not using that
    Last edited: Aug 10, 2015
  11. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    Oh yeah that's true
  12. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    PHP:
    public function onDeath(PlayerDeathEvent $event){
            
    $player $event->getEntity();
            
    $cause $player->getLastDamageCause();
            if(!(
    $cause instanceof EntityDamageByEntityEvent)) return;
            
    $attacker = ($cause->getDamager() instanceof Player $cause->getDamager() : false);
    if(
    $attacker !== false) {
        
    $this->getServer()->broadcastMessage($this->translateColors("&" '&b'.$player->getName().'&a was slain by&6 '.$attacker->getName().'&c using&4 '.$attacker->getInventory()->getItemInHand()->getName().'.'));
    }
    }
    fixed
    BlubberBoy333 likes this.
  13. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    This won't work. Please make sure you are giving the correct solutions, because this does more harm than help.
  14. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Nope. :p
  15. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    lol.
    The victim is same as the PlayerDeathEvent entity.
  16. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    Where was i wrong?
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PlayerInventory->getItemInHand() returns an Item. Item->getId() returns an int.
    jojoe77777 likes this.
  18. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Oh. But sometimes I do $event->getItem() returns a int lol.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No it won't. If it does, some plugin had done something mischief.

Share This Page

Advertisement