minetest_mod_weather/weather/init.lua

52 lines
1.2 KiB
Lua
Raw Normal View History

2013-03-24 14:40:18 +01:00
-- Weather:
-- * rain
-- * snow
2018-04-11 17:55:27 +02:00
-- * wind
2013-03-24 14:40:18 +01:00
assert(minetest.add_particlespawner, "I told you to run the latest GitHub!")
save_weather = function ()
local file = io.open(minetest.get_worldpath().."/weather", "w+")
2018-04-11 17:55:27 +02:00
file:write(minetest.serialize(weather))
2013-03-24 14:40:18 +01:00
file:close()
end
read_weather = function ()
local file = io.open(minetest.get_worldpath().."/weather", "r")
2018-04-11 17:55:27 +02:00
if not file then return {type = "none", wind = 0} end
local readweather = minetest.deserialize(file:read())
2013-03-24 14:40:18 +01:00
file:close()
2018-04-11 17:55:27 +02:00
if type(readweather)~="table" then
return {type = "none", wind = 0}
end
2013-03-24 14:40:18 +01:00
return readweather
end
weather = read_weather()
2018-04-14 08:07:11 +02:00
minetest.register_globalstep(function()
2018-04-11 17:55:27 +02:00
if weather.type == "rain" or weather.type == "snow" then
2013-03-24 14:40:18 +01:00
if math.random(1, 10000) == 1 then
2018-04-11 17:55:27 +02:00
weather.type = "none"
2013-03-24 14:40:18 +01:00
save_weather()
end
else
if math.random(1, 50000) == 1 then
2018-04-11 17:55:27 +02:00
weather.wind = math.random(0,10)
weather.type = "rain"
2013-03-24 14:40:18 +01:00
save_weather()
end
if math.random(1, 50000) == 2 then
2018-04-11 17:55:27 +02:00
weather.wind = math.random(0,10)
weather.type = "snow"
2013-03-24 14:40:18 +01:00
save_weather()
end
end
end)
dofile(minetest.get_modpath("weather").."/rain.lua")
dofile(minetest.get_modpath("weather").."/snow.lua")
dofile(minetest.get_modpath("weather").."/command.lua")