Implement wind

This commit is contained in:
theFox6 2018-04-11 17:55:27 +02:00 committed by Jeija
parent b2195be046
commit d434557adf
4 changed files with 18 additions and 13 deletions

View File

@ -9,7 +9,7 @@ minetest.register_chatcommand("setweather", {
description = "Set weather to rain, snow or none", -- full description description = "Set weather to rain, snow or none", -- full description
privs = {weather = true}, privs = {weather = true},
func = function(name, param) func = function(name, param)
weather = param weather.type = param
save_weather() save_weather()
end end
}) })

View File

@ -1,7 +1,7 @@
-- Weather: -- Weather:
-- * rain -- * rain
-- * snow -- * snow
-- * wind (not implemented) -- * wind
assert(minetest.add_particlespawner, "I told you to run the latest GitHub!") assert(minetest.add_particlespawner, "I told you to run the latest GitHub!")
@ -11,33 +11,38 @@ end
save_weather = function () save_weather = function ()
local file = io.open(minetest.get_worldpath().."/weather", "w+") local file = io.open(minetest.get_worldpath().."/weather", "w+")
file:write(weather) file:write(minetest.serialize(weather))
file:close() file:close()
end end
read_weather = function () read_weather = function ()
local file = io.open(minetest.get_worldpath().."/weather", "r") 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() local readweather = minetest.deserialize(file:read())
file:close() file:close()
if type(readweather)~="table" then
return {type = "none", wind = 0}
end
return readweather return readweather
end end
weather = read_weather() weather = read_weather()
minetest.register_globalstep(function(dtime) 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 if math.random(1, 10000) == 1 then
weather = "none" weather.type = "none"
save_weather() save_weather()
end end
else else
if math.random(1, 50000) == 1 then if math.random(1, 50000) == 1 then
weather = "rain" weather.wind = math.random(0,10)
weather.type = "rain"
save_weather() save_weather()
end end
if math.random(1, 50000) == 2 then if math.random(1, 50000) == 2 then
weather = "snow" weather.wind = math.random(0,10)
weather.type = "snow"
save_weather() save_weather()
end end
end end

View File

@ -1,6 +1,6 @@
-- Rain -- Rain
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
if weather ~= "rain" then return end if weather.type ~= "rain" then return end
for _, player in ipairs(minetest.get_connected_players()) do for _, player in ipairs(minetest.get_connected_players()) do
local ppos = player:getpos() local ppos = player:getpos()
@ -10,7 +10,7 @@ minetest.register_globalstep(function(dtime)
local minp = addvectors(ppos, {x=-9, y=7, z=-9}) local minp = addvectors(ppos, {x=-9, y=7, z=-9})
local maxp = addvectors(ppos, {x= 9, y=7, z= 9}) local maxp = addvectors(ppos, {x= 9, y=7, z= 9})
local vel = {x=0, y= -4, z=0} local vel = {x=math.random()*weather.wind, y= -4, z=math.random()*weather.wind}
local acc = {x=0, y=-9.81, z=0} local acc = {x=0, y=-9.81, z=0}
minetest.add_particlespawner({amount=25, time=0.5, minetest.add_particlespawner({amount=25, time=0.5,

View File

@ -1,6 +1,6 @@
-- Snow -- Snow
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
if weather ~= "snow" then return end if weather.type ~= "snow" then return end
for _, player in ipairs(minetest.get_connected_players()) do for _, player in ipairs(minetest.get_connected_players()) do
local ppos = player:getpos() local ppos = player:getpos()
@ -13,7 +13,7 @@ minetest.register_globalstep(function(dtime)
local minp_deep = addvectors(ppos, {x=-10, y=3.2, z=-10}) local minp_deep = addvectors(ppos, {x=-10, y=3.2, z=-10})
local maxp_deep = addvectors(ppos, {x= 10, y=2.6, z= 10}) local maxp_deep = addvectors(ppos, {x= 10, y=2.6, z= 10})
local vel = {x=0, y= -0.5, z=0} local vel = {x=math.random()*weather.wind, y= -0.5, z=math.random()*weather.wind}
local acc = {x=0, y= -0.5, z=0} local acc = {x=0, y= -0.5, z=0}
minetest.add_particlespawner(5, 0.5, minetest.add_particlespawner(5, 0.5,