diff --git a/config.lua b/config.lua index 09da124..8fed351 100644 --- a/config.lua +++ b/config.lua @@ -14,6 +14,9 @@ -- Set this only if you need to force-mute an NPC or something like that. yl_speak_up.enable_staff_based_editing = true +-- enable/disable special mobs in the yl_speak_up-namespace (mobs_redo based) +yl_speak_up.enable_yl_mobs = true + -- Do the NPCs talk right after they spawned? yl_speak_up.talk_after_spawn = true diff --git a/functions.lua b/functions.lua index 23d1b3b..569d6be 100644 --- a/functions.lua +++ b/functions.lua @@ -393,15 +393,29 @@ end function yl_speak_up.talk(self, clicker) - if not clicker and not clicker:is_player() then - return - end - if not self then - return - end - if not self.yl_speak_up or not self.yl_speak_up.id then - return - end + if not clicker and not clicker:is_player() then + return + end + if not self then + return + end + + -- initialize the mob if necessary; this happens at the time of first talk, not at spawn time! + if(not(self.yl_speak_up) or not(self.yl_speak_up.id)) then + 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) + + self.yl_speak_up = { + talk = true, + id = m_id, + textures = self.textures + } + end + + -- create a detached inventory for the npc and load its inventory + yl_speak_up.load_npc_inventory("n_"..tostring(self.yl_speak_up.id)) + local npc_id = self.yl_speak_up.id local n_id = "n_" .. npc_id diff --git a/init.lua b/init.lua index 9cb0aa8..607a482 100644 --- a/init.lua +++ b/init.lua @@ -36,8 +36,6 @@ dofile(modpath .. "command_npc_talk_privs.lua") dofile(modpath .. "add_generic_dialogs.lua") -- the actual command to add or remove generic npc dialogs dofile(modpath .. "command_npc_talk_generic.lua") --- react to right-click etc. -dofile(modpath .. "interface_mobs_api.lua") -- handle on_player_receive_fields and showing of formspecs dofile(modpath .. "show_fs.lua") -- general decoration part for main formspec, trade window etc. @@ -113,8 +111,13 @@ dofile(modpath .. "register_node_punch.lua") if(yl_speak_up.enable_staff_based_editing) then dofile(modpath .. "tools.lua") end --- the actual mobs, using mobs_redo -dofile(modpath .. "mobs.lua") +-- mobs registered as yl_speak_up-mobs (based on mobs_redo) +if(yl_speak_up.enable_yl_mobs) then + -- react to right-click etc. + dofile(modpath .. "interface_mobs_api.lua") + -- the actual mobs, using mobs_redo + dofile(modpath .. "mobs.lua") +end --dofile(modpath .. "debug.lua") minetest.mkdir(yl_speak_up.worldpath..yl_speak_up.path) diff --git a/interface_mobs_api.lua b/interface_mobs_api.lua index 1c5cd33..0ac7a84 100644 --- a/interface_mobs_api.lua +++ b/interface_mobs_api.lua @@ -30,12 +30,14 @@ 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 = { @@ -60,11 +62,11 @@ function yl_speak_up.on_spawn(self) end function yl_speak_up.after_activate(self, staticdata, def, dtime) - minetest.log( - "action", - "[MOD] yl_speak_up: NPC with ID n_" .. - self.yl_speak_up.id .. " activated at " .. minetest.pos_to_string(self.object:get_pos(), 0) - ) +-- minetest.log( +-- "action", +-- "[MOD] yl_speak_up: NPC with ID n_" .. +-- self.yl_speak_up.id .. " activated at " .. minetest.pos_to_string(self.object:get_pos(), 0) +-- ) if yl_speak_up.status == 2 then self.object:remove() @@ -89,7 +91,4 @@ function yl_speak_up.after_activate(self, staticdata, def, dtime) end yl_speak_up.update_nametag(self) - - -- create a detached inventory for the npc and load its inventory - yl_speak_up.load_npc_inventory("n_"..tostring(self.yl_speak_up.id)) end