diff options
author | TenPlus1 <kinsellaja@yahoo.com> | 2016-09-05 19:47:08 +0100 |
---|---|---|
committer | TenPlus1 <kinsellaja@yahoo.com> | 2016-09-05 19:47:08 +0100 |
commit | b63317bc21469aa0867308cc4598b0e36ffaf032 (patch) | |
tree | f1b28dfabdc73b77e506ba4f5643b194ffb901a5 /api.lua | |
parent | 046204cf9a1544892070b1cf8991594f13ce0eaa (diff) |
added specific_attack flag for special mob attacks
Diffstat (limited to 'api.lua')
-rw-r--r-- | api.lua | 31 |
1 files changed, 27 insertions, 4 deletions
@@ -975,6 +975,25 @@ function smart_mobs(self, s, p, dist, dtime) end end +-- specific attacks +local specific_attack = function(list, what) + + -- no list so attack default (player, animals etc.) + if list == nil then + return true + end + + -- is found entity on list to attack? + for no = 1, #list do + + if list[no] == what then + return true + end + end + + return false +end + -- monster find someone to attack local monster_attack = function(self) @@ -988,7 +1007,7 @@ local monster_attack = function(self) local s = self.object:getpos() local p, sp, dist local player, obj, min_player - local type = "" + local type, name = "", "" local min_dist = self.view_range + 1 local objs = minetest.get_objects_inside_radius(s, self.view_range) @@ -1002,6 +1021,7 @@ local monster_attack = function(self) else player = objs[n] type = "player" + name = "player" end else obj = objs[n]:get_luaentity() @@ -1009,12 +1029,14 @@ local monster_attack = function(self) if obj then player = obj.object type = obj.type + name = obj.name or "" end end - if type == "player" - or type == "npc" - or (type == "animal" and self.attack_animals == true) then + -- find specific mob to attack, failing that attack player/npc/animal + if specific_attack(self.specific_attack, name) + and (type == "player" or type == "npc" + or (type == "animal" and self.attack_animals == true)) then s = self.object:getpos() p = player:getpos() @@ -2326,6 +2348,7 @@ minetest.register_entity(name, { dogshoot_count = 0, dogshoot_count_max = def.dogshoot_count_max or 5, attack_animals = def.attack_animals or false, + specific_attack = def.specific_attack, on_blast = def.on_blast or do_tnt, |