GetHealthScale() on Creature

Discussion in 'Plugin Development' started by To175, Dec 1, 2014.

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

    To175

    Hi,
    how can I use getHealthScale() on instanceof Creature ?
    thanks
     
  2. To175 You can't. This is a Player only method, so naturally is not available to anything other than Players.
     
  3. Offline

    To175

    AdamQpzm Ok thanks, so how can I get mob's health ?
     
  4. To175 getHealth() will work :)
     
  5. Offline

    To175

    AdamQpzm thx but
    etc... So I can't :(

    And an other question, for mobs I have to use Creature or LivingEntity ?
     
  6. To175 Official: http://forums.bukkit.org/threads/oops-i-didnt-break-your-plugins-ambiguous-gethealth.156975

    Other:
    https://forums.bukkit.org/threads/issue-with-getting-health.325610
    http://forums.bukkit.org/threads/getmaxhealth-method-is-ambiguous-for-the-type-player.317479/
    http://forums.bukkit.org/threads/player-gethealth-is-ambiguious-i-dont-get-it.307389/
    https://forums.bukkit.org/threads/ambiguous-e-gethealth.304166/
    http://forums.bukkit.org/threads/player-gethealth-no-work.302636/
    http://forums.bukkit.org/threads/calling-livingentity-getmaxhealth-makes-compilation-error.302253/
    http://forums.bukkit.org/threads/running-into-a-ambigous-gethealth-prolblem-is-there-a-fix.299984
    http://forums.bukkit.org/threads/player-gethealth-not-working.294791
    https://forums.bukkit.org/threads/ambiguous-method-call.290605/
    http://forums.bukkit.org/threads/gethealth.276919/
    http://forums.bukkit.org/threads/ambiguous-method-call-help.259542/
    http://forums.bukkit.org/threads/player-gethealth-in-a-event.252147
    http://forums.bukkit.org/threads/adding-health.249685/
    http://forums.bukkit.org/threads/adding-to-player-health.248607
    http://forums.bukkit.org/threads/gethealth-help.240372/
    http://forums.bukkit.org/threads/help-please.237838/
    http://forums.bukkit.org/threads/gethealth-is-ambiguous.231921/
    http://forums.bukkit.org/threads/gethealth-is-ambiguous.228237/
    http://forums.bukkit.org/threads/gethealth.227353
    http://forums.bukkit.org/threads/gaining-health.222595
    http://forums.bukkit.org/threads/player-getmaxhealth-problem.218817/
    http://forums.bukkit.org/threads/player-get-health-get-how-much-soups-he-had-in-hes-hotbar.218264
    http://forums.bukkit.org/threads/add-health-instead-of-setting-it.129058
    http://forums.bukkit.org/threads/gethealth-is-ambiguous-for-the-type-player.215698/
    http://forums.bukkit.org/threads/the-method-gethealth-is-ambiguous-for-the-type-player.214760/
    http://forums.bukkit.org/threads/help-with-my-plugin-wont-get-player-health.212361/
    http://forums.bukkit.org/threads/delay-on-command.211452
    http://forums.bukkit.org/threads/snowball-damage.209423
    http://forums.bukkit.org/threads/land-mines-doesnt-cause-player-damage.208364
    http://forums.bukkit.org/threads/target-gethealth-error.208123
    http://forums.bukkit.org/threads/getting-player-health.204195
    http://forums.bukkit.org/threads/gethealth-getmaxhealth.200176/
    http://forums.bukkit.org/threads/slenderman-plugin-errors.195214/
    http://forums.bukkit.org/threads/two-different-gethealth-methods-in-code.194860/
    http://forums.bukkit.org/threads/mob-health.194295
    http://forums.bukkit.org/threads/right-click-on-item.193745
    http://forums.bukkit.org/threads/p-gethealth-error.193150
    http://forums.bukkit.org/threads/events-not-fired-foodlevelchangeevent.191799
    http://forums.bukkit.org/threads/gethealth-isnt-working.184244/
    http://forums.bukkit.org/threads/healing-problems.182755
    http://forums.bukkit.org/threads/please-help-player-health.176919
    http://forums.bukkit.org/threads/ambiguous-gethealth.176704/
    http://forums.bukkit.org/threads/double-hp-player-gethealth.175774
    http://forums.bukkit.org/threads/instant-soup-plugin-help.175203/
    http://forums.bukkit.org/threads/gethealth-problem.172985/
    http://forums.bukkit.org/threads/the-method-gethealth-is-ambiguous-for-the-type-livingentity.172649/
    http://forums.bukkit.org/threads/soup-plugin-trouble.171039/
    http://forums.bukkit.org/threads/checking-health.169234
    http://forums.bukkit.org/threads/gethealth-and-getmaxhealth-is-ambiguous.168384/
    http://forums.bukkit.org/threads/i-still-dont-understand-this-livingentitys-gethealth.166316/
    http://forums.bukkit.org/threads/gethealth.164234
    http://forums.bukkit.org/threads/trouble-displaying-health.162284
    http://forums.bukkit.org/threads/cant-use-bukkit-or-craftbukkit.161364
    http://forums.bukkit.org/threads/gethealth-not-working.161136
    http://forums.bukkit.org/threads/player-gethealth-wont-work-for-1-6.160857/
    http://forums.bukkit.org/threads/player-gethealth-1-6-2-problem.159547
    http://forums.bukkit.org/threads/lose-hearts-health-on-command.159632
    http://forums.bukkit.org/threads/a-fast-soup-problem.159522
    http://forums.bukkit.org/threads/adding-more-hearts-to-players.159191/
    http://forums.bukkit.org/threads/1-6-ambiguous-gethealth.158924
    http://forums.bukkit.org/threads/ambiguous-with-double.158182
    http://forums.bukkit.org/threads/gethealth-is-ambiguous.157851/
    http://forums.bukkit.org/threads/the-method-gethealth-is-ambiguous-for-the-type-player.157668/
    http://forums.bukkit.org/threads/1-6-1-gethealth-ambiguous.157592
    http://forums.bukkit.org/threads/health-is-ambiguous.157586/
    http://forums.bukkit.org/threads/gethealth-how-do-i-add-health-to-a-player.157398/
    http://forums.bukkit.org/threads/gethealth-1-6-1-change-help.157315/
    http://forums.bukkit.org/threads/unable-to-get-players-health.157229/
    http://forums.bukkit.org/threads/giving-players-health-p-damage-in-1-6-help.157063/
    [​IMG]
     
    Skionz likes this.
  7. Offline

    To175

    AdamQpzm I know those links.
     
  8. To175 Either is fine I suppose.
     
  9. Offline

    To175

    AdamQpzm Which one ?

    And I don't understand links, in Eclipse Libraries I have craftbukkit 1.7.10 and JRE 1.7 ... and what is the bukkit file ??
     
  10. To175 The Bukkit file is the Bukkit API, found here. You should be building against it, rather than craftbukkit.jar. If you need CB files, make sure Bukkit has a higher priority in the build path than CraftBukkit.
     
  11. Offline

    To175

    AdamQpzm thanks !
    Which one can I take ?
    I'm using craftbukkit-1.7.10-R0.1-20140817.180155-16
     
  12. To175 The Bukkit and craftbukkit version don't really have to match :) I would just go for the most recent one that you can (last I knew, some of the links weren't working, so you may have to try a few)
     
  13. Offline

    To175

    AdamQpzm I find it ! :)
    But my code doesn't work :(
    Code:java
    1. @EventHandler
    2. public void EntityDamageEvent(final Entity damagee, final DamageCause cause, final int damage) {
    3. ScoreboardManager manager = Bukkit.getScoreboardManager();
    4. Scoreboard board = manager.getNewScoreboard();
    5. Objective objective = board.registerNewObjective("showhealth", "health");
    6. objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
    7. if(damagee instanceof Creature && damagee != null) {
    8. Creature wounded = (Creature)damagee;
    9. double health = wounded.getHealth(); //Update their health
    10. double demiCoeurs = health/2;
    11. if(demiCoeurs%2==1){
    12. demiCoeurs = demiCoeurs - 0.5;
    13. }
    14. String barreDeVie = "";
    15. while(demiCoeurs>0){
    16. barreDeVie = barreDeVie + "|";
    17. demiCoeurs = demiCoeurs - 1;
    18. }
    19. objective.setDisplayName(barreDeVie);
    20. }else if(damagee instanceof Player && damagee != null){
    21. Player wounded = (Player)damagee;
    22. if(IsInGame(wounded)){
    23. double health = wounded.getHealthScale(); //Update their health
    24. double demiCoeurs = health/2;
    25. if(demiCoeurs%2==1){
    26. demiCoeurs = demiCoeurs - 0.5;
    27. }
    28. String barreDeVie = "";
    29. while(demiCoeurs>0){
    30. barreDeVie = barreDeVie + "|";
    31. demiCoeurs = demiCoeurs - 1;
    32. }
    33. objective.setDisplayName(barreDeVie);
    34. }
    35. }else{
    36. return;
    37. }
    38. }

    No errors in logs
     
  14. To175 You're creating a new scoreboard every time an entity damages an entity, I don't think you want to do that. Additionally, you never give any players this scoreboard, so it just fades into nothingness. Finally, you don't really want to fiddle with getHealthScale() here - you want getHealth()
     
  15. Offline

    To175

    AdamQpzm ok thanks,
    I corrected it but I don't know other things that getNewScoreboard, I didn't see getScoreboard :'(
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent event){
    3. ScoreboardManager manager = Bukkit.getScoreboardManager();
    4. Scoreboard board = manager.getNewScoreboard();
    5. Objective objective = board.registerNewObjective("showhealth", "health");
    6. objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
    7. double health = event.getPlayer().getHealthScale(); //Update their health
    8. double demiCoeurs = health/2;
    9. if(demiCoeurs%2==1){
    10. demiCoeurs = demiCoeurs - 0.5;
    11. }
    12. String barreDeVie = "";
    13. while(demiCoeurs>0){
    14. barreDeVie = barreDeVie + "|";
    15. demiCoeurs = demiCoeurs - 1;
    16. }
    17. objective.setDisplayName(barreDeVie);
    18. event.getPlayer().setScoreboard(board);
    19. }
    20.  
    21. @EventHandler
    22. public void EntityDamageEvent(final Entity damagee, final DamageCause cause, final int damage) {
    23. ScoreboardManager manager = Bukkit.getScoreboardManager();
    24. Scoreboard board = manager.getNewScoreboard();
    25. Objective objective = board.registerNewObjective("showhealth", "health");
    26. objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
    27. if(damagee instanceof LivingEntity && damagee != null) {
    28. LivingEntity wounded = (LivingEntity)damagee;
    29. double health = wounded.getHealth(); //Update their health
    30. double demiCoeurs = health/2;
    31. if(demiCoeurs%2==1){
    32. demiCoeurs = demiCoeurs - 0.5;
    33. }
    34. String barreDeVie = "";
    35. while(demiCoeurs>0){
    36. barreDeVie = barreDeVie + "|";
    37. demiCoeurs = demiCoeurs - 1;
    38. }
    39. objective.setDisplayName(barreDeVie);
    40. }else{
    41. return;
    42. }
    43. }

    I have not the choice if I want to refresh it -_-
    Yes I forget the OnPlayerJoin event !
    This is the same thing for player.
     
  16. To175 You should store a reference to the scoreboard as a field (or in a Map if using per-player boards) and reuse the instance, you don't need to make a new one each time :)

    Health and health scale are different things. At times they may be the same thing, but you can't really rely on that - any plugin can change the health scale without it affecting the player's health, but plugins can't change the health without the player's health physically changing.
     
  17. Offline

    To175

    thx but What is that ? :eek:
    Yes per player because health bars
     
Thread Status:
Not open for further replies.

Share This Page