From 471776dde4af3ef3beb6b4eaed81ddd381fa2ab2 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sat, 8 Jul 2023 04:42:15 +0200 Subject: [PATCH] added yl_speak_up.initialize_npc for setting n_ID --- functions.lua | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/functions.lua b/functions.lua index fd9f619..55ec021 100644 --- a/functions.lua +++ b/functions.lua @@ -538,6 +538,30 @@ end -- Make the NPC talk +-- assign n_ID +-- usually this happens when talking to the NPC for the first time; +-- but if you want to you can call this function earlier (on spawn) +-- so that logging of spawning with the ID is possible +yl_speak_up.initialize_npc = function(self) + -- already configured? + if(not(self) or (self.yl_speak_up and self.yl_speak_up.id)) then + return self + end + + 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) + + self.yl_speak_up = { + talk = m_talk, + id = m_id, + textures = self.textures + } + return self +end + + function yl_speak_up.talk(self, clicker) if not clicker and not clicker:is_player() then @@ -563,15 +587,7 @@ function yl_speak_up.talk(self, clicker) -- initialize the mob if necessary; this happens at the time of first talk, not at spawn time! elseif(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 - } + self = yl_speak_up.initialize_npc(self) end -- create a detached inventory for the npc and load its inventory