add dynamic per player change

This commit is contained in:
cora 2021-09-26 15:48:18 +02:00
parent c6ba41e6e8
commit 53603050c0
4 changed files with 41 additions and 14 deletions

View File

@ -15,6 +15,7 @@ local players = {}
players.particlespawners={}
players.soundhandler={}
players.weatheractive = {}
players.weather = {}
local interval=1
@ -152,6 +153,7 @@ function mcl_weather.start_weather_player(name,def)
if def.sound then
mcl_weather.add_sound(name,def.sound)
end
players.weather[name]=def
players.weatheractive[name] = true
end
@ -176,6 +178,7 @@ function mcl_weather.start_weather(def)
doplayers(function(name)
if def.start_player == nil or not def.start_player(name) then
mcl_weather.start_weather_player(name,def)
players.weather[name]=mcl_weather.current
end
end)
end
@ -198,35 +201,56 @@ function mcl_weather.change(new_weather,force)
local def=mcl_weather.get_weatherdef(new_weather)
local old=mcl_weather.get_weatherdef(mcl_weather.current)
if not def then return end
mcl_weather.stop_weather(old)
mcl_weather.start_weather(def)
mcl_weather.current = new_weather
mcl_weather.state = new_weather
local duration = math.random(def.min_duration,def.max_duration)
mcl_weather.current_endtime = os.time() + duration
if force or minetest.settings:get_bool("mcl_doWeatherCycle") then
mcl_weather.stop_weather(old)
mcl_weather.start_weather(def)
mcl_weather.current = new_weather
mcl_weather.state = new_weather
mcl_weather.current_endtime = os.time() + duration
end
minetest.after(duration,function()
mcl_weather.change(mcl_weather.get_next_weather())
end)
minetest.chat_send_all("weather changed to "..mcl_weather.current)
end
function mcl_weather.change_player(name,new)
if players.weather[name] ~= new then
local nd = mcl_weather.get_weatherdef(new)
if nd then
mcl_weather.stop_weather_player(name,mcl_weather.get_weatherdef(mcl_weather.current))
mcl_weather.start_weather_player(name,nd)
players.weather[name] = new
end
end
end
function mcl_weather.tick()
doplayers(function(name,player)
local pos=player:get_pos()
local cdef=mcl_weather.get_weatherdef(mcl_weather.current)
if players.weatheractive[name] then
if ( cdef.at_pos ~= nil and not cdef.at_pos(pos) ) or not mcl_weather.player_has_weather(player) then
if cdef.at_pos ~= nil then --switch to defined weather in at_pos conditions
if not cdef.at_pos(pos) and cdef.change_at_pos ~= nil then
mcl_weather.change_player(name,cdef.change_at_pos)
else
mcl_weather.change_player(name,mcl_weather.current)
end
end
if players.weatheractive[name] then --turn off weather indoows/underwater
if not mcl_weather.player_has_weather(player) then
mcl_weather.stop_weather_player(name,cdef)
--mcl_weather.delete_particlespawners_player(name)
players.weatheractive[name] = false
end
else
if ( cdef.at_pos == nil or cdef.at_pos(pos)) and mcl_weather.player_has_weather(player) then
if mcl_weather.player_has_weather(player) then
mcl_weather.start_weather_player(name,cdef)
--mcl_weather.add_particlespawners_player(name,cdef.particlespawners)
players.weather[name]=mcl_weather.current
players.weatheractive[name] = true
end
end
end)
minetest.after(interval,mcl_weather.tick)
end

View File

@ -92,7 +92,8 @@ mcl_weather.register_weather("rain",{
if mcl_worlds.has_weather(pos) and biome.heat > 15 and biome.heat < 95 then
return true
end
end
end,
change_at_pos = "snow"
})
if mcl_weather.allow_abm then

View File

@ -69,5 +69,6 @@ mcl_weather.register_weather("snow",{
if mcl_worlds.has_weather(pos) and biome.heat < 15 then
return true
end
end
end,
change_at_pos = "rain"
})

View File

@ -99,5 +99,6 @@ mcl_weather.register_weather("thunder",{
if mcl_worlds.has_weather(pos) and biome.heat > 15 and biome.heat < 95 then
return true
end
end
end,
change_at_pos = "snow"
})