From 2ae401d4f50ed9e8c7fc7fb6cc7bb77335c07cc1 Mon Sep 17 00:00:00 2001 From: ANAND Date: Wed, 18 Sep 2019 02:28:17 +0800 Subject: [PATCH] ctf_chat: Add colored PMs (#449) - Sender name is colorized according to their team color. - Message body is colorized according to the setting `ctf_chat.message_color`; defaults to `#E043FF`. --- mods/ctf/ctf_chat/init.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mods/ctf/ctf_chat/init.lua b/mods/ctf/ctf_chat/init.lua index 8c037c5..e09efda 100644 --- a/mods/ctf/ctf_chat/init.lua +++ b/mods/ctf/ctf_chat/init.lua @@ -11,6 +11,34 @@ function minetest.is_player_name_valid(name) return name:match("^[%a%d_-]+$") end +-- Implement coloured PMs by overriding /msg +-- The following code has been adapted from the chat-command of the same name in +-- builtin/game/chat.lua of Minetest licensed +-- under the GNU LGPLv2.1+ license +minetest.override_chatcommand("msg", { + func = function(name, param) + local sendto, message = param:match("^(%S+)%s(.+)$") + if not sendto then + return false, "Invalid usage, see /help msg." + end + if not minetest.get_player_by_name(sendto) then + return false, "The player " .. sendto .. " is not online." + end + + -- Message color + local color = minetest.settings:get("ctf_chat.message_color") or "#E043FF" + + -- Colorized sender name and message + local str = minetest.colorize(color, "PM from ") + str = str .. minetest.colorize(ctf_colors.get_color(ctf.player(name)).css, name) + str = str .. minetest.colorize(color, ": " .. message) + minetest.chat_send_player(sendto, str) + + minetest.log("action", "PM from " .. name .. " to " .. sendto .. ": " .. message) + return true, "Message sent." + end +}) + local function team_console_help(name) minetest.chat_send_player(name, "Try:") minetest.chat_send_player(name, "/team - show team panel")