From 9a0acb22c0a3049ac89369891f4fd8e23d69c904 Mon Sep 17 00:00:00 2001 From: crabman77 Date: Sat, 14 Feb 2015 23:55:06 +0100 Subject: [PATCH] mod soundset initial release --- mods/soundset/init.lua | 114 +++++++++++++++++++++++++++++++++++++++ mods/soundset/readme.txt | 6 +++ 2 files changed, 120 insertions(+) create mode 100644 mods/soundset/init.lua create mode 100644 mods/soundset/readme.txt diff --git a/mods/soundset/init.lua b/mods/soundset/init.lua new file mode 100644 index 00000000..af771cd8 --- /dev/null +++ b/mods/soundset/init.lua @@ -0,0 +1,114 @@ +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.gainplayers = {} + + +sounds.set_sound = function(name, param) + if param == "" then + minetest.chat_send_player(name, "/setsound ") + 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 ") + minetest.log("action", "invalid param, see /setsound ") + return + end + + if param_name ~= "musique" 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 + local value = tonumber(param_value) + if value == nil then + minetest.log("action", "invalid value, " ..param_value .. " must be number") + return + end + + if value < 0 then + value = 0 + elseif value > 100 then + value = 100 + end + + if sounds.gainplayers[name][param_name] == value then + minetest.chat_send_player(name, "ambience " .. param_name .. " already set to " .. value) + minetest.log("action", name ..", ambience " .. param_name .. " already set to " .. value) + 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) + 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) + +end + + +sounds.get_gain = function(name, sound_type) + return sounds.gainplayers[name][sound_type]/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) + end +end + + +load_sounds_config() + +minetest.register_chatcommand("setsound", { + params = "", + description = "set volume sound ", + privs = {}, + func = sounds.set_sound, +}) + +minetest.register_chatcommand("getsound", { + params = "", + description = "print volume sound ", + 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 +}) + +minetest.register_on_joinplayer(function(player) + local name = player:get_player_name() + if sounds.gainplayers[name] == nil then + sounds.gainplayers[name] = sounds.gaindefault + end +end) +minetest.log("action","[mod soundset] Loaded") + diff --git a/mods/soundset/readme.txt b/mods/soundset/readme.txt new file mode 100644 index 00000000..83f8b6a3 --- /dev/null +++ b/mods/soundset/readme.txt @@ -0,0 +1,6 @@ +-= soundset-MOD for MINETEST =- +by Mg and crabman77 + +YOUR mod can use THIS mod to have a volume that's adjustable by the player(s) + +0.1 - Initial Release