Solved Entity Damager

Discussion in 'Plugin Development' started by CraftingRealm, Sep 2, 2013.

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

    CraftingRealm

    I am making a plugin that shoots an arrow from a player when they fire a gun. When the arrow hits an entity, specifically a zombie, I want to play an effect at the arrows location but in the EntityDamageByEntityEvent, event.getDamager() seems to return the player and not the arrow. How can I find the arrow I shot?

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  2. Offline

    mydeblob

    Can you post your code? It could help.
     
  3. Offline

    CraftingRealm

    mydeblob
    Code:java
    1. @EventHandler
    2. public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    3. if (event.getEntity() instanceof Zombie) {
    4. Zombie zombie = (Zombie) event.getEntity();
    5. Location loc = event.getDamager().getLocation(); // returns player location not arrow location
    6. p.getPlayer().playEffect(loc, Effect.STEP_SOUND, 152);
    7. }
    8. }
     
  4. Offline

    mydeblob

    CraftingRealm
    I could just be tired, but I think you are getting the location of the wrong entity. Try replacing this
    Code:java
    1. Location loc = event.getDamager().getLocation(); //This was getting the player who hit the entity's location

    With this
    Code:java
    1. Location loc = event.getEntity().getLocation(); //This will get the entity that got damaged location
     
  5. Offline

    JPG2000

  6. Offline

    CraftingRealm

Thread Status:
Not open for further replies.

Share This Page