forked from mtcontrib/mobs_redo
supports invisibility, lava/water checks added, code tidied/tweaked
This commit is contained in:
parent
d0fc69d458
commit
7d77124aa0
74
api.lua
74
api.lua
@ -1,9 +1,13 @@
|
|||||||
|
|
||||||
-- Mobs Api (7th June 2016)
|
-- Mobs Api (9th June 2016)
|
||||||
|
|
||||||
mobs = {}
|
mobs = {}
|
||||||
mobs.mod = "redo"
|
mobs.mod = "redo"
|
||||||
|
|
||||||
|
-- Invisibility mod
|
||||||
|
|
||||||
|
local invisibility = invisibility or {}
|
||||||
|
|
||||||
-- Load settings
|
-- Load settings
|
||||||
local damage_enabled = minetest.setting_getbool("enable_damage")
|
local damage_enabled = minetest.setting_getbool("enable_damage")
|
||||||
local peaceful_only = minetest.setting_getbool("only_peaceful_mobs")
|
local peaceful_only = minetest.setting_getbool("only_peaceful_mobs")
|
||||||
@ -554,6 +558,10 @@ end
|
|||||||
-- should mob follow what I'm holding ?
|
-- should mob follow what I'm holding ?
|
||||||
function follow_holding(self, clicker)
|
function follow_holding(self, clicker)
|
||||||
|
|
||||||
|
if invisibility[clicker:get_player_name()] then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
local item = clicker:get_wielded_item()
|
local item = clicker:get_wielded_item()
|
||||||
local t = type(self.follow)
|
local t = type(self.follow)
|
||||||
|
|
||||||
@ -930,8 +938,13 @@ local monster_attack = function(self)
|
|||||||
|
|
||||||
if objs[n]:is_player() then
|
if objs[n]:is_player() then
|
||||||
|
|
||||||
|
if invisibility[ objs[n]:get_player_name() ] then
|
||||||
|
|
||||||
|
type = ""
|
||||||
|
else
|
||||||
player = objs[n]
|
player = objs[n]
|
||||||
type = "player"
|
type = "player"
|
||||||
|
end
|
||||||
else
|
else
|
||||||
obj = objs[n]:get_luaentity()
|
obj = objs[n]:get_luaentity()
|
||||||
|
|
||||||
@ -1026,8 +1039,11 @@ local follow_flop = function(self)
|
|||||||
|
|
||||||
for n = 1, #players do
|
for n = 1, #players do
|
||||||
|
|
||||||
if get_distance(players[n]:getpos(), s) < self.view_range then
|
if get_distance(players[n]:getpos(), s) < self.view_range
|
||||||
|
and not invisibility[ players[n]:get_player_name() ] then
|
||||||
|
|
||||||
self.following = players[n]
|
self.following = players[n]
|
||||||
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1083,17 +1099,13 @@ local follow_flop = function(self)
|
|||||||
z = p.z - s.z
|
z = p.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
-- if vec.x ~= 0
|
local yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
||||||
-- and vec.z ~= 0 then
|
|
||||||
|
|
||||||
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
|
||||||
|
|
||||||
if p.x > s.x then
|
if p.x > s.x then
|
||||||
yaw = yaw + pi
|
yaw = yaw + pi
|
||||||
end
|
end
|
||||||
|
|
||||||
self.object:setyaw(yaw)
|
self.object:setyaw(yaw)
|
||||||
-- end
|
|
||||||
|
|
||||||
-- anyone but standing npc's can move along
|
-- anyone but standing npc's can move along
|
||||||
if dist > self.reach
|
if dist > self.reach
|
||||||
@ -1196,15 +1208,11 @@ local do_states = function(self, dtime)
|
|||||||
z = lp.z - s.z
|
z = lp.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
-- if vec.x ~= 0
|
|
||||||
-- and vec.z ~= 0 then
|
|
||||||
|
|
||||||
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
||||||
|
|
||||||
if lp.x > s.x then
|
if lp.x > s.x then
|
||||||
yaw = yaw + pi
|
yaw = yaw + pi
|
||||||
end
|
end
|
||||||
-- end
|
|
||||||
else
|
else
|
||||||
yaw = (random(0, 360) - 180) / 180 * pi
|
yaw = (random(0, 360) - 180) / 180 * pi
|
||||||
end
|
end
|
||||||
@ -1232,9 +1240,24 @@ local do_states = function(self, dtime)
|
|||||||
elseif self.state == "walk" then
|
elseif self.state == "walk" then
|
||||||
|
|
||||||
local s = self.object:getpos()
|
local s = self.object:getpos()
|
||||||
local lp = minetest.find_node_near(s, 1, {"group:water"})
|
local lp = nil
|
||||||
|
|
||||||
-- if water nearby then turn away
|
-- is there something I need to avoid?
|
||||||
|
if self.water_damage > 0
|
||||||
|
and self.lava_damage > 0 then
|
||||||
|
|
||||||
|
lp = minetest.find_node_near(s, 1, {"group:water", "group:lava"})
|
||||||
|
|
||||||
|
elseif self.water_damage > 0 then
|
||||||
|
|
||||||
|
lp = minetest.find_node_near(s, 1, {"group:water"})
|
||||||
|
|
||||||
|
elseif self.lava_damage > 0 then
|
||||||
|
|
||||||
|
lp = minetest.find_node_near(s, 1, {"group:lava"})
|
||||||
|
end
|
||||||
|
|
||||||
|
-- if something then avoid
|
||||||
if lp then
|
if lp then
|
||||||
|
|
||||||
local vec = {
|
local vec = {
|
||||||
@ -1243,9 +1266,6 @@ local do_states = function(self, dtime)
|
|||||||
z = lp.z - s.z
|
z = lp.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
-- if vec.x ~= 0
|
|
||||||
-- and vec.z ~= 0 then
|
|
||||||
|
|
||||||
yaw = atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
|
yaw = atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
|
||||||
|
|
||||||
if lp.x > s.x then
|
if lp.x > s.x then
|
||||||
@ -1253,7 +1273,6 @@ local do_states = function(self, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.object:setyaw(yaw)
|
self.object:setyaw(yaw)
|
||||||
-- end
|
|
||||||
|
|
||||||
-- otherwise randomly turn
|
-- otherwise randomly turn
|
||||||
elseif random(1, 100) <= 30 then
|
elseif random(1, 100) <= 30 then
|
||||||
@ -1345,9 +1364,6 @@ local do_states = function(self, dtime)
|
|||||||
z = p.z - s.z
|
z = p.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
-- if vec.x ~= 0
|
|
||||||
-- and vec.z ~= 0 then
|
|
||||||
|
|
||||||
yaw = atan(vec.z / vec.x) + pi / 2 - self.rotate
|
yaw = atan(vec.z / vec.x) + pi / 2 - self.rotate
|
||||||
|
|
||||||
if p.x > s.x then
|
if p.x > s.x then
|
||||||
@ -1355,7 +1371,6 @@ local do_states = function(self, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.object:setyaw(yaw)
|
self.object:setyaw(yaw)
|
||||||
-- end
|
|
||||||
|
|
||||||
if dist > self.reach then
|
if dist > self.reach then
|
||||||
|
|
||||||
@ -1396,7 +1411,6 @@ local do_states = function(self, dtime)
|
|||||||
self.object:settexturemod("")
|
self.object:settexturemod("")
|
||||||
else
|
else
|
||||||
self.object:settexturemod("^[brighten")
|
self.object:settexturemod("^[brighten")
|
||||||
--self.object:settexturemod("^[colorize:#ff880070")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.blinkstatus = not self.blinkstatus
|
self.blinkstatus = not self.blinkstatus
|
||||||
@ -1527,9 +1541,6 @@ local do_states = function(self, dtime)
|
|||||||
z = p.z - s.z
|
z = p.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
-- if vec.x ~= 0
|
|
||||||
-- and vec.z ~= 0 then
|
|
||||||
|
|
||||||
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
||||||
|
|
||||||
if p.x > s.x then
|
if p.x > s.x then
|
||||||
@ -1537,7 +1548,6 @@ local do_states = function(self, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.object:setyaw(yaw)
|
self.object:setyaw(yaw)
|
||||||
-- end
|
|
||||||
|
|
||||||
-- move towards enemy if beyond mob reach
|
-- move towards enemy if beyond mob reach
|
||||||
if dist > self.reach then
|
if dist > self.reach then
|
||||||
@ -1645,9 +1655,6 @@ local do_states = function(self, dtime)
|
|||||||
z = p.z - s.z
|
z = p.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
-- if vec.x ~= 0
|
|
||||||
-- and vec.z ~= 0 then
|
|
||||||
|
|
||||||
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
|
||||||
|
|
||||||
if p.x > s.x then
|
if p.x > s.x then
|
||||||
@ -1655,7 +1662,6 @@ local do_states = function(self, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.object:setyaw(yaw)
|
self.object:setyaw(yaw)
|
||||||
-- end
|
|
||||||
|
|
||||||
set_velocity(self, 0)
|
set_velocity(self, 0)
|
||||||
|
|
||||||
@ -1901,9 +1907,6 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
z = lp.z - s.z
|
z = lp.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
-- if vec.x ~= 0
|
|
||||||
-- and vec.z ~= 0 then
|
|
||||||
|
|
||||||
local yaw = atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
|
local yaw = atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
|
||||||
|
|
||||||
if lp.x > s.x then
|
if lp.x > s.x then
|
||||||
@ -1911,8 +1914,6 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
end
|
end
|
||||||
|
|
||||||
self.object:setyaw(yaw)
|
self.object:setyaw(yaw)
|
||||||
-- end
|
|
||||||
|
|
||||||
self.state = "runaway"
|
self.state = "runaway"
|
||||||
self.runaway_timer = 0
|
self.runaway_timer = 0
|
||||||
self.following = nil
|
self.following = nil
|
||||||
@ -1922,7 +1923,8 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
if self.passive == false
|
if self.passive == false
|
||||||
and self.state ~= "flop"
|
and self.state ~= "flop"
|
||||||
and self.child == false
|
and self.child == false
|
||||||
and hitter:get_player_name() ~= self.owner then
|
and hitter:get_player_name() ~= self.owner
|
||||||
|
and not invisibility[ hitter:get_player_name() ] then
|
||||||
|
|
||||||
-- attack whoever punched mob
|
-- attack whoever punched mob
|
||||||
self.state = ""
|
self.state = ""
|
||||||
|
@ -1 +1,2 @@
|
|||||||
default
|
default
|
||||||
|
invisibility?
|
||||||
|
Loading…
Reference in New Issue
Block a user