.07 music, water gasp! shortened bird songs

This commit is contained in:
Neuromancer 2012-08-20 07:58:20 -05:00
parent 9ff5ed516b
commit e54251ec80
10 changed files with 150 additions and 87 deletions

Binary file not shown.

View File

@ -1,18 +1,19 @@
local night = {
handler = {},
{name="horned_owl", length=3},
{name="horned_owl", length=3},
frequency = 10,
{name="horned_owl", length=3},
{name="Wolves_Howling", length=11}
}
local night_frequent = {
handler = {},
frequency = 25,
{name="Crickets_At_NightCombo", length=69}
}
local day = {
handler = {},
frequency = 5,
{name="Best Cardinal Bird", length=4},
{name="craw", length=3},
{name="bluejay", length=18}
@ -20,6 +21,7 @@ local day = {
local day_frequent = {
handler = {},
frequency = 25,
{name="robin2", length=43},
{name="birdsongnl", length=72},
{name="bird", length=30}
@ -27,23 +29,91 @@ local day_frequent = {
local cave = {
handler = {},
frequency = 5,
{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},
frequency = 100,
{name="drippingwater_drip_a", length=2},
{name="drippingwater_drip_b", length=2},
{name="drippingwater_drip_c", length=2},
{name="Single_Water_Droplet", length=3},
{name="Spooky_Water_Drops", length=7}
}
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 = 100,
on_stop = "drowning_gasp",
{name="scuba1bubbles", length=11},
{name="scuba1calm", length=10},
{name="scuba1calm2", length=8.5},
{name="scuba1interestingbubbles", length=11},
{name="scuba1tubulentbubbles", length=10.5}
}
local play_music = minetest.setting_getbool("music") or false
local music = {
handler = {},
frequency = 1,
{name="mtest", length=4*60+33, gain=0.3}
}
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 handler = minetest.sound_play(list[number].name, {to_player=player_name})
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)
@ -64,6 +134,9 @@ local stop_sound = function(still_playing, player)
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
@ -71,6 +144,9 @@ local stop_sound = function(still_playing, player)
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
@ -78,6 +154,9 @@ local stop_sound = function(still_playing, player)
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
@ -85,6 +164,9 @@ local stop_sound = function(still_playing, player)
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
@ -92,6 +174,9 @@ local stop_sound = function(still_playing, player)
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
@ -99,6 +184,39 @@ local stop_sound = function(still_playing, player)
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
@ -108,56 +226,17 @@ end
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer+dtime
if timer < 5 then
if timer < 1 then
return
end
timer = 0
-- normal sounds
if math.random(1, 100) <= 5 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
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({night=true, night_frequent=true}, player)
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
-- frequent sounds
if math.random(1, 100) <= 50 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
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
local ambiences = get_ambience(player)
stop_sound(ambiences, player)
for _,ambience in pairs(ambiences) do
if math.random(1, 100) <= ambience.frequency then
play_sound(player, ambience, math.random(1, #ambience))
end
end
end

View File

@ -44,9 +44,9 @@ local cave_frequent = {
local is_daytime = function()
local daytime
if minetest.env:get_timeofday() < 0.2 or minetest.env:get_timeofday() > 0.8 then
daytime = true
else
daytime = false
else
daytime = true
end
return daytime
end
@ -54,31 +54,17 @@ end
local setting = function (player_parm)
local settinglist
if player_parm:getpos().y < 0 then
settinglist = cave
settinglist = {cave, cave_frequent}
else
if is_daytime then
settinglist = day
settinglist = {day, day_frequent}
else
settinglist = night
settinglist = {night, night_frequent}
end
end
return settinglist
end
local setting_frequent = function (setting_parm)
local setting_frequent_list
if setting_parm == cave then
setting_frequent_list = cave_frequent
elseif setting_parm == day then
setting_frequent_list = day_frequent
else
setting_frequent_list = night_frequent
end
return setting_frequent_list
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()
@ -153,21 +139,19 @@ minetest.register_globalstep(function(dtime)
end
timer = 0
-- normal sounds
if math.random(1, 100) <= 5 then --this 5 is what I am trying to change based on setting
for _,player in ipairs(minetest.get_connected_players()) do
player_setting = setting(player)
stop_sound({cave=true, cave_frequent=true}, player)--big problem here
play_sound(player, player_setting, math.random(1, #player_setting))
end
-- 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
for _,player in ipairs(minetest.get_connected_players()) do
player_setting_frequent = setting_frequent(player)
stop_sound({cave=true, cave_frequent=true}, player)--big problem here
play_sound(player, player_setting_frequent, math.random(1, #player_setting_frequent))
stop_sound({player_setting}, player)--big problem here
play_sound(player, player_setting[2], math.random(1, #player_setting[1]))
end
end
end)
)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
ambience/sounds/mtest.ogg Normal file

Binary file not shown.

Binary file not shown.