added '?' for the viewing direction to wp_shift, by Maverick2797
parent
274bc7abbf
commit
30b17c555a
52
init.lua
52
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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue