From 6a1dfd695156a7b58a14dbed01c31e51249c3387 Mon Sep 17 00:00:00 2001 From: theFox6 Date: Tue, 10 Apr 2018 19:05:55 +0200 Subject: [PATCH] make weather a table containing type and wind --- weather/init.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/weather/init.lua b/weather/init.lua index 37777d7..9331bec 100644 --- a/weather/init.lua +++ b/weather/init.lua @@ -1,7 +1,7 @@ -- Weather: -- * rain -- * snow --- * wind (not implemented) +-- * wind assert(minetest.add_particlespawner, "I told you to run the latest GitHub!") @@ -17,27 +17,32 @@ end read_weather = function () local file = io.open(minetest.get_worldpath().."/weather", "r") - if not file then return end + if not file then return {type = "none", wind = 0} end local readweather = file:read() file:close() + if type(readweather)~="table" then + return {type = "none", wind = 0} + end return readweather end weather = read_weather() minetest.register_globalstep(function(dtime) - if weather == "rain" or weather == "snow" then + if weather.type == "rain" or weather.type == "snow" then if math.random(1, 10000) == 1 then - weather = "none" + weather.type = "none" save_weather() end else if math.random(1, 50000) == 1 then - weather = "rain" + weather.wind = math.random(0,10) + weather.type = "rain" save_weather() end if math.random(1, 50000) == 2 then - weather = "snow" + weather.wind = math.random(0,10) + weather.type = "snow" save_weather() end end