-- Make the NPC talk (mobs_redo interface) --### -- Mob functions --### -- TODO: mob_table is currently unused function yl_speak_up.init_mob_table() return false end -- -- TODO currently. mob_table doesn't really do anything -- yl_speak_up.mob_table[self.yl_speak_up.id] = "yl_speak_up:test_npc" -- this only makes sense if mobs_redo exists and is loaded if(not(minetest.get_modpath("mobs")) or not(minetest.global_exists("mobs")) or not(mobs.mob_class)) then minetest.log("action","[MOD] yl_speak_up Info: mobs_redo mod not found. Not loading interface.") return end -- React to right-clicking a mobs_redo mob: -- * capture the mob with a lasso or net (if appropriate) -- * protect the mob with a protector -- * if none of the above applies: actually talk to the mob -- This is so often needed (but also mobs_redo specific!) that we provide -- an extra easy-to-call function here. function yl_speak_up.do_mobs_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 local pos = self.object:get_pos() if mobs:capture_mob(self, clicker, nil, 100, 100, true, nil) then if(self.yl_speak_up) then minetest.log("action","[MOD] yl_speak_up ".. " NPC n_"..tostring(self.yl_speak_up.id).. " named "..tostring(self.yl_speak_up.npc_name).. " (owned by "..tostring(self.owner).. ") picked up by "..tostring(clicker:get_player_name()).. " at pos "..minetest.pos_to_string(pos, 0)..".") end return end end -- protect npc with mobs:protector if mobs:protect(self, clicker) then if(self.yl_speak_up) then minetest.log("action","[MOD] yl_speak_up ".. " NPC n_"..tostring(self.yl_speak_up.id).. " named "..tostring(self.yl_speak_up.npc_name).. " (owned by "..tostring(self.owner).. ") protected with protector by "..tostring(clicker:get_player_name()).. " at pos "..minetest.pos_to_string(pos, 0)..".") end return end -- bring up the dialog options if clicker then yl_speak_up.talk(self, clicker) return end end function yl_speak_up.do_mobs_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") -- we are not (yet?) responsible for this mob if(not(self.yl_speak_up)) then return true end if yl_speak_up.status == 2 then self.object:remove() return true end -- load the texture/skin of the NPC 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 -- the NPC may have another animation (i.e. sitting) if self.yl_speak_up and self.yl_speak_up.animation then self.object:set_animation(self.yl_speak_up.animation) end -- add a more informative infotext 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 -- set nametag (especially color) yl_speak_up.update_nametag(self) end -- prevent NPC from getting hurt by special nodes -- This has another positive side-effect: update_tag doesn't get called constantly if(not(yl_speak_up.orig_mobs_do_env_damage)) then yl_speak_up.orig_mobs_do_env_damage = mobs.mob_class.do_env_damage end mobs.mob_class.do_env_damage = 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_do_env_damage(self) end -- *no* env dammage for NPC return end -- we need to override this function from mobs_redo mod so that color -- changes to the name tag color are possible -- BUT: Only do this once. NOT at each reset! if(not(yl_speak_up.orig_mobs_update_tag)) then yl_speak_up.orig_mobs_update_tag = mobs.mob_class.update_tag end -- 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 qua = 0 local floor = math.floor local col = "#00FF00" local prop = self.object:get_properties() local hp_max = 0 if(prop) then hp_max = prop.hp_max else hp_max = self.hp_max end local qua = hp_max / 6 if(self.force_nametag_color) then col = self.force_nametag_color elseif self.health <= qua then col = "#FF0000" elseif self.health <= (qua * 2) then col = "#FF7A00" elseif self.health <= (qua * 3) then col = "#FFB500" elseif self.health <= (qua * 4) then col = "#FFFF00" elseif self.health <= (qua * 5) then col = "#B4FF00" elseif self.health > (qua * 5) then col = "#00FF00" end local text = "" if self.horny == true then local HORNY_TIME = 30 local HORNY_AGAIN_TIME = 60 * 5 -- 5 minutes text = "\nLoving: " .. (self.hornytimer - (HORNY_TIME + HORNY_AGAIN_TIME)) elseif self.child == true then local CHILD_GROW_TIME = 60 * 20 -- 20 minutes 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 .. " / " .. 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