new command: .day teleport to a place and automatically return
parent
42d33d92a7
commit
33647ef72d
67
init.lua
67
init.lua
|
@ -19,6 +19,8 @@ local mod_storage = minetest.get_mod_storage()
|
|||
|
||||
local search_delta_default = 10
|
||||
|
||||
local daydelay_default = 5
|
||||
|
||||
--
|
||||
--
|
||||
-- local functions
|
||||
|
@ -309,11 +311,64 @@ local function calc_distance(wp)
|
|||
rg = l1 .. "\n" .. l2
|
||||
end
|
||||
|
||||
|
||||
return true,rg
|
||||
end
|
||||
|
||||
|
||||
local function teleport_day_back(x,y,z)
|
||||
minetest.run_server_chatcommand('teleport',
|
||||
string.format("%d %d %d",x,y,z)
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local function teleport_day(params)
|
||||
local daypos = mod_storage:get_string('daypos')
|
||||
local daydelay = mod_storage:get_string('daydelay')
|
||||
daypos = minetest.deserialize(daypos) or ""
|
||||
daydelay = (daydelay and tonumber(minetest.deserialize(daydelay))) or
|
||||
daydelay_default
|
||||
|
||||
if not params or
|
||||
params == ""
|
||||
then
|
||||
-- no parameter - execute the function
|
||||
if daypos == "" then
|
||||
minetest.display_chat_message("no saved position")
|
||||
return
|
||||
end
|
||||
minetest.run_server_chatcommand('teleport', tostring_point(daypos))
|
||||
local point = minetest.localplayer:get_pos()
|
||||
minetest.after(daydelay,teleport_day_back,point.x,point.y,point.z)
|
||||
return
|
||||
end
|
||||
|
||||
if params == "show" then
|
||||
minetest.display_chat_message("position: "..tostring_point(daypos)..
|
||||
" delay:"..daydelay)
|
||||
return
|
||||
end
|
||||
if params == "setpos" then
|
||||
local point = minetest.localplayer:get_pos()
|
||||
mod_storage:set_string('daypos', minetest.serialize(tostring_point(point)))
|
||||
minetest.display_chat_message("position saved")
|
||||
return
|
||||
end
|
||||
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('daydelay', minetest.serialize(newtime))
|
||||
minetest.display_chat_message("delay saved")
|
||||
end
|
||||
return
|
||||
end
|
||||
-- wrong parameters - what now?
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
--
|
||||
-- chat commands
|
||||
|
@ -522,7 +577,7 @@ minetest.register_chatcommand('wp_grep', {
|
|||
end),
|
||||
})
|
||||
|
||||
|
||||
-- wp_fgrep derived from wp_grep by erstazi
|
||||
minetest.register_chatcommand('wp_fgrep', {
|
||||
params = '<name>',
|
||||
description = 'lists matching waypoints',
|
||||
|
@ -545,5 +600,9 @@ minetest.register_chatcommand('wp_fgrep', {
|
|||
})
|
||||
|
||||
|
||||
|
||||
|
||||
minetest.register_chatcommand('day', {
|
||||
params = '[show|setpos|setdelay <number>]',
|
||||
description = 'teleports to the day button and return after a few seconds ',
|
||||
func = teleport_day,
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue