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
|
-- new shift with more than one possible shift coordinate
|
||||||
-- only the last value for one coordinate is used
|
-- 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
|
if not p then return end
|
||||||
|
local player = minetest.localplayer
|
||||||
local param = p:split(" ")
|
local param = p:split(" ")
|
||||||
|
|
||||||
local shift = {}
|
local shift = {}
|
||||||
shift.x = 0
|
shift.x = 0
|
||||||
shift.y = 0
|
shift.y = 0
|
||||||
shift.z = 0
|
shift.z = 0
|
||||||
|
|
||||||
local vp = 1
|
local vp = 1
|
||||||
while (vp+1 <= #param )
|
while (vp+1 <= #param ) do
|
||||||
do
|
|
||||||
local direction = param[vp]
|
local direction = param[vp]
|
||||||
d = ""
|
|
||||||
if direction == "x" or direction == "X" then d = "x" end
|
local distance = tonumber(param[vp+1])
|
||||||
if direction == "y" or direction == "Y" then d = "y" end
|
if not distance then
|
||||||
if direction == "z" or direction == "Z" then d = "z" end
|
distance = 0
|
||||||
if d ~= "" then
|
end
|
||||||
distance = tonumber(param[vp+1])
|
|
||||||
if not distance then
|
local d = ""
|
||||||
distance = 0
|
if direction == "x" or direction == "X" then d = "x" end
|
||||||
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
|
shift[direction] = distance
|
||||||
end
|
end
|
||||||
vp = vp+2
|
vp = vp+2
|
||||||
end
|
end
|
||||||
|
|
||||||
if shift.x == 0 and shift.y == 0 and shift.z == 0 then
|
if shift.x == 0 and shift.y == 0 and shift.z == 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local here = minetest.localplayer:get_pos()
|
local here = player:get_pos()
|
||||||
|
|
||||||
here.x = here.x+shift.x
|
here.x = here.x+shift.x
|
||||||
here.y = here.y+shift.y
|
here.y = here.y+shift.y
|
||||||
here.z = here.z+shift.z
|
here.z = here.z+shift.z
|
||||||
|
|
||||||
-- here.y = here.y - 1 -- correction
|
-- here.y = here.y - 1 -- correction
|
||||||
|
|
||||||
minetest.run_server_chatcommand('teleport', tostring_point(here))
|
minetest.run_server_chatcommand('teleport', tostring_point(here))
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue