damage.txt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. event.load("animal_tame");
  2. event.load("living_hurt");
  3. event.load("living_heal");
  4. event.load("entity_join");
  5. entities_list = list.new();
  6. msg("dev", "§bDamage §rloaded.");
  7. @wait
  8. wait();
  9. ignoreGoto(event);
  10. goto("wait");
  11. @animal_tame
  12. if(isLiving(animal) && !isPlayer(animal)) {
  13. if(list.getSize(entities_list) == 0) {
  14. sgoto(1, "sgoto_updateEntityName");
  15. }
  16. list.add(entities_list, animal);
  17. }
  18. goto("wait");
  19. @entity_join
  20. if(isLiving(entity) && !isPlayer(entity)) {
  21. updateEntityName(entity);
  22. }
  23. goto("wait");
  24. @living_heal
  25. cancel = true;
  26. if(heal_amount <= 0) {
  27. goto("wait");
  28. }
  29. health = living.getHealth(living_entity);
  30. if(health <= 0) {
  31. goto("wait");
  32. }
  33. new_health = health + heal_amount;
  34. living.setHealth(living_entity, new_health);
  35. if(!isPlayer(living_entity)) {
  36. updateEntityName(living_entity);
  37. }
  38. goto("wait");
  39. @living_hurt
  40. if(isPlayer(living_entity)) {
  41. goto("wait");
  42. }
  43. if(list.getSize(entities_list) == 0) {
  44. sgoto(1, "sgoto_updateEntityName");
  45. }
  46. list.add(entities_list, living_entity);
  47. goto("wait");
  48. @sgoto_updateEntityName
  49. iter = list.iterator(entities_list);
  50. while(hasNext(iter)) {
  51. updateEntityName(next(iter));
  52. }
  53. list.clear(entities_list);
  54. goto("wait");
  55. function updateEntityName(living_entity) {
  56. entity_type = entity.getType(living_entity);
  57. if(entity_type == "nobody" || entity_type == "armor_stand" || entity_type == "human") {
  58. return;
  59. }
  60. entity_name = entity.getName(living_entity);
  61. max_health = living.getMaxHealth(living_entity);
  62. health = text.number(math.round(living.getHealth(living_entity)));
  63. max_health = text.number(math.roundComma(max_health, 1));
  64. heart_index = text.indexOf(entity_name, "❤", 0);
  65. if(heart_index == -1) {
  66. //Kein Herz gefunden
  67. entity.setName(living_entity, concat(health, "/", max_health, " §c❤\n", entity_name), true);
  68. return;
  69. }
  70. next_new_line = text.indexOf(entity_name, "\n", heart_index);
  71. if(next_new_line == -1) {
  72. //Rechts vom Herz keine New-Line gefunden
  73. entity.setName(living_entity, concat(health, "/", max_health, " §c❤"), true);
  74. return;
  75. }
  76. entity_name = text.subString(entity_name, next_new_line + 1, text.length(entity_name));
  77. entity.setName(living_entity, concat(health, "/", max_health, " §c❤\n", entity_name), true);
  78. }