Added a /setspawn command to set the spawn point more easily (requires server priv)
This commit is contained in:
parent
d0315792a7
commit
9bf34765a8
46
init.lua
46
init.lua
@ -1,19 +1,41 @@
|
||||
--Spawn mod for Minetest
|
||||
--Originally written by VanessaE (I think), modified by cheapie
|
||||
--License unknown for original code, modifications are WTFPL
|
||||
--Originally written by VanessaE (I think), rewritten by cheapie
|
||||
--WTFPL
|
||||
|
||||
minetest.register_on_chat_message(function(name, message, playername, player)
|
||||
local cmd = "/spawn"
|
||||
if message:sub(0, #cmd) == cmd then
|
||||
if message == '/spawn' then
|
||||
local player = minetest.env:get_player_by_name(name)
|
||||
|
||||
minetest.register_chatcommand("spawn", {
|
||||
params = "",
|
||||
description = "Teleport to the spawn point",
|
||||
func = function(name, param)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then
|
||||
return false, "Player not found"
|
||||
end
|
||||
if minetest.setting_get_pos("static_spawnpoint") then
|
||||
minetest.chat_send_player(player:get_player_name(), "Teleporting to spawn...")
|
||||
player:setpos(minetest.setting_get_pos("static_spawnpoint"))
|
||||
return true, "Teleporting to spawn..."
|
||||
else
|
||||
minetest.chat_send_player(player:get_player_name(), "ERROR: No spawn point is set on this server!")
|
||||
return false, "The spawn point is not set!"
|
||||
end
|
||||
return true
|
||||
end,
|
||||
})
|
||||
|
||||
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"
|
||||
end
|
||||
end
|
||||
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 spawn point to ("..x..", "..y..", "..z..")"
|
||||
minetest.setting_set("static_spawnpoint",pos_string)
|
||||
return true, pos_string_2
|
||||
end,
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user