-- Make the NPC talk (mobs_redo interface) --### -- Mob functions --### function yl_speak_up.init_mob_table() return false end function yl_speak_up.on_rightclick(self, clicker) --local item = clicker:get_wielded_item() local name = clicker:get_player_name() -- Take the mob only with net or lasso if self.owner and self.owner == name then if mobs:capture_mob(self, clicker, nil, 100, 100, true, nil) then return end end -- protect npc with mobs:protector if mobs:protect(self, clicker) then return end -- bring up the dialog options if clicker then yl_speak_up.talk(self, clicker) return end end function yl_speak_up.on_spawn(self) --Let's assign an ID -- TODO make this global mute available local m_talk = yl_speak_up.talk_after_spawn or true local m_id = yl_speak_up.number_of_npcs + 1 yl_speak_up.number_of_npcs = m_id yl_speak_up.modstorage:set_int("amount", m_id) -- TODO currently. mob_table doesn't really do anything yl_speak_up.mob_table[m_id] = "yl_speak_up:test_npc" self.yl_speak_up = { talk = m_talk, id = m_id, textures = self.textures } --Let's protect it self.protected = true self.tamed = true self.object:set_armor_groups({immortal = 100}) yl_speak_up.log_change("-", "n_"..self.yl_speak_up.id, "spawned at "..minetest.pos_to_string(self.object:get_pos()), "action") --Let's do it only once return true end function yl_speak_up.after_activate(self, staticdata, def, dtime) -- this scrolls far too much -- yl_speak_up.log_change("-", "n_"..self.yl_speak_up.id, -- "activated at "..minetest.pos_to_string(self.object:get_pos()), "action") if yl_speak_up.status == 2 then self.object:remove() return true end if self.yl_speak_up and self.yl_speak_up.skin then local tex = self.yl_speak_up.skin self.object:set_properties({textures = {tex[1], tex[2], tex[3], tex[4]}}) end if yl_speak_up.infotext then local i_text = "" if self.yl_speak_up.npc_name then i_text = i_text .. self.yl_speak_up.npc_name .. "\n" end if self.yl_speak_up.npc_description then i_text = i_text .. self.yl_speak_up.npc_description .. "\n" end i_text = i_text .. yl_speak_up.infotext self.object:set_properties({infotext = i_text}) end 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