support removal, support over-mode

This commit is contained in:
Tai @ Flex 2016-09-29 23:41:42 +01:00
parent f19b188f7b
commit 9e89b292a0
2 changed files with 22 additions and 8 deletions

View File

@ -7,6 +7,9 @@ spawnstep.interval = 1 -- how frequently to try to spawn a new mob (seconds)
spawnstep.maxmobs = 1 -- maxiumum number of mobs to allow in area defined by spawn range, around the trap node
spawnstep.overmode = false -- whether to look at node above instead of under
spawnstep.remove = false -- whether to remove the node after spawning
spawnstep.tiles = { -- define the tiles for the trap node
"default_stone.png^default_mese_crystal.png"
}

View File

@ -33,19 +33,27 @@ local count_nearby_mobs = function(pos,radius)
return objcount
end
local get_mob_from_node = function(pos)
-- return the expected mob, or nil if none matches
-- get node under position
local underpos = {x=pos.x, y=pos.y-1, z=pos.z}
local tellernode = minetest.get_node(underpos).name
-- iterate spawnstep.mobnodes, check against nodename
for _,mobnode in pairs(spawnstep.mobnodes) do
local match_from_pairs = function(lookuptable,tellernode)
for _,mobnode in pairs(lookuptable) do
-- if match, return mobstring
if mobnode.node == tellernode then return mobnode.mob end
if mobnode.node == tellernode then
return mobnode.mob
end
end
return nil
end
local get_mob_from_node = function(pos)
-- return the expected mob, or nil if none matches
-- get node under or over position
local tellerpos = {x=pos.x, y=pos.y-1, z=pos.z}
if spawnstep.overmode = true then
tellerpos = {x=pos.x, y=pos.y+1, z=pos.z}
end
local tellernode = minetest.get_node(tellerpos).name
return match_from_pairs(spawnstep.mobnodes,tellernode)
end
minetest.register_abm{
nodenames = {"spawnstep:spawntrap"},
neighbors = nil,
@ -61,6 +69,9 @@ minetest.register_abm{
local mobnicename = mobname:sub(mobname:find(':')+1,#mobname )
minetest.chat_send_player(obj:get_player_name(),"A wild "..mobnicename.." appeared!")
spawnstep.spawn_mob(pos,mobname)
if spawnstep.remove == true then
minetest.remove_node(pos)
end
else
minetest.debug("Failed to determine a mob.")
end