Spawn angry wolf

Discussion in 'Plugin Development' started by Mr. X, Aug 26, 2011.

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

    Mr. X

    Hi
    i use this code to spawn wolves but when the target is dead the wolves attacks other players!
    Or when i set tarmetwolf to true then the wolves are friendly but the don't follow my commands!
    Whats wrong i dont know.
    Code:
    
    Wolf w = (Wolf) player.getWorld().spawnCreature(loc, ct);
                            w.setTarget(owner);
                            w.setAngry(true);
                            if(tarmetwolf){
                                w.setAngry(false);
                                w.setTamed(true);
                            }
                            w.setSitting(false);
     
  2. Offline

    Crash

    You can simply check if the target is alive
    if(owner.getHealth() >0)
    w.setTarget(owner);

    For not following commands you need to tell the wolf who the owner is by using setOwner
     
  3. Offline

    Mr. X

    Thanks, which event is triggered when the wolf kills the player?
     
  4. onEntityDeath(EntityDeathEvent event)

    I think, wrote that by heart.
     
  5. Offline

    Mr. X

    Yes I know the event but how do I get out of who the player was killed?
     
  6. Code:java
    1. public void onEntityDeath(EntityDeathEvent event) {
    2. if (event.getEntity() instanceof Player) {
    3. Player victim = (Player) event.getEntity();
    4. Wolf killer = null;
    5.  
    6. if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
    7. EntityDamageByEntityEvent nEvent = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
    8. if (nEvent.getDamager() instanceof Wolf) {
    9. killer = (Wolf) nEvent.getDamager();
    10. }
    11. }
    12.  
    13. //do stuff
    14. }
    15. }
     
Thread Status:
Not open for further replies.

Share This Page