From 491675ad09904ed602f7bc8916d59078f87cda22 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sat, 8 Jul 2023 04:48:20 +0200 Subject: [PATCH] adjusted interface for mobs --- interface_mobs_api.lua | 36 +++++++++++++++++------------------- mobs.lua | 12 ++++++------ 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/interface_mobs_api.lua b/interface_mobs_api.lua index d6ae7c3..7f93476 100644 --- a/interface_mobs_api.lua +++ b/interface_mobs_api.lua @@ -39,30 +39,24 @@ function yl_speak_up.mobs_on_rightclick(self, clicker) end end +-- TODO: -> goes to yl_npc 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}) + --Let's assign an ID (usually this happens at first talk) + self = yl_speak_up.initialize_npc(self) + + if(not(self) or not(self.yl_speak_up) or not(self.yl_speak_up.id)) then + -- something went very wrong + 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" + yl_speak_up.log_change("-", "n_"..self.yl_speak_up.id, "spawned at "..minetest.pos_to_string(self.object:get_pos()), "action") @@ -70,7 +64,7 @@ function yl_speak_up.on_spawn(self) return true end -function yl_speak_up.after_activate(self, staticdata, def, dtime) +function yl_speak_up.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") @@ -80,15 +74,18 @@ function yl_speak_up.after_activate(self, staticdata, def, dtime) 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 @@ -101,6 +98,7 @@ function yl_speak_up.after_activate(self, staticdata, def, dtime) self.object:set_properties({infotext = i_text}) end + -- set nametag (especially color) yl_speak_up.update_nametag(self) end diff --git a/mobs.lua b/mobs.lua index c26258c..a428d96 100644 --- a/mobs.lua +++ b/mobs.lua @@ -48,7 +48,7 @@ mobs:register_mob("yl_speak_up:human", { on_rightclick = yl_speak_up.mobs_on_rightclick, on_spawn = yl_speak_up.on_spawn, - after_activate = yl_speak_up.after_activate + after_activate = yl_speak_up.mobs_after_activate }) mobs:register_egg("yl_speak_up:human", "Human", "wool_blue.png", 1) @@ -103,7 +103,7 @@ mobs:register_mob("yl_speak_up:elf", { on_rightclick = yl_speak_up.mobs_on_rightclick, on_spawn = yl_speak_up.on_spawn, - after_activate = yl_speak_up.after_activate + after_activate = yl_speak_up.mobs_after_activate }) mobs:register_egg("yl_speak_up:elf", "Elf", "wool_cyan.png", 1) @@ -158,7 +158,7 @@ mobs:register_mob("yl_speak_up:dwarf", { on_rightclick = yl_speak_up.mobs_on_rightclick, on_spawn = yl_speak_up.on_spawn, - after_activate = yl_speak_up.after_activate + after_activate = yl_speak_up.mobs_after_activate }) mobs:register_egg("yl_speak_up:dwarf", "Dwarf", "wool_red.png", 1) @@ -213,7 +213,7 @@ mobs:register_mob("yl_speak_up:goblin", { on_rightclick = yl_speak_up.mobs_on_rightclick, on_spawn = yl_speak_up.on_spawn, - after_activate = yl_speak_up.after_activate + after_activate = yl_speak_up.mobs_after_activate }) mobs:register_egg("yl_speak_up:goblin", "Goblin", "wool_yellow.png", 1) @@ -268,7 +268,7 @@ mobs:register_mob("yl_speak_up:orc", { on_rightclick = yl_speak_up.mobs_on_rightclick, on_spawn = yl_speak_up.on_spawn, - after_activate = yl_speak_up.after_activate + after_activate = yl_speak_up.mobs_after_activate }) mobs:register_egg("yl_speak_up:orc", "Orc", "wool_dark_green.png", 1) @@ -327,7 +327,7 @@ mobs:register_mob("yl_speak_up:npc", { on_rightclick = yl_speak_up.mobs_on_rightclick, on_spawn = yl_speak_up.on_spawn, - after_activate = yl_speak_up.after_activate + after_activate = yl_speak_up.mobs_after_activate }) mobs:register_egg("yl_speak_up:npc", "NPC", "wool_black.png", 1)