From e92cabde42b0364693f13382a529f7592e836d22 Mon Sep 17 00:00:00 2001 From: alek13 Date: Fri, 22 Dec 2023 03:25:06 +0300 Subject: [PATCH] Mobs: Ability to specify `armor_groups`. (Copied from upstream). Relates to #25 --- mods/_various/mobs/api.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mods/_various/mobs/api.lua b/mods/_various/mobs/api.lua index 7142916f4..613271254 100644 --- a/mods/_various/mobs/api.lua +++ b/mods/_various/mobs/api.lua @@ -54,6 +54,7 @@ local atan = function(x) return atann(x) end end +local table_copy = table.copy -- Load settings @@ -2202,9 +2203,19 @@ local mob_activate = function(self, staticdata, def) self.path.stuck = false self.path.following = false -- currently following path? self.path.stuck_timer = 0 -- if stuck for too long search for path - -- end init - self.object:set_armor_groups({immortal = 1, fleshy = self.armor}) + -- Armor groups (immortal = 1 for custom damage handling) + local armor + + if type(self.armor) == "table" then + armor = table_copy(self.armor) + else + armor = {fleshy = self.armor, immortal = 1} + end + + self.object:set_armor_groups(armor) + + -- mob defaults self.old_y = self.object:get_pos().y self.old_health = self.health self.sounds.distance = self.sounds.distance or 10