with luck this works.
parent
b3f8e0a1c3
commit
f09834b5ba
33
init.lua
33
init.lua
|
@ -1,38 +1,38 @@
|
||||||
random_spawn = {}
|
random_spawn = {}
|
||||||
|
|
||||||
function random_spawn(player)
|
function random_spawn(player)
|
||||||
local elevation = 5
|
local elevation = 15
|
||||||
local radius = 600
|
local radius = 1000
|
||||||
local posx = math.random(-radius, radius)
|
local posx = math.random(-radius, radius)
|
||||||
local posz = math.random(-radius, radius)
|
local posz = math.random(-radius, radius)
|
||||||
local new_spawn = {x = posx, y = elevation, z = posz}
|
local new_spawn = {x = posx, y = elevation, z = posz}
|
||||||
minetest.log("action", (new_spawn.x..' is the X location and '..new_spawn.z..' is the Z location.'))
|
|
||||||
local node = minetest.get_node_or_nil(new_spawn)
|
local node = minetest.get_node_or_nil(new_spawn)
|
||||||
if not node or node.name == 'ignore' then
|
if not node or node.name == 'ignore' then
|
||||||
minetest.log("action", 'area is not loaded.')
|
|
||||||
minetest.emerge_area({x = new_spawn.x, y = new_spawn.y+30, z = new_spawn.z}, {x = new_spawn.x, y = new_spawn.y-30, z = new_spawn.z})
|
minetest.emerge_area({x = new_spawn.x, y = new_spawn.y+30, z = new_spawn.z}, {x = new_spawn.x, y = new_spawn.y-30, z = new_spawn.z})
|
||||||
minetest.after(3, find_ground, new_spawn, player)
|
minetest.after(.5, find_ground, new_spawn, player)
|
||||||
|
else
|
||||||
|
find_ground(new_spawn, player)
|
||||||
end
|
end
|
||||||
find_ground(new_spawn, player)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function find_ground(pos, player)
|
function find_ground(pos, player)
|
||||||
minetest.log("action", 'area has been loaded.')
|
|
||||||
local node = minetest.get_node({x = pos.x, y = pos.y, z = pos.z})
|
local node = minetest.get_node({x = pos.x, y = pos.y, z = pos.z})
|
||||||
if node.name == 'air' or node.name == 'ignore' then --Theoretically above ground
|
if node.name == 'air' or node.name == 'ignore' then --Theoretically above ground
|
||||||
local i = 1
|
local i = 1
|
||||||
local finished = false
|
local finished = false
|
||||||
minetest.log("action", 'heading underground.')
|
|
||||||
repeat
|
repeat
|
||||||
local node = minetest.get_node({x = pos.x, y = pos.y - i, z = pos.z})
|
local node = minetest.get_node({x = pos.x, y = pos.y - i, z = pos.z})
|
||||||
i = i-1
|
i = i-1
|
||||||
if i == -40 then
|
if i == -40 then
|
||||||
minetest.log("action", 'unable to find solid ground for player.')
|
random_spawn(player)
|
||||||
-- random_spawn(player)
|
|
||||||
end
|
end
|
||||||
if node.name ~= 'air' and node.name ~= 'ignore' then
|
if node.name ~= 'air' and node.name ~= 'ignore' then
|
||||||
|
local protection = minetest.is_protected({x = pos.x, y = pos.y - i + 2, z = pos.z})
|
||||||
|
if protection then
|
||||||
|
random_spawn(player)
|
||||||
|
end
|
||||||
player:setpos({x = pos.x, y = pos.y - i + 2, z = pos.z})
|
player:setpos({x = pos.x, y = pos.y - i + 2, z = pos.z})
|
||||||
minetest.log("action", 'like a mole, we find air.')
|
minetest.set_node({x = pos.x, y = pos.y + i +1, z = pos.z}, {name = 'default:torch', param2 = 1})
|
||||||
finished = true
|
finished = true
|
||||||
end
|
end
|
||||||
until finished == true or i < -40
|
until finished == true or i < -40
|
||||||
|
@ -42,11 +42,13 @@ function find_ground(pos, player)
|
||||||
local node = minetest.get_node({x = pos.x, y = pos.y + i, z = pos.z})
|
local node = minetest.get_node({x = pos.x, y = pos.y + i, z = pos.z})
|
||||||
i = i + 1
|
i = i + 1
|
||||||
if i == 40 then
|
if i == 40 then
|
||||||
minetest.log("action", 'unable to find air for player, trying again.')
|
random_spawn(player)
|
||||||
-- random_spawn(player)
|
|
||||||
end
|
end
|
||||||
if node.name == 'air' then
|
if node.name == 'air' then
|
||||||
minetest.log("action", 'horray, everything worked out.')
|
local protection = minetest.is_protected({x = pos.x, y = pos.y + i, z = pos.z})
|
||||||
|
if protection then
|
||||||
|
random_spawn(player)
|
||||||
|
end
|
||||||
player:setpos({x = pos.x, y = pos.y + i, z = pos.z})
|
player:setpos({x = pos.x, y = pos.y + i, z = pos.z})
|
||||||
minetest.set_node({x = pos.x, y = pos.y + i -1, z = pos.z}, {name = 'default:torch', param2 = 1})
|
minetest.set_node({x = pos.x, y = pos.y + i -1, z = pos.z}, {name = 'default:torch', param2 = 1})
|
||||||
i = 45
|
i = 45
|
||||||
|
@ -63,9 +65,6 @@ minetest.register_node('random_spawn:node', {
|
||||||
paramtype = 'light',
|
paramtype = 'light',
|
||||||
light_source = 14,
|
light_source = 14,
|
||||||
on_punch = function(pos, node, player)
|
on_punch = function(pos, node, player)
|
||||||
-- local new_pos = {x = pos.x, y = pos.y + 3, z = pos.z}
|
|
||||||
minetest.log("action", 'somebody punched a node, what a jerk.')
|
|
||||||
random_spawn(player)
|
random_spawn(player)
|
||||||
-- player:setpos(new_pos)
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue