2015-02-14 23:55:06 +01:00
|
|
|
minetest.log("action","[mod soundset] Loading...")
|
|
|
|
|
|
|
|
sounds = {}
|
|
|
|
sounds.file = minetest.get_worldpath() .. "/sounds_config.txt"
|
|
|
|
sounds.gainplayers = {}
|
|
|
|
|
|
|
|
|
|
|
|
sounds.set_sound = function(name, param)
|
|
|
|
if param == "" then
|
2015-02-19 20:33:59 +01:00
|
|
|
minetest.chat_send_player(name, "/setsound <music|ambience|mobs|other> <number>")
|
2015-02-14 23:55:06 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local param_name, param_value = param:match("^(%S+)%s(%S+)$")
|
|
|
|
if param_name == nil or param_value == nil then
|
2015-02-19 20:33:59 +01:00
|
|
|
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>")
|
2015-02-14 23:55:06 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-02-19 20:33:59 +01:00
|
|
|
if param_name ~= "music" and param_name ~= "ambience" and param_name ~= "mobs" and param_name ~= "other" then
|
2015-02-14 23:55:06 +01:00
|
|
|
minetest.chat_send_player(name, "invalid param " .. param_name)
|
|
|
|
minetest.log("action", "invalid param, /setsound " .. param_name)
|
|
|
|
return
|
2015-02-19 20:33:59 +01:00
|
|
|
end
|
2015-02-14 23:55:06 +01:00
|
|
|
local value = tonumber(param_value)
|
|
|
|
if value == nil then
|
|
|
|
minetest.log("action", "invalid value, " ..param_value .. " must be number")
|
|
|
|
return
|
2015-02-19 20:33:59 +01:00
|
|
|
end
|
2015-02-14 23:55:06 +01:00
|
|
|
|
|
|
|
if value < 0 then
|
|
|
|
value = 0
|
|
|
|
elseif value > 100 then
|
|
|
|
value = 100
|
|
|
|
end
|
|
|
|
|
|
|
|
if sounds.gainplayers[name][param_name] == value then
|
2015-02-20 13:42:01 +01:00
|
|
|
minetest.chat_send_player(name, "volume " .. param_name .. " already set to " .. value)
|
|
|
|
minetest.log("action", name ..", volume " .. param_name .. " already set to " .. value)
|
2015-02-14 23:55:06 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2015-02-19 20:33:59 +01:00
|
|
|
|
|
|
|
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
|
2015-02-14 23:55:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
sounds.get_gain = function(name, sound_type)
|
2015-02-19 20:33:59 +01:00
|
|
|
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
|
2015-02-14 23:55:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-02-19 20:33:59 +01:00
|
|
|
|
2015-02-14 23:55:06 +01:00
|
|
|
local function load_sounds_config()
|
2015-02-19 20:33:59 +01:00
|
|
|
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 = {}
|
2015-02-14 23:55:06 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
load_sounds_config()
|
|
|
|
|
|
|
|
minetest.register_chatcommand("setsound", {
|
2015-02-19 20:33:59 +01:00
|
|
|
params = "<music|ambience|mobs|other> <number>",
|
|
|
|
description = "set volume sound <music|ambience|mobs|other>",
|
2015-03-15 15:54:49 +01:00
|
|
|
privs = {interact=true},
|
2015-02-19 20:33:59 +01:00
|
|
|
func = sounds.set_sound,
|
2015-02-14 23:55:06 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("getsound", {
|
2015-02-19 20:33:59 +01:00
|
|
|
params = "",
|
|
|
|
description = "print volume sound <music|ambience|mobs|other>",
|
2015-03-15 15:54:49 +01:00
|
|
|
privs = {interact=true},
|
2015-02-19 20:33:59 +01:00
|
|
|
func = function(name, param)
|
|
|
|
local conf = ""
|
|
|
|
for k, v in pairs(sounds.gainplayers[name]) do
|
|
|
|
conf = conf .. " " .. k .. ":" .. v
|
|
|
|
end
|
2015-02-14 23:55:06 +01:00
|
|
|
minetest.chat_send_player(name, "sounds conf " .. conf)
|
|
|
|
minetest.log("action","Player ".. name .. " sound conf " .. conf)
|
2015-02-19 20:33:59 +01:00
|
|
|
end
|
2015-02-14 23:55:06 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
|
|
|
if sounds.gainplayers[name] == nil then
|
2015-02-20 13:42:01 +01:00
|
|
|
sounds.gainplayers[name] = { ["music"] = 50, ["ambience"] = 50, ["mobs"] = 50, ["other"] = 50 }
|
2015-02-14 23:55:06 +01:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
minetest.log("action","[mod soundset] Loaded")
|
|
|
|
|