icyessentials/ess_spawn/init.lua

43 lines
1.2 KiB
Lua

local modpath = minetest.get_modpath(minetest.get_current_modname())
-- Register base module
local spawn = ess.register_module("spawn", "Spawnpoint management")
spawn.register_chatcommand("spawn", {
description = "Teleport to spawnpoint.",
privs = {
spawn = true,
["spawn.all"] = true,
},
save_player_pos = true,
override = true,
func = function (name)
local spawnpoint = minetest.setting_get_pos("static_spawnpoint")
if not spawnpoint then
return false, "There is no defined spawnpoint for this world."
end
minetest.get_player_by_name(name):set_pos(spawnpoint)
return true, "Teleported to spawn."
end
})
spawn.register_chatcommand("setspawn", {
description = "Set a spawnpoint for the world.",
privs = {
["spawn.set"] = true,
["spawn.all"] = true,
},
override = true,
func = function (name)
if minetest.is_singleplayer() then
return false, "There is no point in setting a spawnpoint for a singleplayer world! Use /sethome instead."
end
local pos = minetest.get_player_by_name(name):get_pos(spawnpoint)
local str = minetest.pos_to_string(pos)
minetest.settings:set("static_spawnpoint", str)
minetest.settings:save()
return true, "Set the world's spawn point to " .. str
end
})