aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
Diffstat (limited to 'builtin')
-rw-r--r--builtin/builtin.lua1
-rw-r--r--builtin/chatcommands.lua2
-rw-r--r--builtin/misc.lua32
-rw-r--r--builtin/static_spawn.lua33
4 files changed, 67 insertions, 1 deletions
diff --git a/builtin/builtin.lua b/builtin/builtin.lua
index 10acd0f52..13c1c09d4 100644
--- a/builtin/builtin.lua
+++ b/builtin/builtin.lua
@@ -19,4 +19,5 @@ dofile(minetest.get_modpath("__builtin").."/misc.lua")
dofile(minetest.get_modpath("__builtin").."/privileges.lua")
dofile(minetest.get_modpath("__builtin").."/auth.lua")
dofile(minetest.get_modpath("__builtin").."/chatcommands.lua")
+dofile(minetest.get_modpath("__builtin").."/static_spawn.lua")
diff --git a/builtin/chatcommands.lua b/builtin/chatcommands.lua
index 047cfc692..a7061e3a3 100644
--- a/builtin/chatcommands.lua
+++ b/builtin/chatcommands.lua
@@ -322,7 +322,7 @@ minetest.register_chatcommand("set", {
privs = {server=true},
func = function(name, param)
local arg, setname, setvalue = string.match(param, "(-[n]) ([^ ]+) (.+)")
- if arg and arg == "n" and setname and setvalue then
+ if arg and arg == "-n" and setname and setvalue then
minetest.setting_set(setname, setvalue)
minetest.chat_send_player(name, setname.." = "..setvalue)
return
diff --git a/builtin/misc.lua b/builtin/misc.lua
index 89f90dfbd..b3b1ec6e8 100644
--- a/builtin/misc.lua
+++ b/builtin/misc.lua
@@ -67,3 +67,35 @@ function minetest.get_node_group(name, group)
return minetest.get_item_group(name, group)
end
+function minetest.string_to_pos(value)
+ local p = {}
+ p.x, p.y, p.z = string.match(value, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$")
+ if p.x and p.y and p.z then
+ p.x = tonumber(p.x)
+ p.y = tonumber(p.y)
+ p.z = tonumber(p.z)
+ return p
+ end
+ local p = {}
+ p.x, p.y, p.z = string.match(value, "^%( *([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+) *%)$")
+ if p.x and p.y and p.z then
+ p.x = tonumber(p.x)
+ p.y = tonumber(p.y)
+ p.z = tonumber(p.z)
+ return p
+ end
+ return nil
+end
+
+assert(minetest.string_to_pos("10.0, 5, -2").x == 10)
+assert(minetest.string_to_pos("( 10.0, 5, -2)").z == -2)
+assert(minetest.string_to_pos("asd, 5, -2)") == nil)
+
+function minetest.setting_get_pos(name)
+ local value = minetest.setting_get(name)
+ if not value then
+ return nil
+ end
+ return minetest.string_to_pos(value)
+end
+
diff --git a/builtin/static_spawn.lua b/builtin/static_spawn.lua
new file mode 100644
index 000000000..e8c107d86
--- /dev/null
+++ b/builtin/static_spawn.lua
@@ -0,0 +1,33 @@
+-- Minetest: builtin/static_spawn.lua
+
+local function warn_invalid_static_spawnpoint()
+ if minetest.setting_get("static_spawnpoint") and
+ not minetest.setting_get_pos("static_spawnpoint") then
+ minetest.log('error', "The static_spawnpoint setting is invalid: \""..
+ minetest.setting_get("static_spawnpoint").."\"")
+ end
+end
+
+warn_invalid_static_spawnpoint()
+
+local function put_player_in_spawn(obj)
+ warn_invalid_static_spawnpoint()
+ local static_spawnpoint = minetest.setting_get_pos("static_spawnpoint")
+ if not static_spawnpoint then
+ return false
+ end
+ minetest.log('action', "Moving "..obj:get_player_name()..
+ " to static spawnpoint at "..
+ minetest.pos_to_string(static_spawnpoint))
+ obj:setpos(static_spawnpoint)
+ return true
+end
+
+minetest.register_on_newplayer(function(obj)
+ put_player_in_spawn(obj)
+end)
+
+minetest.register_on_respawnplayer(function(obj)
+ return put_player_in_spawn(obj)
+end)
+