From c50c8ee073ee33f17289964df4a0866975e3c61b Mon Sep 17 00:00:00 2001 From: whosit Date: Fri, 14 Jul 2023 13:40:16 +0300 Subject: [PATCH] automatically convert yl_speak_up entities into yl_npc on load alias new eggs and NPCs stored in eggs log id and owner --- mobs.lua | 381 +++++++++---------------------------------------------- 1 file changed, 60 insertions(+), 321 deletions(-) diff --git a/mobs.lua b/mobs.lua index d524e10..e261e97 100644 --- a/mobs.lua +++ b/mobs.lua @@ -18,336 +18,75 @@ function yl_speak_up.on_spawn(self) return true end -mobs:register_mob("yl_speak_up:human", { - type = "npc", - passive = true, - damage = 9, - attack_type = "dogfight", - attacks_monsters = true, - attack_npcs = false, - owner_loyal = false, - pathfinding = false, - hp_min = 60, - hp_max = 100, - armor = 0, - collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}, - visual = "mesh", - visual_size = {x = 1, y = 1}, - mesh = "skinsdb_3d_armor_character_5.b3d", - drawtype = "front", - textures = {{ - "blank.png", -- cape? - "yl_speak_up_main_default.png", -- 64x64 skin - "3d_armor_trans.png", -- shield?! - "3d_armor_trans.png", -- item right hand - }}, - makes_footstep_sound = true, - sounds = {}, - walk_velocity = 2, - run_velocity = 3, - jump = false, - water_damage = 0, - lava_damage = 0, - light_damage = 0, - view_range = 4, - owner = "Haven", - order = "stand", - fear_height = 3, - animation = { - speed_normal = 30, - speed_run = 30, - stand_start = 0, - stand_end = 79, - walk_start = 168, - walk_end = 187, - run_start = 168, - run_end = 187, - punch_start = 200, - punch_end = 219, - }, - on_rightclick = yl_speak_up.mobs_on_rightclick, - on_spawn = yl_speak_up.on_spawn, - after_activate = yl_speak_up.mobs_after_activate -}) +-- 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, + }, -mobs:register_egg("yl_speak_up:human", "Human", "wool_blue.png", 1) + on_activate = function(self, staticdata) + local new_entity + local pos = self.object:get_pos() -mobs:register_mob("yl_speak_up:elf", { - type = "npc", - passive = true, - damage = 9, - attack_type = "dogfight", - attacks_monsters = true, - attack_npcs = false, - owner_loyal = false, - pathfinding = false, - hp_min = 60, - hp_max = 100, - armor = 0, - collisionbox = {-0.25, 0.0, -0.25, 0.25, 1.9, 0.25}, - visual = "mesh", - visual_size = {x = 0.9, y = 1.1}, - mesh = "skinsdb_3d_armor_character_5.b3d", - drawtype = "front", - textures = {{ - "blank.png", -- cape? - "yl_speak_up_main_default.png", -- 64x64 skin - "3d_armor_trans.png", -- shield?! - "3d_armor_trans.png", -- item right hand - }}, - makes_footstep_sound = true, - sounds = {}, - walk_velocity = 2, - run_velocity = 3, - jump = false, - water_damage = 0, - lava_damage = 0, - light_damage = 0, - view_range = 4, - owner = "Haven", - order = "stand", - fear_height = 3, - animation = { - speed_normal = 30, - speed_run = 30, - stand_start = 0, - stand_end = 79, - walk_start = 168, - walk_end = 187, - run_start = 168, - run_end = 187, - punch_start = 200, - punch_end = 219, - }, + 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 - on_rightclick = yl_speak_up.mobs_on_rightclick, - on_spawn = yl_speak_up.on_spawn, - after_activate = yl_speak_up.mobs_after_activate -}) + 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" -mobs:register_egg("yl_speak_up:elf", "Elf", "wool_cyan.png", 1) + 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, -mobs:register_mob("yl_speak_up:dwarf", { - type = "npc", - passive = true, - damage = 9, - attack_type = "dogfight", - attacks_monsters = true, - attack_npcs = false, - owner_loyal = false, - pathfinding = false, - hp_min = 60, - hp_max = 100, - armor = 0, - collisionbox = {-0.35, 0.0, -0.35, 0.35, 1.4, 0.35}, - visual = "mesh", - visual_size = {x = 1.1, y = 0.8}, - mesh = "skinsdb_3d_armor_character_5.b3d", - drawtype = "front", - textures = {{ - "blank.png", -- cape? - "yl_speak_up_main_default.png", -- 64x64 skin - "3d_armor_trans.png", -- shield?! - "3d_armor_trans.png", -- item right hand - }}, - makes_footstep_sound = true, - sounds = {}, - walk_velocity = 2, - run_velocity = 3, - jump = false, - water_damage = 0, - lava_damage = 0, - light_damage = 0, - view_range = 4, - owner = "Haven", - order = "stand", - fear_height = 3, - animation = { - speed_normal = 30, - speed_run = 30, - stand_start = 0, - stand_end = 79, - walk_start = 168, - walk_end = 187, - run_start = 168, - run_end = 187, - punch_start = 200, - punch_end = 219, - }, + get_staticdata = function(self) + return self.staticdata + end, - on_rightclick = yl_speak_up.mobs_on_rightclick, - on_spawn = yl_speak_up.on_spawn, - after_activate = yl_speak_up.mobs_after_activate -}) + on_blast = function() + return false, false, {} + end, -mobs:register_egg("yl_speak_up:dwarf", "Dwarf", "wool_red.png", 1) + -- TODO allow STAFF to pick up with lasso and move? + }) +end -mobs:register_mob("yl_speak_up:goblin", { - type = "npc", - passive = true, - damage = 9, - attack_type = "dogfight", - attacks_monsters = true, - attack_npcs = false, - owner_loyal = false, - pathfinding = false, - hp_min = 60, - hp_max = 100, - armor = 0, - collisionbox = {-0.25, 0.0, -0.25, 0.25, 1.4, 0.25}, - visual = "mesh", - visual_size = {x = 0.7, y = 0.8}, - mesh = "skinsdb_3d_armor_character_5.b3d", - drawtype = "front", - textures = {{ - "blank.png", -- cape? - "yl_speak_up_main_default.png", -- 64x64 skin - "3d_armor_trans.png", -- shield?! - "3d_armor_trans.png", -- item right hand - }}, - makes_footstep_sound = true, - sounds = {}, - walk_velocity = 2, - run_velocity = 3, - jump = false, - water_damage = 0, - lava_damage = 0, - light_damage = 0, - view_range = 4, - owner = "Haven", - order = "stand", - fear_height = 3, - animation = { - speed_normal = 30, - speed_run = 30, - stand_start = 0, - stand_end = 79, - walk_start = 168, - walk_end = 187, - run_start = 168, - run_end = 187, - punch_start = 200, - punch_end = 219, - }, - on_rightclick = yl_speak_up.mobs_on_rightclick, - on_spawn = yl_speak_up.on_spawn, - after_activate = yl_speak_up.mobs_after_activate -}) +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) -mobs:register_egg("yl_speak_up:goblin", "Goblin", "wool_yellow.png", 1) + -- 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 -mobs:register_mob("yl_speak_up:orc", { - type = "npc", - passive = true, - damage = 9, - attack_type = "dogfight", - attacks_monsters = true, - attack_npcs = false, - owner_loyal = false, - pathfinding = false, - hp_min = 60, - hp_max = 100, - armor = 0, - collisionbox = {-0.35, 0.0, -0.35, 0.35, 1.9, 0.35}, - visual = "mesh", - visual_size = {x = 1.1, y = 1.1}, - mesh = "skinsdb_3d_armor_character_5.b3d", - drawtype = "front", - textures = {{ - "blank.png", -- cape? - "yl_speak_up_main_default.png", -- 64x64 skin - "3d_armor_trans.png", -- shield?! - "3d_armor_trans.png", -- item right hand - }}, - makes_footstep_sound = true, - sounds = {}, - walk_velocity = 2, - run_velocity = 3, - jump = false, - water_damage = 0, - lava_damage = 0, - light_damage = 0, - view_range = 4, - owner = "Haven", - order = "stand", - fear_height = 3, - animation = { - speed_normal = 30, - speed_run = 30, - stand_start = 0, - stand_end = 79, - walk_start = 168, - walk_end = 187, - run_start = 168, - run_end = 187, - punch_start = 200, - punch_end = 219, - }, - - on_rightclick = yl_speak_up.mobs_on_rightclick, - on_spawn = yl_speak_up.on_spawn, - after_activate = yl_speak_up.mobs_after_activate -}) - -mobs:register_egg("yl_speak_up:orc", "Orc", "wool_dark_green.png", 1) - --- ### --- Test --- ### - -mobs:register_mob("yl_speak_up:npc", { - type = "npc", - passive = true, - damage = 9, - attack_type = "dogfight", - attacks_monsters = true, - attack_npcs = false, - owner_loyal = false, - pathfinding = false, - hp_min = 60, - hp_max = 100, - armor = 0, - collisionbox = {-0.35, 0.0, -0.35, 0.35, 1.9, 0.35}, - visual = "mesh", - visual_size = {x = 1.1, y = 1.1}, - mesh = "skinsdb_3d_armor_character_5.b3d", - drawtype = "front", - textures = {{ - "blank.png", -- cape? wenn 64x32, dann 56,20 - 63,31, wenn 128x64, dann 111,39 - 127,63, rest invis - "yl_speak_up_main_default.png", -- 64x64 skin oder auch 128x128? - "blank.png", -- shield?! 64x32 - "3d_armor_trans.png", -- item right hand (16x16) - }}, - makes_footstep_sound = true, - sounds = {}, - walk_velocity = 2, - run_velocity = 3, - jump = false, - water_damage = 0, - lava_damage = 0, - light_damage = 0, - view_range = 4, - owner = "Haven", - order = "stand", - fear_height = 3, - animation = { - speed_normal = 30, - speed_run = 30, - stand_start = 0, - stand_end = 79, - walk_start = 168, - walk_end = 187, - run_start = 168, - run_end = 187, - punch_start = 200, - punch_end = 219, - }, - - on_rightclick = yl_speak_up.mobs_on_rightclick, - on_spawn = yl_speak_up.on_spawn, - after_activate = yl_speak_up.mobs_after_activate -}) - -mobs:register_egg("yl_speak_up:npc", "NPC", "wool_black.png", 1) +end