mirror of
https://github.com/t-affeldt/climate_api.git
synced 2025-06-30 07:20:48 +02:00
Add chat commands for forcing weather presets
This commit is contained in:
@ -79,11 +79,54 @@ minetest.register_chatcommand("set_humidity", {
|
||||
|
||||
minetest.register_chatcommand("weather_settings", {
|
||||
description = "Print the active Climate API configuration",
|
||||
privs = { weather = true },
|
||||
func = function(playername)
|
||||
minetest.chat_send_player(playername, "Current Settings\n================")
|
||||
for setting, value in pairs(climate_mod.settings) do
|
||||
minetest.chat_send_player(playername, dump2(value, setting))
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("set_weather", {
|
||||
params ="<weather> <status>",
|
||||
description ="Turn the specified weather preset on or off for all players or reset it to automatic",
|
||||
privs = { weather = true },
|
||||
func = function(playername, param)
|
||||
local arguments = {}
|
||||
for w in param:gmatch("%S+") do table.insert(arguments, w) end
|
||||
local weather = arguments[1]
|
||||
if climate_mod.weathers[weather] == nil then
|
||||
minetest.chat_send_player(playername, "Unknown weather preset")
|
||||
return
|
||||
end
|
||||
local status
|
||||
if arguments[2] == "on" then
|
||||
status = true
|
||||
elseif arguments[2] == "off" then
|
||||
status = false
|
||||
elseif arguments[2] == "auto" then
|
||||
status = nil
|
||||
else
|
||||
minetest.chat_send_player(playername, "Invalid weather status. Set the preset to either on, off or auto.")
|
||||
return
|
||||
end
|
||||
climate_mod.forced_weather[weather] = status
|
||||
minetest.chat_send_player(playername, "Weather " .. weather .. " successfully set to " .. arguments[2])
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("weather_status", {
|
||||
description = "Prints which weather presets are enforced or disabled",
|
||||
func = function(playername)
|
||||
minetest.chat_send_player(playername, "Current activation rules:\n================")
|
||||
for weather, _ in pairs(climate_mod.weathers) do
|
||||
local status = "auto"
|
||||
if climate_mod.forced_weather[weather] == true then
|
||||
status = "on"
|
||||
elseif climate_mod.forced_weather[weather] == false then
|
||||
status = "off"
|
||||
end
|
||||
minetest.chat_send_player(playername, dump2(status, weather))
|
||||
end
|
||||
end
|
||||
})
|
@ -30,11 +30,15 @@ local function test_condition(condition, env, goal)
|
||||
end
|
||||
end
|
||||
|
||||
local function is_weather_active(player, weather_config, env)
|
||||
if type(weather_config.conditions) == "function" then
|
||||
return weather_config.conditions(env)
|
||||
local function is_weather_active(player, weather, env)
|
||||
if climate_mod.forced_weather[weather] ~= nil then
|
||||
return climate_mod.forced_weather[weather]
|
||||
end
|
||||
for condition, goal in pairs(weather_config.conditions) do
|
||||
local config = climate_mod.weathers[weather]
|
||||
if type(config.conditions) == "function" then
|
||||
return config.conditions(env)
|
||||
end
|
||||
for condition, goal in pairs(config.conditions) do
|
||||
if not test_condition(condition, env, goal) then
|
||||
return false
|
||||
end
|
||||
@ -70,7 +74,7 @@ function trigger.get_active_effects()
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local pname = player:get_player_name()
|
||||
local env = environments[pname]
|
||||
if is_weather_active(player, wconfig, env) then
|
||||
if is_weather_active(player, wname, env) then
|
||||
if type(climate_mod.current_weather[pname]) == "nil" then
|
||||
climate_mod.current_weather[pname] = {}
|
||||
end
|
||||
|
Reference in New Issue
Block a user