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
privs = {weather = true},
func = function(name, param)
weather = param
weather.type = param
save_weather()
end
})

View File

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

View File

@ -1,6 +1,6 @@
-- Rain
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
local ppos = player:getpos()
@ -10,7 +10,7 @@ minetest.register_globalstep(function(dtime)
local minp = 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}
minetest.add_particlespawner({amount=25, time=0.5,

View File

@ -1,6 +1,6 @@
-- Snow
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
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 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}
minetest.add_particlespawner(5, 0.5,