From 33647ef72dba244388263189c510a26e79a01399 Mon Sep 17 00:00:00 2001 From: Och Noe Date: Thu, 20 May 2021 03:16:13 +0200 Subject: new command: .day teleport to a place and automatically return --- init.lua | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 51f1021..c83fa29 100644 --- a/init.lua +++ b/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 = '', description = 'lists matching waypoints', @@ -545,5 +600,9 @@ minetest.register_chatcommand('wp_fgrep', { }) - - +minetest.register_chatcommand('day', { + params = '[show|setpos|setdelay ]', + description = 'teleports to the day button and return after a few seconds ', + func = teleport_day, + } + ) -- cgit v1.2.3