2015-10-18 00:22:05 -07:00
|
|
|
--a Fusion of cheapies and Zeno's spawn mode with extra CWz flavored goodness
|
2014-07-03 11:18:33 -07:00
|
|
|
--Originally written by VanessaE (I think), rewritten by cheapie
|
|
|
|
--WTFPL
|
2014-07-03 10:46:45 -07:00
|
|
|
|
2015-10-18 00:22:05 -07:00
|
|
|
|
|
|
|
-- Some modified from: Minetest: builtin/static_spawn.lua LGPL
|
|
|
|
|
|
|
|
local function check_spawnpoint(config_setting)
|
|
|
|
if not minetest.setting_get(config_setting) then
|
|
|
|
minetest.log('error', "The \"" .. config_setting .. "\" setting is not set")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
if not minetest.setting_get_pos(config_setting) then
|
|
|
|
minetest.log('error', "The " .. config_setting .. " setting is invalid: \""..
|
|
|
|
core.setting_get(config_setting).."\"")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function put_player_at_spawn(obj)
|
|
|
|
|
|
|
|
local config_setting
|
|
|
|
|
|
|
|
-- players with interact spawn at the location specified by
|
|
|
|
-- "alt_spawnpoint" in the .conf file. Those *without* interact go to
|
|
|
|
-- "static_spawnpoint".
|
|
|
|
|
|
|
|
if not minetest.get_player_privs(obj:get_player_name()).interact then
|
|
|
|
config_setting = "static_spawnpoint"
|
|
|
|
else
|
|
|
|
config_setting = "alt_spawnpoint"
|
|
|
|
end
|
|
|
|
|
|
|
|
if not check_spawnpoint(config_setting) then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local spawnpoint = minetest.setting_get_pos(config_setting)
|
|
|
|
|
|
|
|
minetest.log('action', "Moving " .. obj:get_player_name() ..
|
|
|
|
" to " .. config_setting .. " at "..
|
|
|
|
minetest.pos_to_string(spawnpoint))
|
|
|
|
|
|
|
|
obj:setpos(spawnpoint)
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2014-07-03 11:18:33 -07:00
|
|
|
|
|
|
|
minetest.register_chatcommand("spawn", {
|
2015-10-18 00:22:05 -07:00
|
|
|
description = "Teleport to the spawn location",
|
|
|
|
privs = {spawn=true},
|
|
|
|
func = function(name, _)
|
|
|
|
local ok = put_player_at_spawn(minetest.get_player_by_name(name))
|
|
|
|
if ok then
|
2014-07-03 11:18:33 -07:00
|
|
|
return true, "Teleporting to spawn..."
|
|
|
|
end
|
2015-10-18 00:22:05 -07:00
|
|
|
return false, "Teleport failed"
|
|
|
|
end
|
2014-07-03 11:18:33 -07:00
|
|
|
})
|
|
|
|
|
2015-10-18 00:22:05 -07:00
|
|
|
|
|
|
|
minetest.register_on_newplayer(function(obj)
|
|
|
|
return put_player_at_spawn(obj)
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_respawnplayer(function(obj)
|
|
|
|
return put_player_at_spawn(obj)
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
2014-07-03 11:18:33 -07:00
|
|
|
minetest.register_chatcommand("setspawn", {
|
|
|
|
params = "",
|
|
|
|
description = "Sets the spawn point to your current position",
|
|
|
|
privs = { server=true },
|
|
|
|
func = function(name, param)
|
|
|
|
local player = minetest.get_player_by_name(name)
|
|
|
|
if not player then
|
|
|
|
return false, "Player not found"
|
2014-07-03 10:46:45 -07:00
|
|
|
end
|
2014-07-03 11:18:33 -07:00
|
|
|
local pos = player:getpos()
|
|
|
|
local x = pos.x
|
|
|
|
local y = pos.y
|
|
|
|
local z = pos.z
|
|
|
|
local pos_string = x..","..y..","..z
|
|
|
|
local pos_string_2 = "Setting spawn point to ("..x..", "..y..", "..z..")"
|
|
|
|
minetest.setting_set("static_spawnpoint",pos_string)
|
2015-02-04 17:08:41 -08:00
|
|
|
spawn_spawnpos = pos
|
2015-02-04 18:10:01 -08:00
|
|
|
minetest.setting_save()
|
2014-07-03 11:18:33 -07:00
|
|
|
return true, pos_string_2
|
|
|
|
end,
|
|
|
|
})
|
2015-10-18 00:22:05 -07:00
|
|
|
-- alt_spawnpoint
|
|
|
|
minetest.register_chatcommand("setaltspawn", {
|
|
|
|
params = "",
|
|
|
|
description = "Sets the alt spawn point to your current position",
|
|
|
|
privs = { server=true },
|
|
|
|
func = function(name, param)
|
|
|
|
local player = minetest.get_player_by_name(name)
|
|
|
|
if not player then
|
|
|
|
return false, "Player not found"
|
|
|
|
end
|
|
|
|
local pos = player:getpos()
|
|
|
|
local x = pos.x
|
|
|
|
local y = pos.y
|
|
|
|
local z = pos.z
|
|
|
|
local pos_string = x..","..y..","..z
|
|
|
|
local pos_string_2 = "Setting alt spawn point to ("..x..", "..y..", "..z..")"
|
|
|
|
minetest.setting_set("alt_spawnpoint",pos_string)
|
|
|
|
spawn_spawnpos = pos
|
|
|
|
minetest.setting_save()
|
|
|
|
return true, pos_string_2
|
|
|
|
end,
|
|
|
|
})
|