1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-06-28 06:11:47 +02:00

add serialise and deserialise and default volume set to 50

add serialise and deserialise
set default volume to 50
change variable name "musique" to "music"
This commit is contained in:
2015-02-19 20:33:59 +01:00
parent b165c5512f
commit 3d599fc0d1
3 changed files with 68 additions and 68 deletions

View File

@ -2,32 +2,32 @@ minetest.log("action","[mod soundset] Loading...")
sounds = {}
sounds.file = minetest.get_worldpath() .. "/sounds_config.txt"
sounds.gaindefault = { ["musique"] = 100, ["ambience"] = 100, ["mobs"] = 100, ["other"] = 100 }
sounds.gaindefault = { ["music"] = 50, ["ambience"] = 50, ["mobs"] = 50, ["other"] = 50 }
sounds.gainplayers = {}
sounds.set_sound = function(name, param)
if param == "" then
minetest.chat_send_player(name, "/setsound <musique|ambience|mobs|other> <number>")
minetest.chat_send_player(name, "/setsound <music|ambience|mobs|other> <number>")
return
end
local param_name, param_value = param:match("^(%S+)%s(%S+)$")
if param_name == nil or param_value == nil then
minetest.chat_send_player(name, "invalid param, /setsound <musique|ambience|mobs|other> <number>")
minetest.log("action", "invalid param, see /setsound <musique|ambience|mobs|other> <number>")
minetest.chat_send_player(name, "invalid param, /setsound <music|ambience|mobs|other> <number>")
minetest.log("action", "invalid param, see /setsound <music|ambience|mobs|other> <number>")
return
end
if param_name ~= "musique" and param_name ~= "ambience" and param_name ~= "mobs" and param_name ~= "other" then
if param_name ~= "music" and param_name ~= "ambience" and param_name ~= "mobs" and param_name ~= "other" then
minetest.chat_send_player(name, "invalid param " .. param_name)
minetest.log("action", "invalid param, /setsound " .. param_name)
return
end
end
local value = tonumber(param_value)
if value == nil then
minetest.log("action", "invalid value, " ..param_value .. " must be number")
return
end
end
if value < 0 then
value = 0
@ -44,39 +44,39 @@ sounds.set_sound = function(name, param)
sounds.gainplayers[name][param_name] = value
minetest.chat_send_player(name, "sound " .. param_name .. " set to " .. value)
minetest.log("action", name ..", sound " .. param_name .. " set to " .. value)
local output = io.open(sounds.file, "w")
for i, v in pairs(sounds.gainplayers) do
output:write(v.musique .. " " .. v.ambience .. " " .. v.mobs .. " " .. v.other .. " " .. i .."\n")
end
io.close(output)
local input = io.open(sounds.file, "w")
if input then
input:write(minetest.serialize(sounds.gainplayers))
input:close()
else
minetest.log("action","echec d'ouverture (mode:w) de " .. sounds.file)
end
end
sounds.get_gain = function(name, sound_type)
return sounds.gainplayers[name][sound_type]/50
if name == nil or name == "" then
return 1
end
local gain = sounds.gainplayers[name][sound_type]
if gain == nil then
return 1
end
return gain/50
end
local function load_sounds_config()
local input = io.open(sounds.file, "r")
if input then
repeat
local musique = input:read("*n")
if musique == nil then
break
end
local ambience = input:read("*n")
local mobs = input:read("*n")
local other = input:read("*n")
local name = input:read("*l")
sounds.gainplayers[name:sub(2)] = {musique = musique, ambience = ambience, mobs = mobs, other = other}
until input:read(0) == nil
io.close(input)
local file = io.open(sounds.file, "r")
if file then
sounds.gainplayers = minetest.deserialize(file:read("*all"))
file:close()
end
if sounds.gainplayers == nil then
sounds.gainplayers = {}
end
end
@ -84,24 +84,24 @@ end
load_sounds_config()
minetest.register_chatcommand("setsound", {
params = "",
description = "set volume sound <musique|ambience|mobs|other>",
privs = {},
func = sounds.set_sound,
params = "<music|ambience|mobs|other> <number>",
description = "set volume sound <music|ambience|mobs|other>",
privs = {},
func = sounds.set_sound,
})
minetest.register_chatcommand("getsound", {
params = "",
description = "print volume sound <musique|ambience|mobs|other>",
privs = {},
func = function(name, param)
local conf = ""
for k, v in pairs(sounds.gainplayers[name]) do
conf = conf .. " " .. k .. ":" .. v
end
params = "",
description = "print volume sound <music|ambience|mobs|other>",
privs = {},
func = function(name, param)
local conf = ""
for k, v in pairs(sounds.gainplayers[name]) do
conf = conf .. " " .. k .. ":" .. v
end
minetest.chat_send_player(name, "sounds conf " .. conf)
minetest.log("action","Player ".. name .. " sound conf " .. conf)
end
end
})
minetest.register_on_joinplayer(function(player)

View File

@ -1,5 +1,5 @@
-= soundset-MOD for MINETEST =-
by Mg and crabman77
by LeMagnesium and crabman77
YOUR mod can use THIS mod to have a volume that's adjustable by the player(s)