aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOch Noe <och_noe@forksworld.de>2020-07-25 16:58:36 +0200
committerOch Noe <och_noe@forksworld.de>2020-07-25 16:58:36 +0200
commit691b66140465dbe211c95033b3b786cd03d32a3f (patch)
treeb290b05f6d87d169b7baf8a920e407aa3253ebe6
parent98b4d32fdbef45c1bb261e23ca6a62e41eb95fd9 (diff)
downloadcs_waypoints-691b66140465dbe211c95033b3b786cd03d32a3f.tar.gz
cs_waypoints-691b66140465dbe211c95033b3b786cd03d32a3f.tar.bz2
cs_waypoints-691b66140465dbe211c95033b3b786cd03d32a3f.zip
shift can now handle several coordinates at once
-rw-r--r--init.lua50
1 files changed, 49 insertions, 1 deletions
diff --git a/init.lua b/init.lua
index 472357e..13a2398 100644
--- a/init.lua
+++ b/init.lua
@@ -10,6 +10,8 @@ end
log('action', 'CSM cs_waypoints loading...')
+minetest.display_chat_message("CSM cs_waypoints loading...")
+
local mod_storage = minetest.get_mod_storage()
@@ -209,6 +211,52 @@ local function position_shift(p)
end
+-- new shift with more than one possible shift coordinate
+-- only the last value for one coordinate is used
+local function position_shift2(p)
+ if not p then return end
+
+ param = p:split(" ")
+
+ shift = {}
+ shift.x = 0
+ shift.y = 0
+ shift.z = 0
+
+ vp = 1
+ while (vp+1 <= #param )
+ do
+ direction = param[vp]
+ d = ""
+ if direction == "x" or direction == "X" then d = "x" end
+ if direction == "y" or direction == "Y" then d = "y" end
+ if direction == "z" or direction == "Z" then d = "z" end
+ if d ~= "" then
+ distance = tonumber(param[vp+1])
+ if not distance then
+ distance = 0
+ end
+ shift[direction] = distance
+ end
+ vp = vp+2
+ end
+
+ if shift.x == 0 and shift.y == 0 and shift.z == 0 then
+ return
+ end
+
+ here = minetest.localplayer:get_pos()
+
+ here.x = here.x+shift.x
+ here.y = here.y+shift.y
+ here.z = here.z+shift.z
+
+ here.y = here.y - 1 -- correction
+
+ minetest.run_server_chatcommand('teleport', tostring_point(here))
+
+end
+
local function calc_distance(wp)
local wpname = wp
@@ -351,7 +399,7 @@ minetest.register_chatcommand('wp_search', {
minetest.register_chatcommand('wp_shift', {
params = '<axis> <distance>',
description = '"shift" the player along the given axis and add the given number',
- func = position_shift,
+ func = position_shift2,
}
)