Here is the code I'm having an issue with:
- Code: Select all
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime;
--Place bombs around every 20 seconds.
if timer >= 20 then
timer = 0
if math.random(0,11) >= 0.5 then
minetest.chat_send_all("Bombs Away!")
else
minetest.chat_send_all("Look Out!")
end
local playerlist = minetest.get_connected_players()
--Bomb every player in map.
for _,player in ipairs(playerlist) do
local tpos = player:getpos()
-- local testpos = player:getpos()
--Check each block within a radius of 15 blocks of the player.
for dx=-15,15 do
for dz=-15,15 do
for dy=15,-15,-1 do
tpos.x = tpos.x+dx
tpos.y = tpos.y+dy
tpos.z = tpos.z+dz
--Around a 10% chance of placing tnt in valid node.
if math.random(0,100) > 90 then
local check = true
local setpos = {x = tpos.x, y = tpos.y - 6, z = tpos.z}
--Checking if valid node.
if minetest.env:get_node({x = tpos.x, y = tpos.y - 7, z = tpos.z}).name ~= "air" and minetest.env:get_node(tpos).name == "air" then
-- For testing purposes only:
-- minetest.env:set_node({x = testpos.x, y = testpos.y + 7, z = testpos.z}, {name = "tnt:tnt"})
-- minetest.env:punch_node({x = testpos.x, y = testpos.y + 7, z = testpos.z})
for t=1,6,1 do
if minetest.env:get_node({x = tpos.x, y = tpos.y - t, z = tpos.z}).name ~= "air" then
check = false
end
end
--If valid node... bombs away!!!
if check == true then
minetest.env:set_node(setpos, {name = "tnt:tnt"})
minetest.env:punch_node(setpos)
end
end
end
end
end
end
end
end
end)
The problem is with the minetest.env:get_node(...).name functions. When I check a radius like 15 it almost always returns "ignore" whereas if I check only a radius of 2 it seems to work fine almost all the time, and will identify even more blocks than checking a range of 15! I'm not sure what is going on.