From edc010121c8951b35a7b64d8bcf515be3ef15989 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 16 Nov 2020 12:40:45 +0100 Subject: [PATCH] randomscreenshot: make it nice :) --- clientmods/randomscreenshot/init.lua | 22 ++++++++++++++++---- clientmods/randomscreenshot/settingtypes.txt | 3 +++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/clientmods/randomscreenshot/init.lua b/clientmods/randomscreenshot/init.lua index ad3768900..6cb9af384 100644 --- a/clientmods/randomscreenshot/init.lua +++ b/clientmods/randomscreenshot/init.lua @@ -4,16 +4,30 @@ randomscreenshot = {} -local interval=10 -- minimum number of minutes to wait til next screenshot -local rnd=10 --random time -local nextsc=0 +local function init_settings(setting_table) + for k, v in pairs(setting_table) do + if minetest.settings:get(k) == nil then + if type(v) == "boolean" then + minetest.settings:set_bool(k, v) + else + minetest.settings:set(k, v) + end + end + end +end +init_settings({ + randomscreenshot_interval = 10, + randomscreenshot_rnd = 10 +}) + +local nextsc=0 minetest.register_globalstep(function() if not minetest.settings:get_bool("randomsc") then return end if os.time() < nextsc then return end math.randomseed(os.clock()) - nextsc=os.time() + ( interval * 60 ) + math.random(rnd * 60) + nextsc=os.time() + ( minetest.settings:get('randomscreenshot_interval') * 60 ) + math.random(minetest.settings:get('randomscreenshot_rnd') * 60) minetest.after("15.0",function() minetest.hide_huds() minetest.display_chat_message("\n\n\n\n\n\n\n\n\n") diff --git a/clientmods/randomscreenshot/settingtypes.txt b/clientmods/randomscreenshot/settingtypes.txt index 39d2ec970..bd6029897 100644 --- a/clientmods/randomscreenshot/settingtypes.txt +++ b/clientmods/randomscreenshot/settingtypes.txt @@ -1 +1,4 @@ randomsc (Enable Autoscreenshot) bool false + +randomscreenshot_interval ( Minimum time to wait between screenshots in minutes ) int 10 +randomscreenshot_rnd (Random time between screenshots in minutes ) int 10