onEntityDeath - death cause

Discussion in 'Plugin Development' started by matejdro, Feb 11, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    matejdro

    Is there a way to retreive death cause from onEntityDeath?

    More specifically, i want to know if entity died from ranged attack (bow) or close attack (sword). Currently I'm doing onEntityDamageByEntity and onEntityDamageByProjectile and detect death by checking victim's health with damage. But those events are very unreliable and they do not support armor on players.

    EDIT: Wait a minute, does onEntityDeath even triggers when player is dead?
    EDIT2: yup, it triggers. I had typo in code :)
     
  2. Offline

    Byteflux

    Different causes of death can be determined with the damage events. For example, damage by a projectile (e.g., arrow) will trigger ENTITY_DAMAGEBY_PROJECTILE, damage by an entity such as a mob or player will trigger ENTITY_DAMAGEBY_ENTITY and so forth.

    To know the cause of the death for all possible deaths, you will need to combine all damage events. Keep a map of "last damage" events so you can determine the cause of death.

    When your onEntityDeath() callback is invoked, simply check the player's "last damage" event and determine their cause of death based on the event.

    Check out the source code for the DeathTpPlus plugin if you want a good example of how to handle each damage event.
     
Thread Status:
Not open for further replies.

Share This Page