update ambience
parent
58a280f6d4
commit
c7af77673a
|
@ -0,0 +1,269 @@
|
|||
--Ambiance Configuration for version .08
|
||||
|
||||
local max_frequency_all = 1000 --the larger you make this number the lest frequent ALL sounds will happen recommended values between 100-2000.
|
||||
|
||||
--for frequencies below use a number between 0 and max_frequency_all
|
||||
--for volumes below, use a number between 0.0 and 1, the larger the number the louder the sounds
|
||||
local night_frequency = 20 --owls, wolves
|
||||
local night_volume = 0.9
|
||||
local night_frequent_frequency = 150 --crickets
|
||||
local night_frequent_volume = 0.9
|
||||
local day_frequency = 100 --crow, bluejay, cardinal
|
||||
local day_volume = 0.9
|
||||
local day_frequent_frequency = 1000 --crow, bluejay, cardinal
|
||||
local day_frequent_volume = 0.18
|
||||
local cave_frequency = 10 --bats
|
||||
local cave_volume = 1.0
|
||||
local cave_frequent_frequency = 70 --drops of water dripping
|
||||
local cave_frequent_volume = 1.0
|
||||
local water_frequent_frequency = 1000 --underwater sounds
|
||||
local water_frequent_volume = 1.0
|
||||
local music_frequency = 1 --music (suggestion: keep this one low like around 1)
|
||||
local music_volume = 0.3
|
||||
|
||||
local night = {
|
||||
handler = {},
|
||||
frequency = night_frequency,
|
||||
{name="horned_owl", length=3, gain=night_volume},
|
||||
{name="Wolves_Howling", length=11, gain=night_volume}
|
||||
}
|
||||
|
||||
local night_frequent = {
|
||||
handler = {},
|
||||
frequency = night_frequent_frequency,
|
||||
{name="Crickets_At_NightCombo", length=69, gain=night_frequent_volume}
|
||||
}
|
||||
|
||||
local day = {
|
||||
handler = {},
|
||||
frequency = day_frequency,
|
||||
{name="Best Cardinal Bird", length=4, gain=day_volume},
|
||||
{name="craw", length=3, gain=day_volume},
|
||||
{name="bluejay", length=18, gain=day_volume}
|
||||
}
|
||||
|
||||
local day_frequent = {
|
||||
handler = {},
|
||||
frequency = day_frequent_frequency,
|
||||
{name="robin2", length=43, gain=day_frequent_volume},
|
||||
{name="birdsongnl", length=72, gain=day_frequent_volume},
|
||||
{name="bird", length=30, gain=day_frequent_volume}--,
|
||||
-- {name="Best Cardinal Bird", length=4, gain=day_frequent_volume},
|
||||
-- {name="craw", length=3, gain=day_frequent_volume},
|
||||
-- {name="bluejay", length=18, gain=day_frequent_volume}
|
||||
}
|
||||
|
||||
local cave = {
|
||||
handler = {},
|
||||
frequency = cave_frequency,
|
||||
{name="Bats_in_Cave", length=5, gain=cave_volume}
|
||||
}
|
||||
|
||||
local cave_frequent = {
|
||||
handler = {},
|
||||
frequency = cave_frequent_frequency,
|
||||
{name="drippingwater_drip_a", length=2, gain=cave_frequent_volume},
|
||||
{name="drippingwater_drip_b", length=2, gain=cave_frequent_volume},
|
||||
{name="drippingwater_drip_c", length=2, gain=cave_frequent_volume},
|
||||
{name="Single_Water_Droplet", length=3, gain=cave_frequent_volume},
|
||||
{name="Spooky_Water_Drops", length=7, gain=cave_frequent_volume}
|
||||
}
|
||||
|
||||
local water = {
|
||||
handler = {},
|
||||
frequency = 0,--dolphins dont fit into small lakes
|
||||
{name="dolphins", length=6},
|
||||
{name="dolphins_screaming", length=16.5}
|
||||
}
|
||||
|
||||
local water_frequent = {
|
||||
handler = {},
|
||||
frequency = water_frequent_frequency,
|
||||
on_stop = "drowning_gasp",
|
||||
{name="scuba1bubbles", length=11, gain=water_frequent_volume},
|
||||
{name="scuba1calm", length=10, gain=water_frequent_volume},
|
||||
{name="scuba1calm2", length=8.5, gain=water_frequent_volume},
|
||||
{name="scuba1interestingbubbles", length=11, gain=water_frequent_volume},
|
||||
{name="scuba1tubulentbubbles", length=10.5, gain=water_frequent_volume}
|
||||
}
|
||||
|
||||
local play_music = minetest.setting_getbool("music") or false
|
||||
local music = {
|
||||
handler = {},
|
||||
frequency = music_frequency,
|
||||
{name="mtest", length=4*60+33, gain=music_volume}
|
||||
}
|
||||
|
||||
local is_daytime = function()
|
||||
return (minetest.env:get_timeofday() > 0.2 and minetest.env:get_timeofday() < 0.8)
|
||||
end
|
||||
|
||||
local get_ambience = function(player)
|
||||
local pos = player:getpos()
|
||||
pos.y = pos.y+1.5
|
||||
local nodename = minetest.env:get_node(pos).name
|
||||
if string.find(nodename, "default:water") then
|
||||
if music then
|
||||
return {water=water, water_frequent=water_frequent, music=music}
|
||||
else
|
||||
return {water=water, water_frequent=water_frequent}
|
||||
end
|
||||
end
|
||||
if player:getpos().y < 0 then
|
||||
if music then
|
||||
return {cave=cave, cave_frequent=cave_frequent, music=music}
|
||||
else
|
||||
return {cave=cave, cave_frequent=cave_frequent}
|
||||
end
|
||||
end
|
||||
if is_daytime() then
|
||||
if music then
|
||||
return {day=day, day_frequent=day_frequent, music=music}
|
||||
else
|
||||
return {day=day, day_frequent=day_frequent}
|
||||
end
|
||||
else
|
||||
if music then
|
||||
return {night=night, night_frequent=night_frequent, music=music}
|
||||
else
|
||||
return {night=night, night_frequent=night_frequent}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- start playing the sound, set the handler and delete the handler after sound is played
|
||||
local play_sound = function(player, list, number)
|
||||
local player_name = player:get_player_name()
|
||||
if list.handler[player_name] == nil then
|
||||
local gain = 1.0
|
||||
if list[number].gain ~= nil then
|
||||
gain = list[number].gain
|
||||
end
|
||||
local handler = minetest.sound_play(list[number].name, {to_player=player_name, gain=gain})
|
||||
if handler ~= nil then
|
||||
list.handler[player_name] = handler
|
||||
minetest.after(list[number].length, function(args)
|
||||
local list = args[1]
|
||||
local player_name = args[2]
|
||||
if list.handler[player_name] ~= nil then
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end, {list, player_name})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- stops all sounds that are not in still_playing
|
||||
local stop_sound = function(still_playing, player)
|
||||
local player_name = player:get_player_name()
|
||||
if still_playing.cave == nil then
|
||||
local list = cave
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.cave_frequent == nil then
|
||||
local list = cave_frequent
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.night == nil then
|
||||
local list = night
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.night_frequent == nil then
|
||||
local list = night_frequent
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.day == nil then
|
||||
local list = day
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.day_frequent == nil then
|
||||
local list = day_frequent
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.music == nil then
|
||||
local list = music
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.water == nil then
|
||||
local list = water
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.water_frequent == nil then
|
||||
local list = water_frequent
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer+dtime
|
||||
if timer < 1 then
|
||||
return
|
||||
end
|
||||
timer = 0
|
||||
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local ambiences = get_ambience(player)
|
||||
stop_sound(ambiences, player)
|
||||
for _,ambience in pairs(ambiences) do
|
||||
if math.random(1, 1000) <= ambience.frequency then
|
||||
play_sound(player, ambience, math.random(1, #ambience))
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
|
@ -1,40 +1,273 @@
|
|||
math.randomseed(3)
|
||||
sound_playing = 0
|
||||
--------------------------------------------------------------------------------------------------------
|
||||
--Ambiance Configuration for version .08
|
||||
|
||||
minetest.register_globalstep(function(time)
|
||||
local time = minetest.env:get_timeofday()
|
||||
-- minetest.chat_send_all(time .. " " .. sound_playing)
|
||||
local max_frequency_all = 1000 --the larger you make this number the lest frequent ALL sounds will happen recommended values between 100-2000.
|
||||
|
||||
if sound_playing == 0 then
|
||||
sound_playing = time
|
||||
--for frequencies below use a number between 0 and max_frequency_all
|
||||
--for volumes below, use a number between 0.0 and 1, the larger the number the louder the sounds
|
||||
local night_frequency = 20 --owls, wolves
|
||||
local night_volume = 0.9
|
||||
local night_frequent_frequency = 150 --crickets
|
||||
local night_frequent_volume = 0.9
|
||||
local day_frequency = 100 --crow, bluejay, cardinal
|
||||
local day_volume = 0.9
|
||||
local day_frequent_frequency = 1000 --crow, bluejay, cardinal
|
||||
local day_frequent_volume = 0.18
|
||||
local cave_frequency = 10 --bats
|
||||
local cave_volume = 1.0
|
||||
local cave_frequent_frequency = 70 --drops of water dripping
|
||||
local cave_frequent_volume = 1.0
|
||||
local water_frequent_frequency = 1000 --underwater sounds
|
||||
local water_frequent_volume = 1.0
|
||||
local music_frequency = 1 --music (suggestion: keep this one low like around 1)
|
||||
local music_volume = 0.3
|
||||
--End of Config
|
||||
----------------------------------------------------------------------------------------------------
|
||||
|
||||
local night = {
|
||||
handler = {},
|
||||
frequency = night_frequency,
|
||||
{name="horned_owl", length=3, gain=night_volume},
|
||||
{name="Wolves_Howling", length=11, gain=night_volume}
|
||||
}
|
||||
|
||||
local night_frequent = {
|
||||
handler = {},
|
||||
frequency = night_frequent_frequency,
|
||||
{name="Crickets_At_NightCombo", length=69, gain=night_frequent_volume}
|
||||
}
|
||||
|
||||
local day = {
|
||||
handler = {},
|
||||
frequency = day_frequency,
|
||||
{name="Best Cardinal Bird", length=4, gain=day_volume},
|
||||
{name="craw", length=3, gain=day_volume},
|
||||
{name="bluejay", length=18, gain=day_volume}
|
||||
}
|
||||
|
||||
local day_frequent = {
|
||||
handler = {},
|
||||
frequency = day_frequent_frequency,
|
||||
{name="robin2", length=16, gain=day_frequent_volume},
|
||||
{name="birdsongnl", length=13, gain=day_frequent_volume},
|
||||
{name="bird", length=30, gain=day_frequent_volume}--,
|
||||
-- {name="Best Cardinal Bird", length=4, gain=day_frequent_volume},
|
||||
-- {name="craw", length=3, gain=day_frequent_volume},
|
||||
-- {name="bluejay", length=18, gain=day_frequent_volume}
|
||||
}
|
||||
|
||||
|
||||
local cave = {
|
||||
handler = {},
|
||||
frequency = cave_frequency,
|
||||
{name="Bats_in_Cave", length=5, gain=cave_volume}
|
||||
}
|
||||
|
||||
local cave_frequent = {
|
||||
handler = {},
|
||||
frequency = cave_frequent_frequency,
|
||||
{name="drippingwater_drip_a", length=2, gain=cave_frequent_volume},
|
||||
{name="drippingwater_drip_b", length=2, gain=cave_frequent_volume},
|
||||
{name="drippingwater_drip_c", length=2, gain=cave_frequent_volume},
|
||||
{name="Single_Water_Droplet", length=3, gain=cave_frequent_volume},
|
||||
{name="Spooky_Water_Drops", length=7, gain=cave_frequent_volume}
|
||||
}
|
||||
|
||||
local water = {
|
||||
handler = {},
|
||||
frequency = 0,--dolphins dont fit into small lakes
|
||||
{name="dolphins", length=6},
|
||||
{name="dolphins_screaming", length=16.5}
|
||||
}
|
||||
|
||||
local water_frequent = {
|
||||
handler = {},
|
||||
frequency = water_frequent_frequency,
|
||||
on_stop = "drowning_gasp",
|
||||
{name="scuba1bubbles", length=11, gain=water_frequent_volume},
|
||||
{name="scuba1calm", length=10}, --not sure why but sometimes I get errors when setting gain=water_frequent_volume here.
|
||||
{name="scuba1calm2", length=8.5, gain=water_frequent_volume},
|
||||
{name="scuba1interestingbubbles", length=11, gain=water_frequent_volume},
|
||||
{name="scuba1tubulentbubbles", length=10.5, gain=water_frequent_volume}
|
||||
}
|
||||
|
||||
local play_music = minetest.setting_getbool("music") or false
|
||||
local music = {
|
||||
handler = {},
|
||||
frequency = music_frequency,
|
||||
{name="mtest", length=4*60+33, gain=music_volume}
|
||||
}
|
||||
|
||||
local is_daytime = function()
|
||||
return (minetest.env:get_timeofday() > 0.2 and minetest.env:get_timeofday() < 0.8)
|
||||
end
|
||||
|
||||
local get_ambience = function(player)
|
||||
local pos = player:getpos()
|
||||
pos.y = pos.y+1.5
|
||||
local nodename = minetest.env:get_node(pos).name
|
||||
if string.find(nodename, "default:water") then
|
||||
if music then
|
||||
return {water=water, water_frequent=water_frequent, music=music}
|
||||
else
|
||||
return {water=water, water_frequent=water_frequent}
|
||||
end
|
||||
|
||||
if sound_playing > 1 and time < 0.05 then
|
||||
sound_playing = 0.05
|
||||
end
|
||||
if player:getpos().y < 0 then
|
||||
if music then
|
||||
return {cave=cave, cave_frequent=cave_frequent, music=music}
|
||||
else
|
||||
return {cave=cave, cave_frequent=cave_frequent}
|
||||
end
|
||||
|
||||
--random wolves & owls at night
|
||||
if time > 0.8 or time < 0.2 then
|
||||
if math.random(10000) >9997 then
|
||||
minetest.sound_play("Wolves_Howling")
|
||||
end
|
||||
if math.random(10000) >9997 then
|
||||
minetest.sound_play("horned_owl")
|
||||
end
|
||||
end
|
||||
if time > sound_playing then
|
||||
|
||||
if time > 0.8 or time < 0.2 then
|
||||
sound_playing = time + 0.07
|
||||
minetest.sound_play("Crickets_At_NightCombo")
|
||||
|
||||
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
sound_playing = time + 0.1
|
||||
minetest.sound_play("bird")
|
||||
return true
|
||||
end
|
||||
if is_daytime() then
|
||||
if music then
|
||||
return {day=day, day_frequent=day_frequent, music=music}
|
||||
else
|
||||
return {day=day, day_frequent=day_frequent}
|
||||
end
|
||||
end)
|
||||
else
|
||||
if music then
|
||||
return {night=night, night_frequent=night_frequent, music=music}
|
||||
else
|
||||
return {night=night, night_frequent=night_frequent}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- start playing the sound, set the handler and delete the handler after sound is played
|
||||
local play_sound = function(player, list, number)
|
||||
local player_name = player:get_player_name()
|
||||
if list.handler[player_name] == nil then
|
||||
local gain = 1.0
|
||||
if list[number].gain ~= nil then
|
||||
gain = list[number].gain
|
||||
end
|
||||
local handler = minetest.sound_play(list[number].name, {to_player=player_name, gain=gain})
|
||||
if handler ~= nil then
|
||||
list.handler[player_name] = handler
|
||||
minetest.after(list[number].length, function(args)
|
||||
local list = args[1]
|
||||
local player_name = args[2]
|
||||
if list.handler[player_name] ~= nil then
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end, {list, player_name})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- stops all sounds that are not in still_playing
|
||||
local stop_sound = function(still_playing, player)
|
||||
local player_name = player:get_player_name()
|
||||
if still_playing.cave == nil then
|
||||
local list = cave
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.cave_frequent == nil then
|
||||
local list = cave_frequent
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.night == nil then
|
||||
local list = night
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.night_frequent == nil then
|
||||
local list = night_frequent
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.day == nil then
|
||||
local list = day
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.day_frequent == nil then
|
||||
local list = day_frequent
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.music == nil then
|
||||
local list = music
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.water == nil then
|
||||
local list = water
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.water_frequent == nil then
|
||||
local list = water_frequent
|
||||
if list.handler[player_name] ~= nil then
|
||||
if list.on_stop ~= nil then
|
||||
minetest.sound_play(list.on_stop, {to_player=player:get_player_name()})
|
||||
end
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer+dtime
|
||||
if timer < 1 then
|
||||
return
|
||||
end
|
||||
timer = 0
|
||||
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local ambiences = get_ambience(player)
|
||||
stop_sound(ambiences, player)
|
||||
for _,ambience in pairs(ambiences) do
|
||||
if math.random(1, 1000) <= ambience.frequency then
|
||||
play_sound(player, ambience, math.random(1, #ambience))
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
|
@ -0,0 +1,54 @@
|
|||
local night = {"Crickets_At_NightCombo", "horned_owl", "Wolves_Howling"}
|
||||
local day = {"bird"}
|
||||
local cave = {"Bats_in_Cave","drippingwater_drip.1","drippingwater_drip.2","drippingwater_drip.3", "Single_Water_Droplet", "Spooky_Water_Drops"}
|
||||
|
||||
math.randomseed(3)
|
||||
sound_playing = 0
|
||||
|
||||
minetest.register_globalstep(function(time)
|
||||
local time = minetest.env:get_timeofday()
|
||||
-- minetest.chat_send_all(time .. " " .. sound_playing)
|
||||
|
||||
if sound_playing == 0 then
|
||||
sound_playing = time
|
||||
end
|
||||
|
||||
if sound_playing > 1 and time < 0.05 then
|
||||
sound_playing = 0.05
|
||||
end
|
||||
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
if player:getpos().y < 0 then
|
||||
if math.random(10000) >9980 then
|
||||
minetest.sound_play(cave[math.random(1, #cave)], {to_player = player:get_player_name()})
|
||||
end
|
||||
else
|
||||
--random wolves & owls at night
|
||||
if time > 0.8 or time < 0.2 then
|
||||
if math.random(10000) >9997 then
|
||||
minetest.sound_play("Wolves_Howling")
|
||||
end
|
||||
if math.random(10000) >9997 then
|
||||
minetest.sound_play("horned_owl")
|
||||
end
|
||||
end
|
||||
|
||||
if time > sound_playing then
|
||||
if time > 0.8 or time < 0.2 then
|
||||
sound_playing = time + 0.07
|
||||
minetest.sound_play("Crickets_At_NightCombo")
|
||||
return true
|
||||
end
|
||||
sound_playing = time + 0.1
|
||||
minetest.sound_play("bird")
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end)
|
|
@ -0,0 +1,157 @@
|
|||
--PilzAdam, check out my post about creating a function to determine setting
|
||||
|
||||
local night = {
|
||||
handler = {},
|
||||
{name="horned_owl", length=3},
|
||||
{name="horned_owl", length=3},
|
||||
{name="horned_owl", length=3},
|
||||
{name="Wolves_Howling", length=11}
|
||||
}
|
||||
|
||||
local night_frequent = {
|
||||
handler = {},
|
||||
{name="Crickets_At_NightCombo", length=69}
|
||||
}
|
||||
|
||||
local day = {
|
||||
handler = {},
|
||||
{name="Best Cardinal Bird", length=4},
|
||||
{name="craw", length=3},
|
||||
{name="bluejay", length=18}
|
||||
}
|
||||
|
||||
local day_frequent = {
|
||||
handler = {},
|
||||
{name="robin2", length=43},
|
||||
{name="birdsongnl", length=72},
|
||||
{name="bird", length=30}
|
||||
}
|
||||
|
||||
local cave = {
|
||||
handler = {},
|
||||
{name="Bats_in_Cave", length=5}
|
||||
}
|
||||
|
||||
local cave_frequent = {
|
||||
handler = {},
|
||||
{name="drippingwater_dripa", length=2},
|
||||
{name="drippingwater_dripb", length=2},
|
||||
{name="drippingwater_dripc", length=2},
|
||||
{name="Single_Water_Droplet", length=3},
|
||||
{name="Spooky_Water_Drops", length=7}
|
||||
}
|
||||
|
||||
local is_daytime = function()
|
||||
local daytime
|
||||
if minetest.env:get_timeofday() < 0.2 or minetest.env:get_timeofday() > 0.8 then
|
||||
daytime = false
|
||||
else
|
||||
daytime = true
|
||||
end
|
||||
return daytime
|
||||
end
|
||||
|
||||
local setting = function (player_parm)
|
||||
local settinglist
|
||||
if player_parm:getpos().y < 0 then
|
||||
settinglist = {cave, cave_frequent}
|
||||
else
|
||||
if is_daytime then
|
||||
settinglist = {day, day_frequent}
|
||||
else
|
||||
settinglist = {night, night_frequent}
|
||||
end
|
||||
end
|
||||
return settinglist
|
||||
end
|
||||
|
||||
-- start playing the sound, set the handler and delete the handler after sound is played
|
||||
local play_sound = function(player, list, number)
|
||||
local player_name = player:get_player_name()
|
||||
if list.handler[player_name] == nil then
|
||||
local handler = minetest.sound_play(list[number].name, {to_player=player_name})
|
||||
if handler ~= nil then
|
||||
list.handler[player_name] = handler
|
||||
minetest.after(list[number].length, function(args)
|
||||
local list = args[1]
|
||||
local player_name = args[2]
|
||||
if list.handler[player_name] ~= nil then
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end, {list, player_name})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- stops all sounds that are not in still_playing
|
||||
local stop_sound = function(still_playing, player)
|
||||
local player_name = player:get_player_name()
|
||||
if still_playing.cave == nil then
|
||||
local list = cave
|
||||
if list.handler[player_name] ~= nil then
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.cave_frequent == nil then
|
||||
local list = cave_frequent
|
||||
if list.handler[player_name] ~= nil then
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.night == nil then
|
||||
local list = night
|
||||
if list.handler[player_name] ~= nil then
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.night_frequent == nil then
|
||||
local list = night_frequent
|
||||
if list.handler[player_name] ~= nil then
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.day == nil then
|
||||
local list = day
|
||||
if list.handler[player_name] ~= nil then
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
if still_playing.day_frequent == nil then
|
||||
local list = day_frequent
|
||||
if list.handler[player_name] ~= nil then
|
||||
minetest.sound_stop(list.handler[player_name])
|
||||
list.handler[player_name] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer+dtime
|
||||
if timer < 5 then
|
||||
return
|
||||
end
|
||||
timer = 0
|
||||
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
player_setting = setting(player)
|
||||
|
||||
-- normal sounds
|
||||
if math.random(1, 100) <= 5 then --this 5 is what I am trying to change based on setting
|
||||
stop_sound({player_setting}, player)--big problem here
|
||||
play_sound(player, player_setting[1], math.random(1, #player_setting[0]))
|
||||
end
|
||||
|
||||
-- frequent sounds
|
||||
if math.random(1, 100) <= 50 then
|
||||
stop_sound({player_setting}, player)--big problem here
|
||||
play_sound(player, player_setting[2], math.random(1, #player_setting[1]))
|
||||
end
|
||||
end
|
||||
)
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -3,4 +3,36 @@
|
|||
|
||||
--Medium Pack Of Wolves Howling, License: Public Domain | Recorded by fws.gov, http://soundbible.com/277-Medium-Pack-Of-Wolves-Howling.html
|
||||
|
||||
--Horned Owl Sound, License: Attribution 3.0 | Recorded by Mike Koenig , http://soundbible.com/1851-Horned-Owl.html
|
||||
--Horned Owl Sound, License: Attribution 3.0 | Recorded by Mike Koenig , http://soundbible.com/1851-Horned-Owl.html
|
||||
--Bats In Cave Sound, License: Attr-Noncommercial 3.0 | Recorded by Mike Koenig , http://soundbible.com/1939-Bats-In-Cave.html
|
||||
|
||||
--Spooky Water Drops Sound, License: Attribution 3.0 | Recorded by Mike Koenig, http://soundbible.com/380-Spooky-Water-Drops.html
|
||||
|
||||
|
||||
-- Single Water Droplet Sound, License: Attribution 3.0 | Recorded by Mike Koenig, http://soundbible.com/384-Single-Water-Droplet.html
|
||||
|
||||
--HollowWind, Black Boe, Creative Commons 0 License, http://www.freesound.org/people/Black%20Boe/sounds/22331/
|
||||
|
||||
--drippingwater*.ogg sounds: CC0, Dripping Water Mod, by kddekadenz, http://minetest.net/forum/viewtopic.php?id=1688
|
||||
|
||||
--best cardinal bird: License: Attribution 3.0 | Recorded by PsychoBird, http://soundbible.com/1515-Best-Cardinal-Bird.html
|
||||
|
||||
--birdsongnl: the Attribution License, HerbertBoland, http://www.freesound.org/people/HerbertBoland/sounds/28312/ (end)
|
||||
|
||||
--robin2: Attribution License, reinsamba, http://www.freesound.org/people/reinsamba/sounds/32479/ (end)
|
||||
|
||||
--Craw.WAV, Attribution License, inchadney, http://www.freesound.org/people/inchadney/sounds/52450/
|
||||
|
||||
--bluejay.wav, Creative Commons 0 License, UncleSigmund, http://www.freesound.org/people/UncleSigmund/sounds/42382/
|
||||
|
||||
--scuba1*.ogg- digifishmusic, Attribution License, http://www.freesound.org/people/digifishmusic/sounds/45521/
|
||||
|
||||
--Underwater Pool - Attribution 3.0 | Recorded by Mike Koenig, http://soundbible.com/1660-Underwater-Pool.html
|
||||
|
||||
--dolphin_screaming - Creative Commons 0 License, felix.blume, http://www.freesound.org/people/felix.blume/sounds/161691/
|
||||
|
||||
--dolphins - Attribution Noncommercial License, acclivity, http://www.freesound.org/people/acclivity/sounds/13691/
|
||||
|
||||
--natural night sounds in Boquete.wav, Attribution License, laurent, http://www.freesound.org/people/laurent/sounds/15851/
|
||||
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue