supports invisibility, lava/water checks added, code tidied/tweaked
parent
d0fc69d458
commit
7d77124aa0
144
api.lua
144
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
|
||||||
|
|
||||||
player = objs[n]
|
if invisibility[ objs[n]:get_player_name() ] then
|
||||||
type = "player"
|
|
||||||
|
type = ""
|
||||||
|
else
|
||||||
|
player = objs[n]
|
||||||
|
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
|
||||||
|
yaw = yaw + pi
|
||||||
|
end
|
||||||
|
|
||||||
if p.x > s.x then
|
self.object:setyaw(yaw)
|
||||||
yaw = yaw + pi
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
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 lp.x > s.x then
|
||||||
|
yaw = yaw + pi
|
||||||
if lp.x > s.x then
|
end
|
||||||
yaw = yaw + pi
|
|
||||||
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,17 +1266,13 @@ local do_states = function(self, dtime)
|
||||||
z = lp.z - s.z
|
z = lp.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
-- if vec.x ~= 0
|
yaw = atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
|
||||||
-- and vec.z ~= 0 then
|
|
||||||
|
|
||||||
yaw = atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
|
if lp.x > s.x then
|
||||||
|
yaw = yaw + pi
|
||||||
|
end
|
||||||
|
|
||||||
if lp.x > s.x then
|
self.object:setyaw(yaw)
|
||||||
yaw = yaw + pi
|
|
||||||
end
|
|
||||||
|
|
||||||
self.object:setyaw(yaw)
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- otherwise randomly turn
|
-- otherwise randomly turn
|
||||||
elseif random(1, 100) <= 30 then
|
elseif random(1, 100) <= 30 then
|
||||||
|
@ -1345,17 +1364,13 @@ local do_states = function(self, dtime)
|
||||||
z = p.z - s.z
|
z = p.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
-- if vec.x ~= 0
|
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
|
||||||
|
yaw = yaw + pi
|
||||||
|
end
|
||||||
|
|
||||||
if p.x > s.x then
|
self.object:setyaw(yaw)
|
||||||
yaw = yaw + pi
|
|
||||||
end
|
|
||||||
|
|
||||||
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,17 +1541,13 @@ local do_states = function(self, dtime)
|
||||||
z = p.z - s.z
|
z = p.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
-- if vec.x ~= 0
|
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
|
||||||
|
yaw = yaw + pi
|
||||||
|
end
|
||||||
|
|
||||||
if p.x > s.x then
|
self.object:setyaw(yaw)
|
||||||
yaw = yaw + pi
|
|
||||||
end
|
|
||||||
|
|
||||||
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,17 +1655,13 @@ local do_states = function(self, dtime)
|
||||||
z = p.z - s.z
|
z = p.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
-- if vec.x ~= 0
|
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
|
||||||
|
yaw = yaw + pi
|
||||||
|
end
|
||||||
|
|
||||||
if p.x > s.x then
|
self.object:setyaw(yaw)
|
||||||
yaw = yaw + pi
|
|
||||||
end
|
|
||||||
|
|
||||||
self.object:setyaw(yaw)
|
|
||||||
-- end
|
|
||||||
|
|
||||||
set_velocity(self, 0)
|
set_velocity(self, 0)
|
||||||
|
|
||||||
|
@ -1901,18 +1907,13 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
||||||
z = lp.z - s.z
|
z = lp.z - s.z
|
||||||
}
|
}
|
||||||
|
|
||||||
-- if vec.x ~= 0
|
local yaw = atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
|
||||||
-- and vec.z ~= 0 then
|
|
||||||
|
|
||||||
local yaw = atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
|
if lp.x > s.x then
|
||||||
|
yaw = yaw + pi
|
||||||
if lp.x > s.x then
|
end
|
||||||
yaw = yaw + pi
|
|
||||||
end
|
|
||||||
|
|
||||||
self.object:setyaw(yaw)
|
|
||||||
-- end
|
|
||||||
|
|
||||||
|
self.object:setyaw(yaw)
|
||||||
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