aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOch Noe <och_noe@forksworld.de>2021-09-23 14:42:37 +0200
committerOch Noe <och_noe@forksworld.de>2021-09-23 14:42:37 +0200
commit30b17c555aa93d8ebe6aafe762622135b0f7145a (patch)
tree16c019d7cab6a7c80b88a3851b8b487ca82bbb31
parent274bc7abbfdb069fce417aad444c244897e3a5b9 (diff)
downloadcs_waypoints-30b17c555aa93d8ebe6aafe762622135b0f7145a.tar.gz
cs_waypoints-30b17c555aa93d8ebe6aafe762622135b0f7145a.tar.bz2
cs_waypoints-30b17c555aa93d8ebe6aafe762622135b0f7145a.zip
added '?' for the viewing direction to wp_shift, by Maverick2797
-rw-r--r--init.lua52
1 files changed, 30 insertions, 22 deletions
diff --git a/init.lua b/init.lua
index 7776885..7cd4c86 100644
--- a/init.lua
+++ b/init.lua
@@ -249,48 +249,56 @@ end
-- new shift with more than one possible shift coordinate
-- only the last value for one coordinate is used
-local function position_shift2(p)
+-- viewing direction (?) added by Maverick2797 on 2021-09-23
+local function position_shift2(p)
if not p then return end
-
+ local player = minetest.localplayer
local param = p:split(" ")
-
+
local shift = {}
shift.x = 0
shift.y = 0
shift.z = 0
-
+
local vp = 1
- while (vp+1 <= #param )
- do
+ while (vp+1 <= #param ) do
local 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
+
+ local distance = tonumber(param[vp+1])
+ if not distance then
+ distance = 0
+ end
+
+ local 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 direction == "?" then
+ --tp according to facing angle
+ local yaw = player:get_last_look_horizontal()
+ local pitch = player:get_last_look_vertical()
+ shift.x = distance*math.cos(yaw)*math.cos(pitch)
+ shift.z = distance*math.sin(yaw)*math.cos(pitch)
+ shift.y = distance*math.sin(pitch)
+ elseif d ~= "" then
shift[direction] = distance
end
vp = vp+2
end
-
+
if shift.x == 0 and shift.y == 0 and shift.z == 0 then
return
end
-
- local here = minetest.localplayer:get_pos()
-
+
+ local here = player: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