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

Recognize a death caused by a shot

Comments in 'Plugin Development' started by Kripto, Jan 5, 2015.

  1. Kripto
    Offline

    Kripto New Member

    Joined:
    Mar 2, 2014
    Posts:
    15
    Minecraft User:
    Kripto96
    I have this code
    PHP:
    public function onPlayerDeath(PlayerDeathEvent $event) {
       if(
    $event->getEntity() instanceof Player) {
          
    $cause $event->getEntity()->getLastDamageCause()->getCause();
          
    //
       
    }
    }
    I now that if the cause is equal to 1 someone kill the player, but how I can know if the player has been killed by an arrow?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    $lastCause $event->getEntity()->getLastDamageCause();
    if(
    $lastCause instanceof EntityDamageByChildEntityEvent and $lastCause->getChild() instanceof Arrow){ ... }
    Thunder33345 and xFlare like this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is a bit more complicated if you want to detect a fall damage caused by an arrow; I'm making it for LegionPE. An untested snippet (diff):
    http://pastebin.com/uaXs2sjG

    I used dynamic fields to store data, which is actually a bad practice. But in the whole sessioning framework in that plugin, using dynamic fields is better. It is a rare occasion though.
  4. Kripto
    Offline

    Kripto New Member

    Joined:
    Mar 2, 2014
    Posts:
    15
    Minecraft User:
    Kripto96
    Thanks for the code, I'm trying it
    Jon likes this.

Share This Page

Advertisement