From e735475a106370aa60e72b12498b30e221fec325 Mon Sep 17 00:00:00 2001 From: Och Noe Date: Sat, 3 Jul 2021 04:16:10 +0200 Subject: - ".bounce" added - small bugfix for rounding --- init.lua | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 150390c..a483344 100644 --- a/init.lua +++ b/init.lua @@ -4,7 +4,7 @@ local mod_name = minetest.get_current_modname() -local mod_version = "2.8" +local mod_version = "2.11" local function log(level, 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 daydelay_default = 5 +local bouncedelay_default = 10 -- -- @@ -320,7 +321,7 @@ end local function teleport_day_back(x,y,z) minetest.run_server_chatcommand('teleport', - string.format("%d %d %d",x,y+1,z) + string.format("%f %f %f",x,y+1,z) ) return end @@ -377,6 +378,54 @@ local function teleport_day(params) 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() + 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 + + + -- -- -- chat commands @@ -614,3 +663,20 @@ minetest.register_chatcommand('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 = '[|setdelay []]', + description = 'teleports to the given waypoint and returns after a few seconds ', + func = teleport_bounce, + } + ) + + + + +log('action', 'CSM cs_waypoints '..mod_version..' loaded') +minetest.display_chat_message("CSM cs_waypoints "..mod_version.." loaded") + -- cgit v1.2.3