add owner loyalty so that aggressive tamed mobs will attack player foe's

This commit is contained in:
TenPlus1 2017-05-12 10:02:42 +01:00
parent feb26ed940
commit e814a360f6
2 changed files with 16 additions and 14 deletions

27
api.lua
View File

@ -1,5 +1,5 @@
-- Mobs Api (27th April 2017)
-- Mobs Api (12th May 2017)
mobs = {}
mobs.mod = "redo"
@ -1259,7 +1259,6 @@ local follow_flop = function(self)
if p.x > s.x then yaw = yaw + pi end
-- self.object:setyaw(yaw)
yaw = set_yaw(self.object, yaw)
-- anyone but standing npc's can move along
@ -1364,7 +1363,6 @@ local do_states = function(self, dtime)
yaw = (random(0, 360) - 180) / 180 * pi
end
-- self.object:setyaw(yaw)
yaw = set_yaw(self.object, yaw)
end
@ -1438,7 +1436,6 @@ local do_states = function(self, dtime)
if lp.x > s.x then yaw = yaw + pi end
-- look towards land and jump/move in that direction
-- self.object:setyaw(yaw)
yaw = set_yaw(self.object, yaw)
do_jump(self)
set_velocity(self, self.walk_velocity)
@ -1458,7 +1455,6 @@ local do_states = function(self, dtime)
if lp.x > s.x then yaw = yaw + pi end
end
-- self.object:setyaw(yaw)
yaw = set_yaw(self.object, yaw)
-- otherwise randomly turn
@ -1466,7 +1462,6 @@ local do_states = function(self, dtime)
yaw = random() * 2 * pi
-- self.object:setyaw(yaw)
yaw = set_yaw(self.object, yaw)
end
@ -1547,7 +1542,6 @@ local do_states = function(self, dtime)
if p.x > s.x then yaw = yaw + pi end
-- self.object:setyaw(yaw)
yaw = set_yaw(self.object, yaw)
if dist > self.reach then
@ -1708,7 +1702,6 @@ local do_states = function(self, dtime)
if p.x > s.x then yaw = yaw + pi end
-- self.object:setyaw(yaw)
yaw = set_yaw(self.object, yaw)
-- move towards enemy if beyond mob reach
@ -1808,7 +1801,6 @@ local do_states = function(self, dtime)
if p.x > s.x then yaw = yaw + pi end
-- self.object:setyaw(yaw)
yaw = set_yaw(self.object, yaw)
set_velocity(self, 0)
@ -2085,19 +2077,20 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
yaw = yaw + pi
end
-- self.object:setyaw(yaw)
yaw = set_yaw(self.object, yaw)
self.state = "runaway"
self.runaway_timer = 0
self.following = nil
end
local name = hitter:get_player_name() or ""
-- attack puncher and call other mobs for help
if self.passive == false
and self.state ~= "flop"
and self.child == false
and hitter:get_player_name() ~= self.owner
and not mobs.invis[ hitter:get_player_name() ] then
and not mobs.invis[ name ] then
-- attack whoever punched mob
self.state = ""
@ -2113,10 +2106,18 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
if obj then
-- only alert members of same mob
if obj.group_attack == true
and obj.state ~= "attack" then
and obj.state ~= "attack"
and obj.owner ~= name
and obj.name == self.name then
do_attack(obj, hitter)
end
-- have owned mobs attack player threat
if obj.owner == name and obj.owner_loyal then
do_attack(obj, self.object)
end
end
end
end
@ -2267,7 +2268,6 @@ local mob_activate = function(self, staticdata, def)
-- set anything changed above
self.object:set_properties(self)
-- self.object:setyaw((random(0, 360) - 180) / 180 * pi)
set_yaw(self.object, (random(0, 360) - 180) / 180 * pi)
update_tag(self)
end
@ -2494,6 +2494,7 @@ minetest.register_entity(name, {
dogshoot_count2_max = def.dogshoot_count2_max or (def.dogshoot_count_max or 5),
attack_animals = def.attack_animals or false,
specific_attack = def.specific_attack,
owner_loyal = def.owner_loyal,
on_blast = def.on_blast or do_tnt,

View File

@ -1,5 +1,5 @@
MOB API (27th April 2017)
MOB API (12th May 2017)
The mob api is a function that can be called on by other mods to add new animals or monsters into minetest.
@ -25,6 +25,7 @@ This functions registers a new mob as a Minetest entity.
'docile_by_day' when true, mob will not attack during daylight hours unless provoked
'attacks_monsters' usually for npc's to attack monsters in area
'group_attack' true to defend same kind of mobs from attack in area
'owner_loyal' when true owned mobs will attack any monsters you punch
'attack_animals' true for monster to attack animals as well as player and npc's
'specific_attack' has a table of entity names that monsters can attack {"player", "mobs_animal:chicken"}
'hp_min' minimum health