better infotexts for mobs_redo mobs

This commit is contained in:
Sokomine 2023-02-24 08:51:33 +01:00
parent edc5cdfe77
commit 8ef9aeb5db

View File

@ -92,3 +92,71 @@ function yl_speak_up.after_activate(self, staticdata, def, dtime)
yl_speak_up.update_nametag(self)
end
yl_speak_up.orig_mobs_update_tag = mobs.mob_class.update_tag
-- update nametag and infotext
mobs.mob_class.update_tag = function(self)
-- we are only responsible for talking NPC
if(not(self) or not(self.yl_speak_up)) then
return yl_speak_up.orig_mobs_update_tag(self)
end
local floor = math.floor
local col = "#00FF00"
local qua = self.hp_max / 4
if(self.force_nametag_color) then
col = self.force_nametag_color
elseif self.health <= floor(qua) then
col = "#FF0000"
elseif self.health <= floor(qua * 2) then
col = "#FF6600"
elseif self.health <= floor(qua * 3) then
col = "#FFFF00"
end
local text = ""
if self.horny == true then
text = "\nLoving: " .. (self.hornytimer - (HORNY_TIME + HORNY_AGAIN_TIME))
elseif self.child == true then
text = "\nGrowing: " .. (self.hornytimer - CHILD_GROW_TIME)
elseif self._breed_countdown then
text = "\nBreeding: " .. self._breed_countdown
end
if self.protected then
if self.protected == 2 then
text = text .. "\nProtection: Level 2"
else
text = text .. "\nProtection: Level 1"
end
end
local add_info = ""
if(self.yl_speak_up and self.yl_speak_up.npc_name) then
add_info = "\n"..tostring(self.yl_speak_up.npc_name)
if(self.yl_speak_up.npc_description) then
add_info = add_info..", "..tostring(self.yl_speak_up.npc_description)
end
end
self.infotext = "Health: " .. self.health .. " / " .. self.hp_max
.. add_info
.. (self.owner == "" and "" or "\nOwner: " .. self.owner)
.. text
-- set changes
self.object:set_properties({
nametag = self.nametag,
nametag_color = col,
infotext = self.infotext
})
end