From 8f4c8f7668bdf7cb5692a531e9cfa5d58c6fb5d4 Mon Sep 17 00:00:00 2001 From: Duane Date: Thu, 4 Aug 2016 04:43:16 -0500 Subject: [PATCH] Fix mob promotion problems. --- abms.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/abms.lua b/abms.lua index 67a9626..c9f9146 100644 --- a/abms.lua +++ b/abms.lua @@ -135,10 +135,13 @@ minetest.register_globalstep(function(dtime) local factor = 1 + (math.max(math.abs(pos.x), math.abs(pos.y), math.abs(pos.z)) / 6200) mob.hp_max = math.floor(mob.hp_max * factor) mob.damage = math.floor(mob.damage * factor) - mob.object:set_hp(mob.hp_max) - mob.health = mob.hp_max + mob.health = math.floor(mob.health * factor) + mob.object:set_hp(mob.health) mob.initial_promotion = true check_for_death(mob) + + --local name = mob.object:get_entity_name() or '' + --print('Promoting '..name..': '..mob.health..' health, '..mob.damage..' damage') end end end @@ -422,11 +425,14 @@ minetest.register_abm({ local name = desc.name local level = desc.level - local mob = minetest.add_entity(pos, name) + local obj = minetest.add_entity(pos, name) + if not obj then + return + end + local mob = obj:get_luaentity() if not mob then return end - --print('Spawned '..name) if mob.hp_max and mob.object and mob.health and mob.damage then local factor = 1 + (math.max(math.abs(pos.x), math.abs(pos.y), math.abs(pos.z)) / 6200) @@ -434,10 +440,12 @@ minetest.register_abm({ factor = factor * 1.5 mob.hp_max = math.floor(mob.hp_max * factor) mob.damage = math.floor(mob.damage * factor) - mob.object:set_hp(mob.hp_max) - mob.health = mob.hp_max + mob.health = math.floor(mob.health * factor) + mob.object:set_hp(mob.health) mob.initial_promotion = true check_for_death(mob) + + --print('Dungeon quality '..name..': '..mob.health..' health, '..mob.damage..' damage') end end })