Added extra checks when spawning mob
This commit is contained in:
parent
d255915ec8
commit
0e7a59ced2
27
api.lua
27
api.lua
@ -1,4 +1,4 @@
|
|||||||
-- Mobs Api (26th Feb 2015)
|
-- Mobs Api (1st March 2015)
|
||||||
mobs = {}
|
mobs = {}
|
||||||
|
|
||||||
-- Set global for other mod checks (e.g. Better HUD uses this)
|
-- Set global for other mod checks (e.g. Better HUD uses this)
|
||||||
@ -227,7 +227,7 @@ function mobs:register_mob(name, def)
|
|||||||
-- pause is only set after a monster is hit
|
-- pause is only set after a monster is hit
|
||||||
if self.pause_timer > 0 then
|
if self.pause_timer > 0 then
|
||||||
self.pause_timer = self.pause_timer - dtime
|
self.pause_timer = self.pause_timer - dtime
|
||||||
if self.pause_timer <= 0 then
|
if self.pause_timer < 1 then
|
||||||
self.pause_timer = 0
|
self.pause_timer = 0
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
@ -584,8 +584,7 @@ function mobs:register_mob(name, def)
|
|||||||
|
|
||||||
on_activate = function(self, staticdata, dtime_s)
|
on_activate = function(self, staticdata, dtime_s)
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
-- reset HP
|
self.object:set_hp( math.random(self.hp_min, self.hp_max) ) -- reset HP
|
||||||
self.object:set_hp( math.random(self.hp_min, self.hp_max) )
|
|
||||||
self.object:set_armor_groups({fleshy=self.armor})
|
self.object:set_armor_groups({fleshy=self.armor})
|
||||||
self.object:setacceleration({x=0, y=-10, z=0})
|
self.object:setacceleration({x=0, y=-10, z=0})
|
||||||
self.state = "stand"
|
self.state = "stand"
|
||||||
@ -644,8 +643,8 @@ function mobs:register_mob(name, def)
|
|||||||
minetest.add_particlespawner({
|
minetest.add_particlespawner({
|
||||||
amount = self.blood_amount,
|
amount = self.blood_amount,
|
||||||
time = 0.25,
|
time = 0.25,
|
||||||
minpos = {x=pos.x-0.2, y=pos.y-0.2, z=pos.z-0.2},
|
minpos = {x=p.x-0.2, y=p.y-0.2, z=p.z-0.2},
|
||||||
maxpos = {x=pos.x+0.2, y=pos.y+0.2, z=pos.z+0.2},
|
maxpos = {x=p.x+0.2, y=p.y+0.2, z=p.z+0.2},
|
||||||
minvel = {x=-0, y=-2, z=-0},
|
minvel = {x=-0, y=-2, z=-0},
|
||||||
maxvel = {x=2, y=2, z=2},
|
maxvel = {x=2, y=2, z=2},
|
||||||
minacc = {x=-4, y=-4, z=-4},
|
minacc = {x=-4, y=-4, z=-4},
|
||||||
@ -705,13 +704,14 @@ function mobs:register_spawn(name, nodes, max_light, min_light, chance, active_o
|
|||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = nodes,
|
nodenames = nodes,
|
||||||
neighbors = {"air"},
|
neighbors = {"air"},
|
||||||
interval = 30,
|
interval = 5, --30,
|
||||||
chance = chance,
|
chance = 1, --chance,
|
||||||
action = function(pos, node, _, active_object_count_wider)
|
action = function(pos, node, _, active_object_count_wider)
|
||||||
|
|
||||||
-- do not spawn if too many in one active area
|
-- do not spawn if too many in one active area
|
||||||
if active_object_count_wider > active_object_count
|
if active_object_count_wider > active_object_count
|
||||||
or not mobs.spawning_mobs[name] then
|
or not mobs.spawning_mobs[name]
|
||||||
|
or not pos then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -732,17 +732,18 @@ function mobs:register_spawn(name, nodes, max_light, min_light, chance, active_o
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- are we spawning inside a node?
|
-- are we spawning inside a node?
|
||||||
if minetest.registered_nodes[minetest.get_node(pos).name].walkable then return end
|
local nod = minetest.get_node_or_nil(pos)
|
||||||
|
if not nod or minetest.registered_nodes[nod.name].walkable == true then return end
|
||||||
pos.y = pos.y + 1
|
pos.y = pos.y + 1
|
||||||
if minetest.registered_nodes[minetest.get_node(pos).name].walkable then return end
|
nod = minetest.get_node_or_nil(pos)
|
||||||
pos.y = pos.y - 1
|
if not nod or minetest.registered_nodes[nod.name].walkable == true then return end
|
||||||
|
|
||||||
if minetest.setting_getbool("display_mob_spawn") then
|
if minetest.setting_getbool("display_mob_spawn") then
|
||||||
minetest.chat_send_all("[mobs] Add "..name.." at "..minetest.pos_to_string(pos))
|
minetest.chat_send_all("[mobs] Add "..name.." at "..minetest.pos_to_string(pos))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- spawn mob half block higher
|
-- spawn mob half block higher
|
||||||
pos.y = pos.y + 0.5
|
pos.y = pos.y - 0.5
|
||||||
local mob = minetest.add_entity(pos, name)
|
local mob = minetest.add_entity(pos, name)
|
||||||
|
|
||||||
-- set mob health (randomly between min and max)
|
-- set mob health (randomly between min and max)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user