From cd4fb6f2a62e9c0e947b6794bfe89a2c827a42c5 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Sun, 26 Mar 2023 08:31:40 +0100 Subject: [PATCH] add friendly_fire mob setting for arrows (thx eschan145) --- api.lua | 17 ++++++++++++++--- api.txt | 3 +++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/api.lua b/api.lua index d6af0c0..ecb469b 100644 --- a/api.lua +++ b/api.lua @@ -25,7 +25,7 @@ local use_cmi = minetest.global_exists("cmi") mobs = { mod = "redo", - version = "20230325", + version = "20230326", intllib = S, invis = minetest.global_exists("invisibility") and invisibility or {} } @@ -197,6 +197,7 @@ mobs.mob_class = { attack_animals = false, attack_players = true, attack_npcs = true, + friendly_fire = true, facing_fence = false, _breed_countdown = nil, _cmi_is_mob = true @@ -2953,8 +2954,17 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage) end) end - -- do damage - self.health = self.health - floor(damage) + -- check for friendly fire (arrows from same mob) + if self.friendly_fire then + self.health = self.health - floor(damage) -- do damage regardless + else + local entity = hitter and hitter:get_luaentity() + + -- check if arrow from same mob, if so then do no damage + if entity and entity.name ~= self.arrow then + self.health = self.health - floor(damage) + end + end -- exit here if dead, check for tools with fire damage local hot = tool_capabilities and tool_capabilities.damage_groups @@ -3604,6 +3614,7 @@ minetest.register_entity(name, setmetatable({ attack_players = def.attack_players, attack_npcs = def.attack_npcs, specific_attack = def.specific_attack, + friendly_fire = def.friendly_fire, runaway_from = def.runaway_from, owner_loyal = def.owner_loyal, pushable = def.pushable, diff --git a/api.txt b/api.txt index c97a513..0e7bc33 100644 --- a/api.txt +++ b/api.txt @@ -150,6 +150,9 @@ functions needed for the mob to work properly which contains the following: arrow/fireball appears on mob. 'specific_attack' has a table of entity names that mob can also attack e.g. {"player", "mobs_animal:chicken"}. + 'friendly_fire` when set to false, mobs will not be able to harm other + mobs of the same type with friendly fire arrows. + Defaults to true. 'runaway_from' contains a table with mob names to run away from, add "player" to list to runaway from player also. 'ignore_invisibility' When true mob will still be able to see and attack