mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 18:41:09 +01:00
Add duration parameter to weather command
This commit is contained in:
parent
c6a56ed430
commit
a3388e5288
1 changed files with 21 additions and 6 deletions
|
@ -187,20 +187,35 @@ minetest.register_privilege("weather_manager", {
|
||||||
|
|
||||||
-- Weather command definition. Set
|
-- Weather command definition. Set
|
||||||
minetest.register_chatcommand("weather", {
|
minetest.register_chatcommand("weather", {
|
||||||
params = "clear | rain | snow | thunder",
|
params = "(clear | rain | snow | thunder) [<duration>]",
|
||||||
description = "Changes the weather to the specified parameter.",
|
description = "Changes the weather to the specified parameter.",
|
||||||
privs = {weather_manager = true},
|
privs = {weather_manager = true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
if (param == "") then
|
if (param == "") then
|
||||||
return false, "Error: No weather specified."
|
return false, "Error: No weather specified."
|
||||||
end
|
end
|
||||||
local new_weather
|
local new_weather, end_time
|
||||||
if param == "clear" then
|
local parse1, parse2 = string.match(param, "(%w+) ?(%d*)")
|
||||||
new_weather = "none"
|
if parse1 then
|
||||||
|
if parse1 == "clear" then
|
||||||
|
new_weather = "none"
|
||||||
|
else
|
||||||
|
new_weather = parse1
|
||||||
|
end
|
||||||
else
|
else
|
||||||
new_weather = param
|
return false, "Error: Invalid parameters."
|
||||||
end
|
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
|
if success then
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue