123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- event.load("animal_tame");
- event.load("living_hurt");
- event.load("living_heal");
- event.load("entity_join");
- entities_list = list.new();
- msg("dev", "§bDamage §rloaded.");
- @wait
- wait();
- ignoreGoto(event);
- goto("wait");
- @animal_tame
- if(isLiving(animal) && !isPlayer(animal)) {
- if(list.getSize(entities_list) == 0) {
- sgoto(1, "sgoto_updateEntityName");
- }
- list.add(entities_list, animal);
- }
- goto("wait");
- @entity_join
- if(isLiving(entity) && !isPlayer(entity)) {
- updateEntityName(entity);
- }
- goto("wait");
- @living_heal
- cancel = true;
- if(heal_amount <= 0) {
- goto("wait");
- }
- health = living.getHealth(living_entity);
- if(health <= 0) {
- goto("wait");
- }
- new_health = health + heal_amount;
- living.setHealth(living_entity, new_health);
- if(!isPlayer(living_entity)) {
- updateEntityName(living_entity);
- }
- goto("wait");
- @living_hurt
- if(isPlayer(living_entity)) {
- goto("wait");
- }
- if(list.getSize(entities_list) == 0) {
- sgoto(1, "sgoto_updateEntityName");
- }
- list.add(entities_list, living_entity);
- goto("wait");
- @sgoto_updateEntityName
- iter = list.iterator(entities_list);
- while(hasNext(iter)) {
- updateEntityName(next(iter));
- }
- list.clear(entities_list);
- goto("wait");
- function updateEntityName(living_entity) {
- entity_type = entity.getType(living_entity);
- if(entity_type == "nobody" || entity_type == "armor_stand" || entity_type == "human") {
- return;
- }
- entity_name = entity.getName(living_entity);
- max_health = living.getMaxHealth(living_entity);
- health = text.number(math.round(living.getHealth(living_entity)));
- max_health = text.number(math.roundComma(max_health, 1));
-
- heart_index = text.indexOf(entity_name, "❤", 0);
- if(heart_index == -1) {
- //Kein Herz gefunden
- entity.setName(living_entity, concat(health, "/", max_health, " §c❤\n", entity_name), true);
- return;
- }
-
- next_new_line = text.indexOf(entity_name, "\n", heart_index);
- if(next_new_line == -1) {
- //Rechts vom Herz keine New-Line gefunden
- entity.setName(living_entity, concat(health, "/", max_health, " §c❤"), true);
- return;
- }
- entity_name = text.subString(entity_name, next_new_line + 1, text.length(entity_name));
- entity.setName(living_entity, concat(health, "/", max_health, " §c❤\n", entity_name), true);
- }
|