From 463b3c20e11c653c21f19a472f6906071a52e172 Mon Sep 17 00:00:00 2001 From: Aaron Suen Date: Wed, 18 Mar 2020 22:10:54 -0400 Subject: [PATCH] New mod to add simple chat sounds. --- szutil_chatsounds/README | 0 szutil_chatsounds/init.lua | 114 ++++++++++++++++++ .../sounds/szutil_chatsounds.ogg | Bin 0 -> 4015 bytes szutil_chatsounds/sounds/untitled.ogg | Bin 0 -> 3930 bytes 4 files changed, 114 insertions(+) create mode 100644 szutil_chatsounds/README create mode 100644 szutil_chatsounds/init.lua create mode 100644 szutil_chatsounds/sounds/szutil_chatsounds.ogg create mode 100644 szutil_chatsounds/sounds/untitled.ogg diff --git a/szutil_chatsounds/README b/szutil_chatsounds/README new file mode 100644 index 0000000..e69de29 diff --git a/szutil_chatsounds/init.lua b/szutil_chatsounds/init.lua new file mode 100644 index 0000000..4fdd3ac --- /dev/null +++ b/szutil_chatsounds/init.lua @@ -0,0 +1,114 @@ +-- LUALOCALS < --------------------------------------------------------- +local ipairs, minetest, pairs, tonumber, tostring + = ipairs, minetest, pairs, tonumber, tostring +-- LUALOCALS > --------------------------------------------------------- + +local modname = minetest.get_current_modname() + +local function parsespec(param) + local config = {} + for _, s in ipairs(param:split(" ")) do + local n = tonumber(s) + if n then + config[#config + 1] = {gain = n} + else + local gain, pitch = s:match("^(%S+):(%S+)$") + gain = tonumber(gain) + pitch = tonumber(pitch) + if gain and pitch then + config[#config + 1] = {gain = gain, pitch = pitch} + else + return false, "failed to parse spec" + end + end + end + return config +end + +local default = parsespec("0.5:1.2 0.25 0.25 0.25:0.8 0") + +local function dosound(player, pname, msgtype) + local config = player:get_meta():get_string(modname) or "" + config = config ~= "" and minetest.deserialize(config) or nil + config = config and #config > 0 and config or default + + local data = (msgtype > #config) and config[#config] or config[msgtype] + if (data.gain or 0) <= 0 then return end + + minetest.sound_play(modname, { + to_player = pname, + pitchvary = 0, + gain = data.gain, + pitch = data.pitch or 1 + }) +end + +minetest.register_chatcommand(modname, { + description = "change chat sound configuration", + params = " [... for chat] [...emote]" + .. " [...join/part] [...server] [...other]", + func = function(pname, param) + local player = minetest.get_player_by_name(pname) + if not player then return false, "player not connected" end + + local config = parsespec(param) + if #config < 1 then return false, "empty config" end + + player:get_meta():set_string(modname, minetest.serialize(config)) + end + }) + +local pending = {} + +minetest.register_globalstep(function() + for _, player in pairs(minetest.get_connected_players()) do + local pname = player:get_player_name() + local msgtype = pending[pname] + if msgtype then dosound(player, pname, msgtype) end + end + pending = {} + end) + +local function send(pname, text) + text = tostring(text) + + local msgtype + if text:match("^%s*DM%sfrom%s") then msgtype = 1 -- DM + elseif text:match("^%s*%<") then msgtype = 2 -- public chat + elseif text:match("^%s*%*%s") then msgtype = 3 -- emotes + elseif text:match("^%s*%*%*%*%s") then msgtype = 4 -- join/part + elseif text:match("^%s*%#%s") then msgtype = 5 -- server + else msgtype = 6 end -- unknown/misc + + local n = pending[pname] or msgtype + pending[pname] = msgtype > n and n or msgtype +end + +local function sendall(text) + for _, player in pairs(minetest.get_connected_players()) do + send(player:get_player_name(), text) + end +end + +do + local old_sendall = minetest.chat_send_all + function minetest.chat_send_all(text, ...) + sendall(text) + return old_sendall(text, ...) + end +end + +minetest.register_on_chat_message(function(pname, text) + if text:sub(1, 1) ~= "/" + and minetest.check_player_privs(pname, "shout") then + sendall("<" .. pname .. "> " .. text) + end + end) + +do + local old_sendp = minetest.chat_send_player + function minetest.chat_send_player(pname, text, ...) + send(pname, text) + return old_sendp(pname, text, ...) + end +end diff --git a/szutil_chatsounds/sounds/szutil_chatsounds.ogg b/szutil_chatsounds/sounds/szutil_chatsounds.ogg new file mode 100644 index 0000000000000000000000000000000000000000..9e1a4a685b1d3a6cd63032dd318f8b705ff1a3d9 GIT binary patch literal 4015 zcmd5Xgn$_o43dN>B?-2j(xw_L z0#d|~kr)|1LNFIdF#>9wM=4d*VDW=OM2dn8iOZ-s{QxU{&p9{PnZEUA-mF>k&zyB~ zvd=#I{O;cS?0xRO$-8%_0yprY<)w`(P%<1agD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