aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-04-09 23:29:55 +0300
committerPerttu Ahola <celeron55@gmail.com>2012-04-09 23:32:13 +0300
commit93cdc9b9dc240aef70ec5016552c7f36ee019865 (patch)
tree55157b777205cb9891fa7dd567cb2fe21e6c88fc
parent8ed74a342988b7d67a7c9eacc2257ba42acd00de (diff)
downloadminetest-93cdc9b9dc240aef70ec5016552c7f36ee019865.tar.gz
minetest-93cdc9b9dc240aef70ec5016552c7f36ee019865.tar.bz2
minetest-93cdc9b9dc240aef70ec5016552c7f36ee019865.zip
Support static_spawnpoint setting
-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
-rw-r--r--doc/lua_api.txt2
5 files changed, 69 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)
+
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index aabc673f9..9bb0dfe98 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -514,6 +514,7 @@ string:trim()
^ eg. string.trim("\n \t\tfoo bar\t ") == "foo bar"
minetest.pos_to_string({x=X,y=Y,z=Z}) -> "(X,Y,Z)"
^ Convert position to a printable string
+minetest.string_to_pos(string) -> position
minetest namespace reference
-----------------------------
@@ -576,6 +577,7 @@ Setting-related:
minetest.setting_set(name, value)
minetest.setting_get(name) -> string or nil
minetest.setting_getbool(name) -> boolean value or nil
+minetest.setting_get_pos(name) -> position or nil
minetest.add_to_creative_inventory(itemstring)
Authentication: