diff options
author | Och Noe <och_noe@forksworld.de> | 2021-05-20 03:16:13 +0200 |
---|---|---|
committer | Och Noe <och_noe@forksworld.de> | 2021-05-20 03:16:13 +0200 |
commit | 33647ef72dba244388263189c510a26e79a01399 (patch) | |
tree | 3dbfbecea12bb3ff9b76a3c5e5f8f9632972087d | |
parent | 42d33d92a7365c58f944bd42100ab775dc1e872a (diff) | |
download | cs_waypoints-33647ef72dba244388263189c510a26e79a01399.tar.gz cs_waypoints-33647ef72dba244388263189c510a26e79a01399.tar.bz2 cs_waypoints-33647ef72dba244388263189c510a26e79a01399.zip |
new command: .day teleport to a place and automatically return
-rw-r--r-- | init.lua | 67 |
1 files changed, 63 insertions, 4 deletions
@@ -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, + } + ) |