-- assing ID at spawning (not at first talk) and log it function yl_speak_up.on_spawn(self) --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 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 -- thankyou flux for helping with this function yl_speak_up.alias_mob(old_mob, new_mob) minetest.register_entity( ":" .. old_mob, { initial_properties = { physical = false, -- pointable = false, collide_with_objects = false, -- is_visible = false, glow = -1, -- disable light's effect on texture to make more visible in dark shaded = false, nametag = "Please /bug me", infotext = "I should have been an NPC\nbut something went wrong\nplease report to staff", static_save = true, }, on_activate = function(self, staticdata) local new_entity local pos = self.object:get_pos() if pos and minetest.features.add_entity_with_staticdata then -- if pos is nil then we don't know where we are and we can't add entity. new_entity = minetest.add_entity(pos, new_mob, staticdata) end local data = minetest.deserialize(staticdata) or {} local pos_str = pos and minetest.pos_to_string(pos) or "NO_POS" local owner = data.owner or "NO_OWNER" local id = (data.yl_speak_up or {}).id or "NO_ID" if new_entity then self.object:remove() minetest.log("action", string.format("[yl_speak_up] alias_mob: converted %s ID:%s owned by %s to %s @ %s", old_mob, id, owner, new_mob, pos_str) ) else self.staticdata = staticdata self.object:set_armor_groups({immortal = 1}) minetest.log("error", string.format("[yl_speak_up] alias_mob: error initializing %s ID:%s owned by %s @ %s, keeping %s for safe keeping", new_mob, id, owner, pos_str, old_mob) ) end end, get_staticdata = function(self) return self.staticdata end, on_blast = function() return false, false, {} end, -- TODO allow STAFF to pick up with lasso and move? }) end do local races = {'human', 'elf', 'dwarf', 'goblin', 'orc', 'npc'} for _, race in pairs(races) do -- alias entities yl_speak_up.alias_mob("yl_speak_up:" .. race, "yl_npc:" .. race) -- alias eggs for spawning new NPCs minetest.register_alias("yl_speak_up:" .. race, "yl_npc:" .. race) -- alias eggs that store NPCs picked up with a lasso minetest.register_alias("yl_speak_up:" .. race .. "_set", "yl_npc:" .. race .. "_set") end end