gridgen/spawn.lua
2015-12-21 02:14:49 -08:00

31 lines
861 B
Lua

spawns = {{x=0,y=0,z=0}} -- Possible spawn positions with default one
if minetest.setting_get("spawns") then
spawns = minetest.deserialize(minetest.setting_get("spawns"))
end
local function give_initial_stuff(player)
player:get_inventory():add_item('main', 'default:pick_wood')
player:get_inventory():add_item('main', 'default:torch 99')
end
local function spawn(player)
local choice = math.random(#spawns)
local spawn = spawns[choice]
table.remove(spawns, choice)
minetest.setting_set("spawns", minetest.serialize(spawns))
player:setpos(spawn)
end
minetest.register_on_newplayer(function(player)
spawn(player)
give_initial_stuff(player)
end)
minetest.register_on_respawnplayer(function(player)
spawn(player)
player:get_inventory():set_list("main", {})
player:get_inventory():set_list("craft", {})
give_initial_stuff(player)
return true
end)