Finish mod
parent
1fc2cf53f0
commit
42338f18d0
|
@ -1,7 +1,7 @@
|
|||
spawn_pillar.formname = "pillar_gui"
|
||||
|
||||
function spawn_pillar.make_formspec(player, pos)
|
||||
local active_pillar = minetest.deserialize(player:get_attribute("spawn_pillar"))
|
||||
local active_pillar = spawn_pillar.get_player_pillar(player)
|
||||
|
||||
local fs = "size[10.3,11.3]" ..
|
||||
"label[0.5,-0.25;Select a spawn pillar to tune to.]" ..
|
||||
|
@ -17,10 +17,10 @@ function spawn_pillar.make_formspec(player, pos)
|
|||
fs = fs .. "\nlabel[-0.04," .. (i/1.5 + 0.4) .. ";" .. i .. "]"
|
||||
end
|
||||
local string = " "
|
||||
if active_pillar.x == j and active_pillar.y == i then
|
||||
if active_pillar.x == j and active_pillar.z == i then
|
||||
string = "\\[X\\]"
|
||||
end
|
||||
fs = fs .. "\nbutton[" .. (j/1.6 - 0.3) .. "," .. (i/1.5 + 0.4) .. ";0.8,0.5;x = " .. j .. ", y = " .. i .. ";" .. string .. "]"
|
||||
fs = fs .. "\nbutton[" .. (j/1.6 - 0.3) .. "," .. (i/1.5 + 0.4) .. ";0.8,0.5;x = " .. j .. ", z = " .. i .. ";" .. string .. "]"
|
||||
end
|
||||
end
|
||||
return fs
|
||||
|
|
36
gen.lua
36
gen.lua
|
@ -4,19 +4,18 @@ local xseg = 1
|
|||
local zseg = 1
|
||||
for i = -8, 8 do
|
||||
for j = -8, 8 do
|
||||
|
||||
if not spawn_pillar.get_spawnpoint(xseg, zseg) then
|
||||
table.insert(spawn_positions, {x = j*2000, z = i*2000, xseg = xseg, zseg = zseg})
|
||||
end
|
||||
|
||||
xseg = xseg + 1
|
||||
end
|
||||
xseg = 1
|
||||
zseg = zseg + 1
|
||||
end
|
||||
print("[Spawn Pillar] There are " .. #spawn_positions .. "spawn positions.")
|
||||
-- print(dump(spawn_positions))
|
||||
|
||||
local function create_pillar(pos)
|
||||
-- print("[Spawn Pillar] There are " .. #spawn_positions .. "spawn positions.")
|
||||
|
||||
local function create_pillar(pos, segment)
|
||||
for i = -2, 2 do
|
||||
for j = -2, 2 do
|
||||
for k = -1, 3 do
|
||||
|
@ -36,38 +35,39 @@ local function create_pillar(pos)
|
|||
minetest.set_node(vector.add(pos, vector.new(-1, 0, 0)), {name = "default:torch", param2 = 1})
|
||||
minetest.set_node(vector.add(pos, vector.new(0, 0, 1)), {name = "default:torch", param2 = 1})
|
||||
minetest.set_node(vector.add(pos, vector.new(0, 0, -1)), {name = "default:torch", param2 = 1})
|
||||
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local sc = minetest.deserialize(player:get_attribute("spawn_pillar"))
|
||||
if sc.x == segment.x and sc.z == segment.z then
|
||||
player:set_pos(vector.add(spawn_pillar.get_spawnpoint(segment.x, segment.z), {x = 1, y = 0, z = 0}))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_generated(function(minp, maxp)
|
||||
for ind,spos in pairs(spawn_positions) do
|
||||
if minp.x < spos.x and spos.x < maxp.x and
|
||||
minp.z < spos.z and spos.z < maxp.z and
|
||||
minp.y < 79 and 79 < maxp.y then
|
||||
maxp.y > 0 then
|
||||
|
||||
if not spawn_pillar.get_spawnpoint(spos.xseg, spos.zseg) then
|
||||
for j = 79, 2, -1 do
|
||||
for j = maxp.y, math.max(minp.y, 0), -1 do
|
||||
local node = vector.new(spos.x, j, spos.z)
|
||||
local below = vector.new(spos.x, j-1, spos.z)
|
||||
|
||||
if (minetest.get_node(node).name == "air" and
|
||||
minetest.get_node(below).name ~= "air" and minetest.get_node(below).name ~= "ignore") then
|
||||
if (minetest.get_node(node).name == "air" and
|
||||
minetest.get_node(below).name ~= "air" and
|
||||
minetest.get_node(below).name ~= "ignore") then
|
||||
|
||||
create_pillar(vector.new(spos.x, j, spos.z))
|
||||
spawn_pillar.set_spawnpoint(spos.xseg, spos.zseg, vector.new(spos.x, j, spos.z))
|
||||
create_pillar(vector.new(spos.x, j, spos.z), {x = spos.xseg, z = spos.zseg})
|
||||
table.remove(spawn_positions, ind)
|
||||
|
||||
return
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
create_pillar(vector.new(spos.x, 79, spos.z))
|
||||
spawn_pillar.set_spawnpoint(spos.xseg, spos.zseg, vector.new(spos.x, 79, spos.z))
|
||||
table.remove(spawn_positions, ind)
|
||||
return
|
||||
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
end
|
||||
end)
|
18
init.lua
18
init.lua
|
@ -1,25 +1,13 @@
|
|||
spawn_pillar = {}
|
||||
|
||||
spawn_pillar.storage = minetest.get_mod_storage()
|
||||
spawn_pillar.spawn_points = minetest.deserialize(spawn_pillar.storage:get_string("spawn_points")) or {}
|
||||
|
||||
function spawn_pillar.get_spawnpoint(xseg, zseg)
|
||||
return spawn_pillar.spawn_points[xseg .. "|" .. zseg] or nil
|
||||
end
|
||||
|
||||
function spawn_pillar.set_spawnpoint(xseg, zseg, coords)
|
||||
spawn_pillar.spawn_points[xseg .. "|" .. zseg] = coords
|
||||
spawn_pillar.storage:set_string("spawn_points", minetest.serialize(spawn_pillar.spawn_points))
|
||||
-- print(dump(spawn_pillar.spawn_points))
|
||||
print("adding spawnpoint")
|
||||
end
|
||||
|
||||
local path = minetest.get_modpath("spawn_pillar")
|
||||
dofile(path .. "/modstorage.lua")
|
||||
dofile(path .. "/formspec.lua")
|
||||
dofile(path .. "/nodes.lua")
|
||||
dofile(path .. "/gen.lua")
|
||||
dofile(path .. "/respawn.lua")
|
||||
|
||||
minetest.register_on_newplayer(function(player)
|
||||
player:set_attribute("spawn_pillar", minetest.serialize({x = math.random(16), y = math.random(16)}))
|
||||
player:set_attribute("spawn_pillar", minetest.serialize({x = math.random(16), z = math.random(16)}))
|
||||
player:setpos(vector.add(spawn_pillar.get_player_spawn_coords(player), {x = 1, y = 0, z = 0}))
|
||||
end)
|
|
@ -0,0 +1,20 @@
|
|||
spawn_pillar.storage = minetest.get_mod_storage()
|
||||
spawn_pillar.spawn_points = minetest.deserialize(spawn_pillar.storage:get_string("spawn_points")) or {}
|
||||
|
||||
function spawn_pillar.get_spawnpoint(xseg, zseg)
|
||||
return spawn_pillar.spawn_points[xseg .. "|" .. zseg] or nil
|
||||
end
|
||||
|
||||
function spawn_pillar.set_spawnpoint(xseg, zseg, coords)
|
||||
spawn_pillar.spawn_points[xseg .. "|" .. zseg] = coords
|
||||
spawn_pillar.storage:set_string("spawn_points", minetest.serialize(spawn_pillar.spawn_points))
|
||||
end
|
||||
|
||||
function spawn_pillar.get_player_pillar(player)
|
||||
local spawn = minetest.deserialize(player:get_attribute("spawn_pillar"))
|
||||
if not spawn then
|
||||
spawn = {x = math.random(16), z = math.random(16)}
|
||||
player:set_attribute("spawn_pillar", minetest.serialize(spawn))
|
||||
end
|
||||
return spawn
|
||||
end
|
15
respawn.lua
15
respawn.lua
|
@ -1,7 +1,10 @@
|
|||
-- function spawn_pillar.get_spawnpoint(player)
|
||||
function spawn_pillar.get_player_spawn_coords(player)
|
||||
local seg = minetest.deserialize(player:get_attribute("spawn_pillar"))
|
||||
-- print(dump(spawn_pillar.get_spawnpoint(seg.x, seg.z) or {x = (seg.x-9)*2000, y = 20, z = (seg.z-9)*2000}))
|
||||
return spawn_pillar.get_spawnpoint(seg.x, seg.z) or {x = (seg.x-9)*2000, y = 20, z = (seg.z-9)*2000}
|
||||
end
|
||||
|
||||
-- end
|
||||
|
||||
-- minetest.register_on_respawnplayer(function(player)
|
||||
-- player:set_pos(spawn_pillar.get_spawnpoint(player))
|
||||
-- end)
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
player:setpos(vector.add(spawn_pillar.get_player_spawn_coords(player), {x = 1, y = 0, z = 0}))
|
||||
return true
|
||||
end)
|
Loading…
Reference in New Issue