More functions in the sound playing algorithm
parent
d5f65c79e5
commit
fefe97e222
BIN
ambience.zip
BIN
ambience.zip
Binary file not shown.
|
@ -1,33 +1,153 @@
|
||||||
local night = {"Crickets_At_NightCombo", "horned_owl", "Wolves_Howling"}
|
local night = {
|
||||||
local day = {"bird"}
|
handler = {},
|
||||||
local cave = {}
|
{name="horned_owl", length=3},
|
||||||
|
{name="Wolves_Howling", length=11}
|
||||||
|
}
|
||||||
|
|
||||||
|
local night_frequent = {
|
||||||
|
handler = {},
|
||||||
|
{name="Crickets_At_NightCombo", length=69}
|
||||||
|
}
|
||||||
|
|
||||||
|
local day = {
|
||||||
|
handler = {},
|
||||||
|
{name="bird", length=30}
|
||||||
|
}
|
||||||
|
|
||||||
|
local day_frequent = {
|
||||||
|
handler = {},
|
||||||
|
{name="", length=0}
|
||||||
|
}
|
||||||
|
|
||||||
|
local cave = {
|
||||||
|
handler = {},
|
||||||
|
{name="Bats_in_Cave", length=5}
|
||||||
|
}
|
||||||
|
|
||||||
|
local cave_frequent = {
|
||||||
|
handler = {},
|
||||||
|
{name="dippingwater_drip", length=2},
|
||||||
|
{name="Single_Water_Droplet", length=3},
|
||||||
|
{name="Spooky_Water_Drops", length=7}
|
||||||
|
}
|
||||||
|
|
||||||
|
-- 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]
|
||||||
|
minetest.sound_stop(list.handler[player_name])
|
||||||
|
list.handler[player_name] = nil
|
||||||
|
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
|
local timer = 0
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
timer = timer+dtime
|
timer = timer+dtime
|
||||||
if timer < 10 then
|
if timer < 5 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
timer = 0
|
timer = 0
|
||||||
if math.random(1, 100) > 5 then
|
-- normal sounds
|
||||||
return
|
if math.random(1, 100) <= 5 then
|
||||||
end
|
if minetest.env:get_timeofday() < 0.2 or minetest.env:get_timeofday() > 0.8 then
|
||||||
if minetest.env:get_timeofday() < 0.2 or minetest.env:get_timeofday() > 0.8 then
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
if player:getpos().y < 0 then
|
||||||
if player:getpos().y < 0 then
|
stop_sound({cave=true, cave_frequent=true}, player)
|
||||||
--TODO uncommend this if cave sounds are added
|
play_sound(player, cave, math.random(1, #cave))
|
||||||
--minetest.sound_play(cave[math.random(1, #cave)], {to_player = player:get_player_name()})
|
else
|
||||||
else
|
stop_sound({night=true, night_frequent=true}, player)
|
||||||
minetest.sound_play(night[math.random(1, #night)], {to_player = player:get_player_name()})
|
play_sound(player, night, math.random(1, #night))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
|
if player:getpos().y < 0 then
|
||||||
|
stop_sound({cave=true, cave_frequent=true}, player)
|
||||||
|
play_sound(player, cave, math.random(1, #cave))
|
||||||
|
else
|
||||||
|
stop_sound({day=true, day_frequent=true}, player)
|
||||||
|
play_sound(player, day, math.random(1, #day))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
|
||||||
if player:getpos().y < 0 then
|
-- frequent sounds
|
||||||
--TODO uncommend this if cave sounds are added
|
if math.random(1, 100) <= 50 then
|
||||||
--minetest.sound_play(cave[math.random(1, #cave)], {to_player = player:get_player_name()})
|
if minetest.env:get_timeofday() < 0.2 or minetest.env:get_timeofday() > 0.8 then
|
||||||
else
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
minetest.sound_play(day[math.random(1, #day)], {to_player = player:get_player_name()})
|
if player:getpos().y < 0 then
|
||||||
|
stop_sound({cave=true, cave_frequent=true}, player)
|
||||||
|
play_sound(player, cave_frequent, math.random(1, #cave_frequent))
|
||||||
|
else
|
||||||
|
stop_sound({night=true, night_frequent=true}, player)
|
||||||
|
play_sound(player, night_frequent, math.random(1, #night_frequent))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
|
if player:getpos().y < 0 then
|
||||||
|
stop_sound({cave=true, cave_frequent=true}, player)
|
||||||
|
play_sound(player, cave_frequent, math.random(1, #cave_frequent))
|
||||||
|
else
|
||||||
|
stop_sound({day=true, day_frequent=true}, player)
|
||||||
|
play_sound(player, day_frequent, math.random(1, #day_frequent))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -3,4 +3,10 @@
|
||||||
|
|
||||||
--Medium Pack Of Wolves Howling, License: Public Domain | Recorded by fws.gov, http://soundbible.com/277-Medium-Pack-Of-Wolves-Howling.html
|
--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
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue