Solved p.getHealth() error

Discussion in 'Plugin Development' started by Dark_Snaker, Nov 10, 2013.

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

    Dark_Snaker

    Hello :)

    Code:java
    1. @EventHandler(priority = EventPriority.NORMAL)
    2. public void OnPlayerGoToDeath(PlayerEvent e){
    3.  
    4. Player p = e.getPlayer();
    5.  
    6. if(p.getHealth() < 4.0);
    7.  
    8. p.sendMessage(ChatColor.GREEN + "Compétence" + ChatColor.AQUA + " Survivor " + ChatColor.GREEN + "activée !");
    9. p.playSound(p.getLocation(), Sound.SUCCESSFUL_HIT, 100.0F, 1.0F);
    10. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 5, 1));
    11. p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 5, 1));
    12. p.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 5, 1));
    13. }
    14.  


    I have an error with "p.getHealth()"
    I want to when the player's health is two hearts or minus, player recives special skills.

    Thanks if you help me ;)

    P.S. : Sorry for my bad english :oops:
     
  2. Offline

    Xacero

    Code:java
    1. @EventHandler(priority = EventPriority.NORMAL)
    2. public void OnPlayerGoToDeath(EntityDamageEvent e){
    3. if (e.getEntity() instanceof Player) {
    4. Player p = (Player) e.getEntity();
    5. if(((EntityLiving) e.getEntity()).getHealth() < 4.0) {
    6. p.sendMessage(ChatColor.GREEN + "Compétence" + ChatColor.AQUA + " Survivor " + ChatColor.GREEN + "activée !");
    7. p.playSound(p.getLocation(), Sound.SUCCESSFUL_HIT, 100.0F, 1.0F);
    8. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 5, 1));
    9. p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 5, 1));
    10. p.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 5, 1));
    11. }}}

    Try that? Written in the editor so it might have some bracket misalignment.

    **Edit** Fixed ambiguous error
     
    Gater12 likes this.
  3. Offline

    Dark_Snaker

    No, I've got an error on getHelth and getEntity
     
  4. Offline

    NinjaWAffles

    PlayerEvent? PlayerEvent is the class in which events are extended off of, it's not an event itself. You'll want to use PlayerDeathEvent.
     
  5. Offline

    Xacero

    Code:java
    1. if(p.getHealth() < 4.0);

    There's also this. It should be working now. (see my above post)
    I just didn't point out the errors because I'm tired - my attention span is not so good at this point. Sorry about that. :)
     
  6. Offline

    Dark_Snaker

    No, error with getEntity and getHealth...
    "The method getHealth() is ambiguous for the type Player"
     
Thread Status:
Not open for further replies.

Share This Page