2015-09-01 17:15:24 +02:00
|
|
|
--
|
|
|
|
-- Weather mod
|
|
|
|
-- By Kaadmy, for Pixture
|
|
|
|
--
|
|
|
|
|
|
|
|
weather = {}
|
|
|
|
weather.weather = "clear"
|
|
|
|
weather.types = {"storm", "snowstorm", "clear"}
|
|
|
|
|
|
|
|
local function addvec(v1, v2)
|
|
|
|
return {x = v1.x + v2.x, y = v1.y + v2.y, z = v1.z + v2.z}
|
|
|
|
end
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
local snow_enable = minetest.setting_getbool("weather_snow_enable") or false
|
2015-09-23 20:07:30 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
local weather_soundspec=nil
|
2017-05-12 04:29:55 +02:00
|
|
|
local weather_pr=PseudoRandom(minetest.get_mapgen_params().seed + 2387)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
local function play_sound()
|
|
|
|
if weather_soundspec ~= nil then
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.sound_stop(weather_soundspec)
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
|
2015-12-16 19:01:43 +01:00
|
|
|
if weather.weather == "storm" then
|
2017-05-12 04:29:55 +02:00
|
|
|
weather_soundspec=minetest.sound_play({name="weather_storm"})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.after(18, play_sound)
|
2015-09-01 17:15:24 +02:00
|
|
|
return
|
|
|
|
elseif weather.weather == "snowstorm" then
|
2017-05-12 04:29:55 +02:00
|
|
|
weather_soundspec=minetest.sound_play({name="weather_snowstorm"})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.after(7, play_sound)
|
2015-09-01 17:15:24 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.after(3, play_sound)
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function setweather_type(type)
|
|
|
|
local valid = false
|
|
|
|
for i = 1, #weather.types do
|
|
|
|
if weather.types[i] == type then
|
|
|
|
valid = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if valid then
|
|
|
|
weather.weather = type
|
|
|
|
play_sound()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_globalstep(
|
2015-09-01 17:15:24 +02:00
|
|
|
function(dtime)
|
2017-05-12 04:29:55 +02:00
|
|
|
if minetest.setting_getbool("weather_enable") then
|
2015-09-01 17:15:24 +02:00
|
|
|
if weather_pr:next(0, 5000) < 1 then
|
|
|
|
local weathertype = weather_pr:next(0, 19)
|
|
|
|
|
|
|
|
-- on avg., every 1800 frames the weather.weather will change to one of:
|
|
|
|
-- 13/20 chance of clear weather
|
|
|
|
-- 6/20 chance or stormy weather
|
|
|
|
-- 1/20 chance of snowstorm weather
|
|
|
|
|
|
|
|
if weathertype < 13 then
|
|
|
|
weather.weather = "clear"
|
|
|
|
elseif weathertype < 19 then
|
|
|
|
weather.weather = "storm"
|
2015-09-23 20:07:30 +02:00
|
|
|
elseif weathertype < 20 and snow_enable then
|
2015-09-01 17:15:24 +02:00
|
|
|
weather.weather = "snowstorm"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
local light = (minetest.get_timeofday()*2)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
if light > 1 then
|
|
|
|
light=1-(light-1)
|
|
|
|
end
|
|
|
|
light=(light*0.6)+0.1
|
|
|
|
|
|
|
|
local skycol=math.floor(light*190)
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
for _,player in ipairs(minetest.get_connected_players()) do
|
2015-09-01 17:15:24 +02:00
|
|
|
if weather.weather == "storm" or weather.weather == "snowstorm" then
|
|
|
|
player:set_sky({r = skycol, g = skycol, b = skycol*1.2}, "plain", {})
|
|
|
|
player:override_day_night_ratio(light)
|
|
|
|
else
|
|
|
|
player:set_sky(nil, "regular", {})
|
|
|
|
player:override_day_night_ratio(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
local p=player:getpos()
|
|
|
|
|
|
|
|
if weather.weather == "storm" then
|
2017-05-12 04:29:55 +02:00
|
|
|
if minetest.get_node_light({x=p.x, y=p.y+15, z=p.z}, 0.5) == 15 then
|
2015-09-01 17:15:24 +02:00
|
|
|
local minpos = addvec(player:getpos(), {x = -15, y = 15, z = -15})
|
|
|
|
local maxpos = addvec(player:getpos(), {x = 15, y = 10, z = 15})
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.add_particlespawner(
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
|
|
|
amount = 30,
|
|
|
|
time = 0.5,
|
|
|
|
minpos = minpos,
|
|
|
|
maxpos = maxpos,
|
|
|
|
minvel = {x = 0, y = -20, z = 0},
|
|
|
|
maxvel = {x = 0, y = -20, z = 0},
|
|
|
|
minexptime = 0.9,
|
|
|
|
maxexptime = 1.1,
|
|
|
|
minsize = 2,
|
|
|
|
maxsize = 3,
|
|
|
|
collisiondetection = true,
|
2016-11-14 02:24:52 +01:00
|
|
|
collision_removal = true,
|
2015-09-01 17:15:24 +02:00
|
|
|
vertical = true,
|
|
|
|
texture = "weather_rain.png",
|
|
|
|
playername = player:get_player_name()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
elseif weather.weather == "snowstorm" then
|
|
|
|
if math.random(0, 6000*dtime) <= 1 then
|
|
|
|
local hp = player:get_hp()
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
if minetest.get_node_light(p) == 15 then
|
2015-09-01 17:15:24 +02:00
|
|
|
player:set_hp(hp-1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
if minetest.get_node_light({x=p.x, y=p.y+15, z=p.z}, 0.5) == 15 then
|
2015-09-01 17:15:24 +02:00
|
|
|
local minpos = addvec(player:getpos(), {x = -30, y = 20, z = -30})
|
|
|
|
local maxpos = addvec(player:getpos(), {x = 30, y = 15, z = 30})
|
|
|
|
local vel = {x = 16.0, y = -8, z = 13.0}
|
|
|
|
local acc = {x = -16.0, y = -8, z = -13.0}
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.add_particlespawner(
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
|
|
|
amount = 8,
|
|
|
|
time = 0.4,
|
|
|
|
minpos = minpos,
|
|
|
|
maxpos = maxpos,
|
|
|
|
minvel = {x=-vel.x, y=vel.y, z=-vel.z},
|
|
|
|
maxvel = vel,
|
|
|
|
minacc = acc,
|
|
|
|
maxacc = acc,
|
|
|
|
minexptime = 1.0,
|
|
|
|
maxexptime = 1.4,
|
|
|
|
minsize = 3,
|
|
|
|
maxsize = 4,
|
|
|
|
collisiondetection = true,
|
2017-05-12 06:24:54 +02:00
|
|
|
collision_removal = true,
|
2015-09-01 17:15:24 +02:00
|
|
|
vertical = false,
|
|
|
|
texture = "weather_snowflake.png",
|
|
|
|
playername = player:get_player_name()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2017-05-15 19:44:27 +02:00
|
|
|
minetest.register_privilege(
|
|
|
|
"weather",
|
|
|
|
{
|
|
|
|
description = "Can use /weather command",
|
|
|
|
give_to_singleplayer = false
|
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_chatcommand(
|
2015-09-01 17:15:24 +02:00
|
|
|
"weather",
|
|
|
|
{
|
|
|
|
params = "[storm|snowstorm|clear]",
|
|
|
|
description = "Set the weather to either clear, storm, or snowstorm",
|
2017-05-15 20:39:46 +02:00
|
|
|
privs = {weather = true},
|
2015-09-01 17:15:24 +02:00
|
|
|
func = function(name, param)
|
2017-05-12 06:24:54 +02:00
|
|
|
setweather_type(param)
|
|
|
|
end
|
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
setweather_type("clear")
|
|
|
|
|
2016-11-14 02:24:52 +01:00
|
|
|
default.log("mod:weather", "loaded")
|