From a3388e5288ef89cf2181809469514c24f0247041 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 24 Jan 2018 06:50:28 +0100 Subject: [PATCH] Add duration parameter to weather command --- mods/ENVIRONMENT/mcl_weather/weather_core.lua | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/mods/ENVIRONMENT/mcl_weather/weather_core.lua b/mods/ENVIRONMENT/mcl_weather/weather_core.lua index 46592cce..08387987 100644 --- a/mods/ENVIRONMENT/mcl_weather/weather_core.lua +++ b/mods/ENVIRONMENT/mcl_weather/weather_core.lua @@ -187,20 +187,35 @@ minetest.register_privilege("weather_manager", { -- Weather command definition. Set minetest.register_chatcommand("weather", { - params = "clear | rain | snow | thunder", + params = "(clear | rain | snow | thunder) []", description = "Changes the weather to the specified parameter.", privs = {weather_manager = true}, func = function(name, param) if (param == "") then return false, "Error: No weather specified." end - local new_weather - if param == "clear" then - new_weather = "none" + local new_weather, end_time + local parse1, parse2 = string.match(param, "(%w+) ?(%d*)") + if parse1 then + if parse1 == "clear" then + new_weather = "none" + else + new_weather = parse1 + end else - new_weather = param + return false, "Error: Invalid parameters." end - local success = mcl_weather.change_weather(new_weather) + if parse2 then + if type(tonumber(parse2)) == "number" then + local duration = tonumber(parse2) + if duration < 1 then + return false, "Error: Duration can't be less than 1 second." + end + end_time = minetest.get_gametime() + duration + end + end + + local success = mcl_weather.change_weather(new_weather, end_time) if success then return true else -- 2.11.4.GIT