getkiller Skeleton

Discussion in 'Plugin Development' started by Mother__, Mar 11, 2013.

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

    Mother__

    Hi guys why this not working ?

    Code:java
    1.  
    2. String player = event.getEntity().getPlayer().getName();
    3. Player playerInstance = (Player) event.getEntity();
    4. EntityDamageEvent damageEvent = playerInstance.getLastDamageCause();
    5. if(!(damageEvent instanceof EntityDamageByEntityEvent))
    6. return;
    7. Entity damager = ((EntityDamageByEntityEvent)damageEvent).getDamager();
    8.  
    9. if(damager instanceof Skeleton){
    10. event.setDeathMessage("[NOTICE]" + ChatColor.RED + "[" + player + "]"
    11. + ChatColor.WHITE + " killed by skeleton ");
    12. }
    13.  
     
  2. Offline

    DRRichard

  3. Offline

    evilmidget38 Retired Staff

    Mother__ Define "not working".

    EDIT: What's with your first line? "getEntity().getPlayer()"?
     
  4. Offline

    Mother__

    when i die by skeleton not show message killed by skeleton
     
  5. Offline

    evilmidget38 Retired Staff

    Mother__ Do you get any errors? Is your Listener registered? Does it even compile?
     
  6. Offline

    Mother__

    evilmidget38 not have error but not working with others monsters working but skeleton nothing
     
  7. Offline

    evilmidget38 Retired Staff

    Mother__ Can you post all your code?
     
  8. Offline

    Mother__

    Code:java
    1.  
    2. String player = event.getEntity().getPlayer().getName();
    3.  
    4. Player playerInstance = (Player) event.getEntity();
    5. EntityDamageEvent damageEvent = playerInstance.getLastDamageCause();
    6. if(!(damageEvent instanceof EntityDamageByEntityEvent))
    7. return;
    8. Entity damager = ((EntityDamageByEntityEvent)damageEvent).getDamager();
    9. if(damager instanceof Spider){
    10. event.setDeathMessage("[NOTICE]" + ChatColor.RED + "[" + player + "]"
    11. + ChatColor.WHITE + " killed by Spider");
    12. }
    13. if(damager instanceof Zombie){
    14. event.setDeathMessage("[NOTICE]" + ChatColor.RED + "[" + player + "]"
    15. + ChatColor.WHITE + " killed by Zombie");
    16. }
    17. if(damager instanceof Skeleton){
    18. event.setDeathMessage("[NOTICE]" + ChatColor.RED + "[" + player + "]"
    19. + ChatColor.WHITE + " killed by Skeleton");
    20. }
    21. if(damager instanceof Creeper){
    22. event.setDeathMessage("[NOTICE]" + ChatColor.RED + "[" + player + "]"
    23. + ChatColor.WHITE + " killed by Creeper");
    24. }
    25.  
    26.  
    27.  
     
  9. Offline

    evilmidget38 Retired Staff

    Mother__ What event is that, and how are you invoking getPlayer on an entity? That doesn't make sense.
     
  10. Offline

    Mother__

    i learn API bukkit please if u can help me
     
  11. Offline

    evilmidget38 Retired Staff

    Mother__ Please answer my question. I can't help you if I don't know what you're doing. Additionally, you can't help yourself if you don't know what you're doing. If you're not familiar with java or bukkit, there are plenty of resources available to help you learn. If you're not using an IDE, I suggest you start doing so.
     
  12. Offline

    Craftiii4

    Use arrow instead of skeleton, then cast to an arrow, find the shooter then cast to player, or skeleton.

    In more detail:

    A skeleton is not actually killing you, the entity "Arrow" is. But an arrow can be shot by more than one thing, Shooters could be an entity such as a skeleton or a player (or any other mob with a bow), or it could be a block such as a dispenser.

    So check for an arrow first (using instanceof) , if it is an arrow create a new variable of type arrow, get the shooter (in an entity form) then use instanceof for either skeleton or player.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  13. Offline

    Mother__

    Could me example ? thanks
     
  14. Offline

    Craftiii4

    The idea is to learn, not to just copy code. I told you what you needed to do.

    Take your already existing code, change the "instanceof Skeleton" to arrow create a variable of Arrow called arrow with the data damager. Then create a new entity called killershooter with arrow.getShooter(), then use another "instanceof Skeleton"(or player) on killershooter.
     
  15. Offline

    Mother__

    @Craftii4 thx working code if someone want
    Code:java
    1.  
    2.  
    3. Arrow arrow = (Arrow) damager;
    4. Entity killershooter = arrow.getShooter();
    5. if(killershooter instanceof Skeleton) {
    6. event.setDeathMessage("[NOTICE]" + ChatColor.RED + "[" + player + "]"
    7. + ChatColor.WHITE + " killed by skeleton ");
    8. }
    9.  



    but have conflict when the player and killed by another player like this

    Code:java
    1.  
    2.  
    3.  
    4. if (playerInstance.getKiller() instanceof Player){
    5. event.setDeathMessage("[NOTICE]" + ChatColor.RED + "[" + player + "]"
    6. + ChatColor.WHITE + " killed by " + player.getKiller().getDisplayName() + " skeleton ");
    7. }
    8.  


    Can help me please?
     
  16. Offline

    ZeusAllMighty11 Retired Staff

    You're casting arrow to damager before checking if it's an arrow...
     
Thread Status:
Not open for further replies.

Share This Page