fusion ha!
parent
c5be92a8a7
commit
40b92312d3
101
init.lua
101
init.lua
|
@ -1,26 +1,77 @@
|
||||||
--Spawn mod for Minetest
|
--a Fusion of cheapies and Zeno's spawn mode with extra CWz flavored goodness
|
||||||
--Originally written by VanessaE (I think), rewritten by cheapie
|
--Originally written by VanessaE (I think), rewritten by cheapie
|
||||||
--WTFPL
|
--WTFPL
|
||||||
|
|
||||||
local spawn_spawnpos = minetest.setting_get_pos("static_spawnpoint")
|
|
||||||
|
-- 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
|
||||||
|
|
||||||
|
|
||||||
minetest.register_chatcommand("spawn", {
|
minetest.register_chatcommand("spawn", {
|
||||||
params = "",
|
description = "Teleport to the spawn location",
|
||||||
description = "Teleport to the spawn point",
|
privs = {spawn=true},
|
||||||
func = function(name, param)
|
func = function(name, _)
|
||||||
local player = minetest.get_player_by_name(name)
|
local ok = put_player_at_spawn(minetest.get_player_by_name(name))
|
||||||
if not player then
|
if ok then
|
||||||
return false, "Player not found"
|
|
||||||
end
|
|
||||||
if spawn_spawnpos then
|
|
||||||
player:setpos(spawn_spawnpos)
|
|
||||||
return true, "Teleporting to spawn..."
|
return true, "Teleporting to spawn..."
|
||||||
else
|
|
||||||
return false, "The spawn point is not set!"
|
|
||||||
end
|
end
|
||||||
end,
|
return false, "Teleport failed"
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
minetest.register_chatcommand("setspawn", {
|
minetest.register_chatcommand("setspawn", {
|
||||||
params = "",
|
params = "",
|
||||||
description = "Sets the spawn point to your current position",
|
description = "Sets the spawn point to your current position",
|
||||||
|
@ -42,3 +93,25 @@ minetest.register_chatcommand("setspawn", {
|
||||||
return true, pos_string_2
|
return true, pos_string_2
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
-- 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,
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue