diff --git a/ambience.zip b/ambience.zip index b6fef1c..a62a636 100644 Binary files a/ambience.zip and b/ambience.zip differ diff --git a/ambience/init.lua b/ambience/init.lua index 4f25b85..df2bf4f 100644 --- a/ambience/init.lua +++ b/ambience/init.lua @@ -1,12 +1,12 @@ -------------------------------------------------------------------------------------------------------- ---Ambiance Configuration for version .29 ---working on Flying ---PROB: wind stops short even though it says we are still flying and don't hear the start sound. ---really BIG prob, it ruins water meaning you hear beach while treading water. (find out if still hear it in .28) because ---it is fairly rare in .29 ---need a separate onstart variable for flying? ---removing unneeded stuff. - +--Ambience Configuration for version .30 +--added music volume /mvol 0-3.3 music gain gets multiplied by this. +--added sound volume /mvol 0-1 sound gain gets multiplied by this. +--Working on: +--find out why wind stops while flying +--add an extra node near feet to handle treading water as a special case, and don't have to use node under feet. which gets + --invoked when staning on a ledge near water. +--reduce redundant code (stopplay and add ambience to list) local max_frequency_all = 1000 --the larger you make this number the lest frequent ALL sounds will happen recommended values between 100-2000. @@ -36,11 +36,20 @@ local desert_frequent_frequency = 700 --desertwind local desert_frequent_volume = 1.0 local swimming_frequent_frequency = 1000 --swimming splashes local swimming_frequent_volume = 1.0 +local water_surface_volume = 1.0 -- sloshing water +local lava_volume = 1.0 --lava +local flowing_water_volume = .4 --waterfall +local splashing_water_volume = 1 local music_frequency = 7 --music (suggestion: keep this one low like around 6) local music_volume = 0.3 + --End of Config ---------------------------------------------------------------------------------------------------- +local ambiences local counter=0--***************** +local SOUNDVOLUME = 1 +local MUSICVOLUME = 1 +local sound_vol = 1 local last_x_pos = 0 local last_y_pos = 0 local last_z_pos = 0 @@ -48,9 +57,11 @@ local node_under_feet local node_at_upper_body local node_at_lower_body local node_3_under_feet - local played_on_start = false + + + local night = { handler = {}, frequency = night_frequency, @@ -144,8 +155,8 @@ local flying = { local water = { handler = {}, frequency = 0,--dolphins dont fit into small lakes - {name="dolphins", length=6}, - {name="dolphins_screaming", length=16.5} + {name="dolphins", length=6, gain=1}, + {name="dolphins_screaming", length=16.5, gain=1} } local water_frequent = { @@ -154,7 +165,7 @@ local water_frequent = { on_stop = "drowning_gasp", --on_start = "Splash", {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="scuba1calm", length=10, gain=water_frequent_volume}, --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} @@ -165,35 +176,35 @@ local water_surface = { frequency = 1000, on_stop = "Splash", on_start = "Splash", - {name="lake_waves_2_calm", length=9.5}, - {name="lake_waves_2_variety", length=13.1} + {name="lake_waves_2_calm", length=9.5, gain=water_surface_volume}, + {name="lake_waves_2_variety", length=13.1, gain=water_surface_volume} } local splashing_water = { handler = {}, frequency = 1000, - {name="Splash", length=1.22, gain=1} + {name="Splash", length=1.22, gain=splashing_water_volume} } local flowing_water = { handler = {}, frequency = 1000, - {name="small_waterfall", length=14, gain=.4} + {name="small_waterfall", length=14, gain=flowing_water_volume} } local flowing_water2 = { handler = {}, frequency = 1000, - {name="small_waterfall", length=11, gain=.3} + {name="small_waterfall", length=11, gain=flowing_water_volume} } local lava = { handler = {}, frequency = 1000, - {name="earth01a", length=20} + {name="earth01a", length=20, gain=lava_volume} } local lava2 = { handler = {}, frequency = 1000, - {name="earth01a", length=15} + {name="earth01a", length=15, gain=lava_volume} } @@ -201,6 +212,7 @@ local play_music = minetest.setting_getbool("music") or false local music = { handler = {}, frequency = music_frequency, + is_music=true, {name="mtest", length=4*60+33, gain=music_volume}, {name="echos", length=2*60+26, gain=music_volume}, {name="FoamOfTheSea", length=1*60+50, gain=music_volume}, @@ -455,12 +467,18 @@ local get_ambience = function(player) end -- start playing the sound, set the handler and delete the handler after sound is played -local play_sound = function(player, list, number) +local play_sound = function(player, list, number, is_music) 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 + if is_music then + gain = list[number].gain*MUSICVOLUME + --minetest.chat_send_all("gain music: " .. gain ) + else + gain = list[number].gain*SOUNDVOLUME + --minetest.chat_send_all("gain sound: " .. gain ) + end end local handler = minetest.sound_play(list[number].name, {to_player=player_name, gain=gain}) if handler ~= nil then @@ -484,7 +502,7 @@ local stop_sound = function(still_playing, player) 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -494,7 +512,7 @@ local stop_sound = function(still_playing, player) 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -504,7 +522,7 @@ local stop_sound = function(still_playing, player) local list = swimming_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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -514,7 +532,7 @@ local stop_sound = function(still_playing, player) local list = beach 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -524,7 +542,7 @@ local stop_sound = function(still_playing, player) local list = beach_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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -534,7 +552,7 @@ local stop_sound = function(still_playing, player) local list = desert 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -544,7 +562,7 @@ local stop_sound = function(still_playing, player) local list = desert_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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -554,7 +572,7 @@ local stop_sound = function(still_playing, player) 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -564,7 +582,7 @@ local stop_sound = function(still_playing, player) 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -574,7 +592,7 @@ local stop_sound = function(still_playing, player) 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -584,7 +602,7 @@ local stop_sound = function(still_playing, player) 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -594,7 +612,7 @@ local stop_sound = function(still_playing, player) 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -604,7 +622,7 @@ local stop_sound = function(still_playing, player) local list = flowing_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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -614,7 +632,7 @@ local stop_sound = function(still_playing, player) local list = flowing_water2 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -624,7 +642,7 @@ local stop_sound = function(still_playing, player) local list = lava 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -634,7 +652,7 @@ local stop_sound = function(still_playing, player) local list = lava2 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -644,7 +662,7 @@ local stop_sound = function(still_playing, player) 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -654,7 +672,7 @@ local stop_sound = function(still_playing, player) local list = water_surface 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) played_on_start = false end minetest.sound_stop(list.handler[player_name]) @@ -665,7 +683,7 @@ local stop_sound = function(still_playing, player) 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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) -- minetest.chat_send_all("list.on_stop " .. list.on_stop ) played_on_start = false end @@ -680,7 +698,7 @@ local stop_sound = function(still_playing, player) -- minetest.chat_send_all("handler flying " ) if list.on_stop ~= nil then -- minetest.chat_send_all("onstop flying" ) - minetest.sound_play(list.on_stop, {to_player=player:get_player_name()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) played_on_start = false end minetest.sound_stop(list.handler[player_name]) @@ -691,7 +709,7 @@ local stop_sound = function(still_playing, player) local list = splashing_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()}) + minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end minetest.sound_stop(list.handler[player_name]) list.handler[player_name] = nil @@ -709,7 +727,7 @@ minetest.register_globalstep(function(dtime) timer = 0 for _,player in ipairs(minetest.get_connected_players()) do - local ambiences = get_ambience(player) + ambiences = get_ambience(player) stop_sound(ambiences, player) for _,ambience in pairs(ambiences) do if math.random(1, 1000) <= ambience.frequency then @@ -720,15 +738,42 @@ minetest.register_globalstep(function(dtime) -- end if ambience.on_start ~= nil and played_on_start == false then played_on_start = true - minetest.sound_play(ambience.on_start, {to_player=player:get_player_name()}) + minetest.sound_play(ambience.on_start, {to_player=player:get_player_name(),gain=SOUNDVOLUME}) end -- minetest.chat_send_all("ambience: " ..ambience ) -- if ambience.on_start ~= nil and played_on_start_flying == false then -- played_on_start_flying = true -- minetest.sound_play(ambience.on_start, {to_player=player:get_player_name()}) -- end - play_sound(player, ambience, math.random(1, #ambience)) + local is_music =false + if ambience.is_music ~= nil then + is_music = true + end + play_sound(player, ambience, math.random(1, #ambience),is_music) end end end -end) \ No newline at end of file +end) + +minetest.register_chatcommand("svol", { + params = "", + description = "set volume of sounds, default 1 normal volume.", + privs = {server=true}, + func = function(name, param) + SOUNDVOLUME = param + -- local player = minetest.env:get_player_by_name(name) + -- ambiences = get_ambience(player) + -- stop_sound({}, player) + minetest.chat_send_player(name, "Sound volume set.") + end, }) +minetest.register_chatcommand("mvol", { + params = "", + description = "set volume of music, default 1 normal volume.", + privs = {server=true}, + func = function(name, param) + MUSICVOLUME = param + -- local player = minetest.env:get_player_by_name(name) + -- stop_sound({}, player) + -- ambiences = get_ambience(player) + minetest.chat_send_player(name, "Music volume set.") + end, }) \ No newline at end of file