Compare commits
5 Commits
b3a48ed647
...
1e4d9e80c1
Author | SHA1 | Date |
---|---|---|
Och Noe | 1e4d9e80c1 | |
Och Noe | 30b17c555a | |
Och Noe | 274bc7abbf | |
Och Noe | 01e27c7757 | |
Och Noe | e735475a10 |
188
init.lua
188
init.lua
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
local mod_name = minetest.get_current_modname()
|
local mod_name = minetest.get_current_modname()
|
||||||
|
|
||||||
local mod_version = "2.8"
|
local mod_version = "2.15"
|
||||||
|
|
||||||
local function log(level, message)
|
local function log(level, message)
|
||||||
minetest.log(level, ('[%s] %s'):format(mod_name, message))
|
minetest.log(level, ('[%s] %s'):format(mod_name, message))
|
||||||
|
@ -20,6 +20,7 @@ local mod_storage = minetest.get_mod_storage()
|
||||||
local search_delta_default = 10
|
local search_delta_default = 10
|
||||||
|
|
||||||
local daydelay_default = 5
|
local daydelay_default = 5
|
||||||
|
local bouncedelay_default = 10
|
||||||
|
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
|
@ -150,7 +151,7 @@ local function stack_pop()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function stack_use()
|
local function stack_use()
|
||||||
wp_stack = load_waypoints_stack()
|
local wp_stack = load_waypoints_stack()
|
||||||
count = 0
|
count = 0
|
||||||
if nil ~= wp_stack then count = #wp_stack end
|
if nil ~= wp_stack then count = #wp_stack end
|
||||||
if count<1 then
|
if count<1 then
|
||||||
|
@ -162,7 +163,7 @@ local function stack_use()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function stack_exch()
|
local function stack_exch()
|
||||||
wp_stack = load_waypoints_stack()
|
local wp_stack = load_waypoints_stack()
|
||||||
count = 0
|
count = 0
|
||||||
if nil ~= wp_stack then count = #wp_stack end
|
if nil ~= wp_stack then count = #wp_stack end
|
||||||
if count<2 then
|
if count<2 then
|
||||||
|
@ -178,7 +179,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
local function stack_show()
|
local function stack_show()
|
||||||
wp_stack = load_waypoints_stack()
|
local wp_stack = load_waypoints_stack()
|
||||||
count = 0
|
count = 0
|
||||||
if nil ~= wp_stack then count = #wp_stack end
|
if nil ~= wp_stack then count = #wp_stack end
|
||||||
if count<1 then
|
if count<1 then
|
||||||
|
@ -248,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
|
||||||
param = p:split(" ")
|
local param = p:split(" ")
|
||||||
|
|
||||||
shift = {}
|
local shift = {}
|
||||||
shift.x = 0
|
shift.x = 0
|
||||||
shift.y = 0
|
shift.y = 0
|
||||||
shift.z = 0
|
shift.z = 0
|
||||||
|
|
||||||
vp = 1
|
local vp = 1
|
||||||
while (vp+1 <= #param )
|
while (vp+1 <= #param ) do
|
||||||
do
|
local direction = param[vp]
|
||||||
direction = param[vp]
|
|
||||||
d = ""
|
local distance = tonumber(param[vp+1])
|
||||||
if direction == "x" or direction == "X" then d = "x" end
|
if not distance then
|
||||||
if direction == "y" or direction == "Y" then d = "y" end
|
distance = 0
|
||||||
if direction == "z" or direction == "Z" then d = "z" end
|
end
|
||||||
if d ~= "" then
|
|
||||||
distance = tonumber(param[vp+1])
|
local d = ""
|
||||||
if not distance then
|
if direction == "x" or direction == "X" then d = "x" end
|
||||||
distance = 0
|
if direction == "y" or direction == "Y" then d = "y" end
|
||||||
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
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
@ -320,7 +329,7 @@ end
|
||||||
|
|
||||||
local function teleport_day_back(x,y,z)
|
local function teleport_day_back(x,y,z)
|
||||||
minetest.run_server_chatcommand('teleport',
|
minetest.run_server_chatcommand('teleport',
|
||||||
string.format("%d %d %d",x,y+1,z)
|
string.format("%f %f %f",x,y+1,z)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -377,6 +386,100 @@ local function teleport_day(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function teleport_bounce(params)
|
||||||
|
|
||||||
|
if not params or
|
||||||
|
params == ""
|
||||||
|
|
||||||
|
then
|
||||||
|
-- no parameter - return
|
||||||
|
minetest.display_chat_message("no waypoint given")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local bouncedelay = mod_storage:get_string('bouncedelay')
|
||||||
|
bouncedelay = (bouncedelay and tonumber(minetest.deserialize(bouncedelay))) or
|
||||||
|
bouncedelay_default
|
||||||
|
|
||||||
|
local sdp = string.find(params,"setdelay",1,false)
|
||||||
|
if sdp and sdp == 1 then
|
||||||
|
local newtime = tonumber(params:sub(10,16))
|
||||||
|
|
||||||
|
if newtime and newtime>0 then
|
||||||
|
mod_storage:set_string('bouncedelay', minetest.serialize(newtime))
|
||||||
|
minetest.display_chat_message("delay saved")
|
||||||
|
else
|
||||||
|
minetest.display_chat_message("delay: "..bouncedelay)
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local bouncepos = params
|
||||||
|
local bouncetarget = waypoints[bouncepos]
|
||||||
|
if not bouncetarget then
|
||||||
|
minetest.display_chat_message("unknown waypoint")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local pstr = tostring_point(bouncetarget)
|
||||||
|
local point = minetest.localplayer:get_pos()
|
||||||
|
|
||||||
|
-- from Maverick2897 with some small changes
|
||||||
|
local player = minetest.localplayer
|
||||||
|
local hud_id = player:hud_add({
|
||||||
|
hud_elem_type = "text",
|
||||||
|
position = {x=0.0,y=0.8},
|
||||||
|
size = {x=-20,y=-20},
|
||||||
|
alignment = {x=1,y=0},
|
||||||
|
offset = {x=8,y=0},
|
||||||
|
number = 0xffffff,
|
||||||
|
})
|
||||||
|
for i=bouncedelay,1,-1 do
|
||||||
|
minetest.after(bouncedelay-i,
|
||||||
|
function()
|
||||||
|
local text = ""
|
||||||
|
if i == 1 then
|
||||||
|
text = "Returning Now"
|
||||||
|
else
|
||||||
|
text = "Returning in "..i.."s\nTarget Pos: "..bouncepos.." ("..pstr..")\nReturn Pos: "..tostring_point(point)
|
||||||
|
end
|
||||||
|
player:hud_change(hud_id,"text",text)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
minetest.after(bouncedelay,function()player:hud_remove(hud_id)end)
|
||||||
|
--
|
||||||
|
|
||||||
|
minetest.after(bouncedelay,teleport_day_back,point.x,point.y,point.z)
|
||||||
|
minetest.display_chat_message("position "..pstr)
|
||||||
|
minetest.run_server_chatcommand('teleport', pstr)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function wp_export(param)
|
||||||
|
local wpl = load_waypoints()
|
||||||
|
if not wpl then return end
|
||||||
|
local list = ""
|
||||||
|
for k,p in pairsByKeys(wpl,lc_cmp) do
|
||||||
|
if param == "" or string.find(k,param,1,true) then
|
||||||
|
local line = "("..p.x..","..p.y..","..p.y..") name = "..k.."\n"
|
||||||
|
list = list .. line
|
||||||
|
end
|
||||||
|
end
|
||||||
|
minetest.display_chat_message(list)
|
||||||
|
minetest.show_formspec("cs_waypoints:export",
|
||||||
|
"size[15,12]" ..
|
||||||
|
"label[3.5,0;Waypoint List]"..
|
||||||
|
"textarea[0.3,1;15,11;note;;".. list .."]"..
|
||||||
|
"button_exit[4.5,11.2;1.4,1;e;Close]")
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
-- chat commands
|
-- chat commands
|
||||||
|
@ -614,3 +717,26 @@ minetest.register_chatcommand('day', {
|
||||||
func = teleport_day,
|
func = teleport_day,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
-- bounce name idea by Maverick2797 on 2021-05-20
|
||||||
|
-- jump to a waypoint and 'bounce' back to the start point after a delay
|
||||||
|
minetest.register_chatcommand('bounce', {
|
||||||
|
params = '[<waypoint>|setdelay [<number>]]',
|
||||||
|
description = 'teleports to the given waypoint and returns after a few seconds ',
|
||||||
|
func = teleport_bounce,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
minetest.register_chatcommand('wp_export', {
|
||||||
|
params = '[<name part>]',
|
||||||
|
description = 'Export all waypoints as list',
|
||||||
|
func = wp_export,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
log('action', 'CSM cs_waypoints '..mod_version..' loaded')
|
||||||
|
minetest.display_chat_message("CSM cs_waypoints "..mod_version.." loaded")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue