1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-16 23:40:31 +01:00

update soundset (calcul gain berore returning value)

update mod use soundset
This commit is contained in:
crabman77 2015-06-20 20:58:56 +02:00
parent 986ee7e7ad
commit 5cb1581e77
6 changed files with 89 additions and 76 deletions

View File

@ -521,7 +521,7 @@ local stop_sound = function(still_playing, player)
local list = cave local list = cave
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -531,7 +531,7 @@ local stop_sound = function(still_playing, player)
local list = cave_frequent local list = cave_frequent
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -541,7 +541,7 @@ local stop_sound = function(still_playing, player)
local list = swimming_frequent local list = swimming_frequent
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -551,7 +551,7 @@ local stop_sound = function(still_playing, player)
local list = beach local list = beach
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -561,7 +561,7 @@ local stop_sound = function(still_playing, player)
local list = beach_frequent local list = beach_frequent
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -571,7 +571,7 @@ local stop_sound = function(still_playing, player)
local list = desert local list = desert
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -581,7 +581,7 @@ local stop_sound = function(still_playing, player)
local list = desert_frequent local list = desert_frequent
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -591,7 +591,7 @@ local stop_sound = function(still_playing, player)
local list = night local list = night
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -601,7 +601,7 @@ local stop_sound = function(still_playing, player)
local list = night_frequent local list = night_frequent
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -611,7 +611,7 @@ local stop_sound = function(still_playing, player)
local list = day local list = day
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -621,7 +621,7 @@ local stop_sound = function(still_playing, player)
local list = day_frequent local list = day_frequent
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -631,7 +631,7 @@ local stop_sound = function(still_playing, player)
local list = music local list = music
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -641,7 +641,7 @@ local stop_sound = function(still_playing, player)
local list = flowing_water local list = flowing_water
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -651,7 +651,7 @@ local stop_sound = function(still_playing, player)
local list = flowing_water2 local list = flowing_water2
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -661,7 +661,7 @@ local stop_sound = function(still_playing, player)
local list = lava local list = lava
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -671,7 +671,7 @@ local stop_sound = function(still_playing, player)
local list = lava2 local list = lava2
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -681,7 +681,7 @@ local stop_sound = function(still_playing, player)
local list = water local list = water
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -691,7 +691,7 @@ local stop_sound = function(still_playing, player)
local list = water_surface local list = water_surface
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
played_on_start = false played_on_start = false
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
@ -702,7 +702,7 @@ local stop_sound = function(still_playing, player)
local list = water_frequent local list = water_frequent
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
-- minetest.chat_send_all("list.on_stop " .. list.on_stop ) -- minetest.chat_send_all("list.on_stop " .. list.on_stop )
played_on_start = false played_on_start = false
end end
@ -717,7 +717,7 @@ local stop_sound = function(still_playing, player)
-- minetest.chat_send_all("handler flying " ) -- minetest.chat_send_all("handler flying " )
if list.on_stop ~= nil then if list.on_stop ~= nil then
-- minetest.chat_send_all("onstop flying" ) -- minetest.chat_send_all("onstop flying" )
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
played_on_start = false played_on_start = false
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
@ -728,7 +728,7 @@ local stop_sound = function(still_playing, player)
local list = splashing_water local list = splashing_water
if list.handler[player_name] ~= nil then if list.handler[player_name] ~= nil then
if list.on_stop ~= nil then if list.on_stop ~= nil then
minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player_name, "ambience")}) minetest.sound_play(list.on_stop, {to_player=player:get_player_name(),gain=soundset.get_gain(player_name, "ambience")})
end end
minetest.sound_stop(list.handler[player_name]) minetest.sound_stop(list.handler[player_name])
list.handler[player_name] = nil list.handler[player_name] = nil
@ -757,7 +757,7 @@ minetest.register_globalstep(function(dtime)
-- end -- end
if ambience.on_start ~= nil and played_on_start == false then if ambience.on_start ~= nil and played_on_start == false then
played_on_start = true played_on_start = true
minetest.sound_play(ambience.on_start, {to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player:get_player_name(), "ambience")}) minetest.sound_play(ambience.on_start, {to_player=player:get_player_name(),gain=soundset.get_gain(player:get_player_name(), "ambience")})
end end
-- minetest.chat_send_all("ambience: " ..ambience ) -- minetest.chat_send_all("ambience: " ..ambience )
-- if ambience.on_start ~= nil and played_on_start_flying == false then -- if ambience.on_start ~= nil and played_on_start_flying == false then

View File

@ -310,7 +310,7 @@ function awards.give_achievement(name, award)
-- save playertable -- save playertable
awards.save() awards.save()
minetest.sound_play("award_award_won", {to_player = name, gain = 0.5*soundset.get_gain(name,"other")}) minetest.sound_play("award_award_won", {to_player = name, gain = soundset.get_gain(name,"other")})
end end
end end

View File

@ -82,7 +82,7 @@ local function sound_play_all(dead)
for _, p in ipairs(minetest.get_connected_players()) do for _, p in ipairs(minetest.get_connected_players()) do
local player_name = p:get_player_name() local player_name = p:get_player_name()
if player_name and player_name ~= dead then if player_name and player_name ~= dead then
minetest.sound_play("death_messages_people_1",{to_player=player_name, gain=0.5*soundset.get_gain(player_name,"other")}) minetest.sound_play("death_messages_people_1",{to_player=player_name, gain=soundset.get_gain(player_name,"other")})
end end
end end
end end
@ -121,7 +121,7 @@ if RANDOM_MESSAGES == true then
minetest.chat_send_all(death_message) minetest.chat_send_all(death_message)
irc:say(death_message) irc:say(death_message)
minetest.sound_play(sounds[math.random(1,#sounds)],{to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player:get_player_name(),"other")}) minetest.sound_play(sounds[math.random(1,#sounds)],{to_player=player:get_player_name(),gain=soundset.get_gain(player:get_player_name(),"other")})
sound_play_all(player:get_player_name()) sound_play_all(player:get_player_name())
end) end)
@ -145,7 +145,7 @@ else
else else
minetest.chat_send_all(player_name .. " died.") minetest.chat_send_all(player_name .. " died.")
end end
minetest.sound_play(sounds[math.random(1,#sounds)],{to_player=player:get_player_name(),gain=0.5*soundset.get_gain(player:get_player_name(),"other")}) minetest.sound_play(sounds[math.random(1,#sounds)],{to_player=player:get_player_name(),gain=soundset.get_gain(player:get_player_name(),"other")})
sound_play_all(player:get_player_name()) sound_play_all(player:get_player_name())
end) end)
end end

39
mods/soundset/README.md Normal file
View File

@ -0,0 +1,39 @@
soundset MOD for MINETEST
========================
by Mg (@LeMagnesium) and @crabman77
YOUR mod can use THIS mod to have a volume that's adjustable by the player(s)
EXEMPLE
minetest.sound_play("music_file", {to_player=player:get_player_name(),gain=sounds.get_gain(player:get_player_name(), "music")})
OR
minetest.sound_play("mob_sound", {to_player=player:get_player_name(),gain=sounds.get_gain(player:get_player_name(), "mobs")})
OR
minetest.sound_play("wind_sound", {to_player=player:get_player_name(),gain=sounds.get_gain(player:get_player_name(), "ambience")})
commandchat
/soundset : display menu
/soundsetg : display player config
/soundsets <music|ambience|mobs|other> <number> : set volume
Licenses images: Author:mikhog http://opengameart.org/content/play-pause-mute-and-unmute-buttons CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
0.1 - Initial Release
0.2 - change default volume to 50, add serialise|deserialise to read|write config file
0.3 - add menu setting and button for unified_inventory and chatcommand to display menu

63
mods/soundset/init.lua Executable file → Normal file
View File

@ -76,13 +76,29 @@ soundset.get_gain = function(name, sound_type)
if gain == nil then if gain == nil then
return 1 return 1
end end
return gain/50 return gain/100
end
local inc = function(value)
value = value + 5
if value > 100 then
value = 100
end
return value
end
local dec = function(value)
value = value - 5
if value < 0 then
value = 0
end
return value
end end
local formspec = "size[6,6]".. local formspec = "size[6,6]"..
"label[2,0;Sound Menu]".. "label[2,0;Sound Menu]"..
"label[0.3,1.2;MUSIC]".. "label[0,1.2;MUSIC]"..
"image_button[1.6,1;1,1;soundset_dec.png;vmusic;-]".. "image_button[1.6,1;1,1;soundset_dec.png;vmusic;-]"..
"label[2.7,1.2;%s]".. "label[2.7,1.2;%s]"..
"image_button[3.5,1;1,1;soundset_inc.png;vmusic;+]".. "image_button[3.5,1;1,1;soundset_inc.png;vmusic;+]"..
@ -129,47 +145,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
soundset.tmp[name] = nil soundset.tmp[name] = nil
return return
elseif fields["vmusic"] == "+" then elseif fields["vmusic"] == "+" then
if fmusic < 100 then fmusic = inc(fmusic)
fmusic = fmusic +5
if fmusic > 100 then
fmusic = 100
end
end
elseif fields["vmusic"] == "-" then elseif fields["vmusic"] == "-" then
if fmusic > 0 then fmusic = dec(fmusic)
fmusic = fmusic -5
if fmusic < 0 then
fmusic = 0
end
end
elseif fields["vambience"] == "+" then elseif fields["vambience"] == "+" then
if fambience < 100 then fambience = inc(fambience)
fambience = fambience +5
if fambience > 100 then
fambience = 100
end
end
elseif fields["vambience"] == "-" then elseif fields["vambience"] == "-" then
if fambience > 0 then fambience = dec(fambience)
fambience = fambience -5
if fambience < 0 then
fambience = 0
end
end
elseif fields["vother"] == "+" then elseif fields["vother"] == "+" then
if fother < 100 then fother = inc(fother)
fother = fother +5
if fother > 100 then
fother = 100
end
end
elseif fields["vother"] == "-" then elseif fields["vother"] == "-" then
if fother > 0 then fother = dec(fother)
fother = fother -5
if fother < 0 then
fother = 0
end
end
elseif fields["quit"] == "true" then elseif fields["quit"] == "true" then
soundset.tmp[name] = nil soundset.tmp[name] = nil
return return
@ -206,7 +192,6 @@ minetest.register_chatcommand("soundset", {
}) })
minetest.register_chatcommand("soundsets", { minetest.register_chatcommand("soundsets", {
params = "<music|ambience|mobs|other> <number>", params = "<music|ambience|mobs|other> <number>",
description = "Set volume sound <music|ambience|mobs|other>", description = "Set volume sound <music|ambience|mobs|other>",

View File

@ -1,11 +0,0 @@
-= soundset-MOD for MINETEST =-
by LeMagnesium and crabman77
YOUR mod can use THIS mod to have a volume that's adjustable by the player(s)
0.1 - Initial Release
0.2 - add menu setting and button for unified_inventory and chatcommand to display menu
Licenses images: Author:mikhog http://opengameart.org/content/play-pause-mute-and-unmute-buttons CC0 1.0 Universal (CC0 1.0) Public Domain Dedication