Check if a player dies from a wolf?

Discussion in 'Plugin Development' started by GrimmjowHD, Oct 29, 2013.

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

    GrimmjowHD

    Hello,
    How would you go about checking if a wolf kills a player? So you can get the owner of the wolf, and do yada yada ?
    What I have so far..
    Code:java
    1. @EventHandler(priority = EventPriority.HIGH)
    2. public void dog(PlayerDeathEvent event) {
    3. if (event.getEntity() instanceof Player) {
    4. Player p = (Player) event.getEntity();
    5. p.sendMessage("test1");
    6.  
    7. if (p.getLastDamageCause().equals(EntityType.WOLF)){
    8. Wolf w = (Wolf) p.getKiller();
    9. Player o = (Player) w.getOwner();
    10. p.setHealth(20.0);
    11. p.sendMessage("test2");
    12. p.damage(1000.0, o);
    13. p.sendMessage("test3");
    14. }
    15. }
    16. }
     
  2. Offline

    calebbfmv

    EntityDamageByEntityEvent, check if the damagee is a player, damager is a wolf, check if the player dies, which I think you can do, then do whatever else you need.
     
  3. Offline

    GrimmjowHD

    I tried..
    Code:java
    1. @EventHandler(priority = EventPriority.HIGH)
    2. public void wolf(EntityDamageByEntityEvent event){
    3.  
    4. if (event.getEntity() instanceof Player) {
    5. Bukkit.broadcastMessage("test1");
    6. Player damaged = (Player) event.getEntity();
    7.  
    8. if (event.getDamager() instanceof Wolf) {
    9. Bukkit.broadcastMessage("test2");
    10.  
    11. if(damaged.getHealth() == pHealth){
    12. Bukkit.broadcastMessage("test3");
    13. Wolf w = (Wolf) event.getDamager();
    14. Player o = (Player) w.getOwner();
    15. event.setCancelled(true);
    16. damaged.damage(8.0, o);
    17. }
    18. }
    19. }
    20. }

    where pHealth is..
    Code:java
    1. public double pHealth = 0.0;

    and It doesn't send the third debug message
     
  4. Offline

    calebbfmv

    GrimmjowHD
    I have no idea, I haven't messed with health and things.
    What I think is that your checking if a dead player is being damaged, which isn't possible. Try getting the damagee healths at .1 or something so low, he has no chance of living.
     
  5. GrimmjowHD

    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent e)
    3. {
    4. if (e.getEntity().getKiller() instanceof Wolf)
    5. {
    6. Wolf killer = (Wolf)e.getEntity().getKiller();
    7. }
    8. }


    What this basically is doing:
    On the death event, if the thing that killed them is a Wolf, then create a variable that stores the killer(The wolf) in it.
    After that you can do all of your codez.
     
    calebbfmv likes this.
Thread Status:
Not open for further replies.

Share This Page