Solved Check an entity's health [EntityDamageByEntityEvent]

Discussion in 'Plugin Development' started by AmberOfSickness, Jan 26, 2013.

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

    AmberOfSickness

    Hello, i am trying to make a function that gets triggered when a giant is killed by a player. I already know how to check if the killer is a player, if the entity killed is a giant, but i can't check for the Giant's health. Here's the code (resembled according to what i want to share):
    Code:
    @EventHandler
        public void onGiantKillEvent(EntityDamageByEntityEvent event) {
            if(event.getDamager() instanceof Player) getLogger().info("Giocatore OK");
            getLogger().info(event.getEntity().toString());
            mainclass.getLogger().info(event.getEntityType().toString());
            if(event.getDamager() instanceof Player & event.getEntityType().toString() == "GIANT") {
                Player Killer = (Player) event.getDamager();
               
               if(GIANTSHEALTS <= 0) {
                    Killer.sendMessage("ยง6Goncratulations! This dead giant has raised your counter on our website!");
                    DoThisFunction();
                }
            }
        }
    There may be errors above, but my code works well [i've rewritten it]. I need to check the giant's current health where "GIANTSHEALTH" is. I just can't find out how to check the giant's health. Can anyone help me, please? Thanks in advance!
     
  2. Offline

    Etaki

    This is something I did a while back to get the health of a player for regeneration, maybe it'll help?

    Code:text
    1.  
    2. public void onEntityDamage(EntityDamageEvent evt)
    3. {
    4. org.bukkit.entity.Entity e = evt.getEntity();
    5. Player user = (Player) e;
    6. int hp = user.getHealth();
    7. if(user.hasPermission("ga.regen"))
    8. {
    9. if(plugin.pluginEnabled.containsKey(user.getName()) == true)
    10. {
    11. if(evt.getEntity() instanceof Player)
    12. {
    13. if(hp > 10);
    14. user.setHealth(hp + (hp * plugin.getConfig().getInt("Options.regen")));
    15. }
    16. else{
    17. user.sendMessage(ChatColor.RED + "Regen Not Enabled, You Don't Have Permission");
    18. }
    19. }
    20. }
    21. }
    22.  
     
    AmberOfSickness likes this.
  3. Offline

    RealDope

    Code:JAVA
    1.  
    2. if(event.getEntity() instanceof Giant) {
    3. Giant giant = (Giant) event.getEntity();
    4. int health = giant.getHealth();
    5. }
    6.  
     
    AmberOfSickness likes this.
  4. Offline

    Etaki

    ...That's so much simpler than what I was about to put. I feel stupid now.
     
    AmberOfSickness likes this.
  5. Offline

    AmberOfSickness

    Ok, now my function is done, thanks!
     
Thread Status:
Not open for further replies.

Share This Page