From a51d7cd347fe80e81465aa93f1b6ce2d056b291e Mon Sep 17 00:00:00 2001 From: -sniper- <47271658+JostP@users.noreply.github.com> Date: Sun, 13 Dec 2020 17:44:31 +0100 Subject: [PATCH] Colorize "flag regarding" messages (#715) * Colorize "flag regarding" messages * edit flag_func.lua * edit api.lua * edit matches.lua * fix small bug in flag_func.lua * fix another small bug in flag_func.lua --- mods/ctf/ctf_flag/api.lua | 12 ++++++++++- mods/ctf/ctf_flag/flag_func.lua | 36 +++++++++++++++++++++++++++++---- mods/ctf/ctf_match/matches.lua | 15 ++++++++++++-- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/mods/ctf/ctf_flag/api.lua b/mods/ctf/ctf_flag/api.lua index 4fdeba2..de4666f 100644 --- a/mods/ctf/ctf_flag/api.lua +++ b/mods/ctf/ctf_flag/api.lua @@ -80,7 +80,17 @@ function ctf_flag.player_drop_flag(name) ctf.hud.updateAll() ctf.action("flag", name .. " dropped " .. flag_name) - minetest.chat_send_all(flag_name.." has returned.") + + local flag_return_color = "#ffffff" + if flag_name == "red's flag" then + flag_return_color = ctf_colors.colors["red"] + end + if flag_name == "blue's flag" then + flag_return_color = ctf_colors.colors["blue"] + end + flag_return_color = "#" .. tostring(flag_return_color):sub(3, 8) + + minetest.chat_send_all(minetest.colorize(flag_return_color, (flag_name.." has returned."))) for j = 1, #ctf_flag.registered_on_drop do ctf_flag.registered_on_drop[j](name, flag) diff --git a/mods/ctf/ctf_flag/flag_func.lua b/mods/ctf/ctf_flag/flag_func.lua index 1beab69..989a8aa 100644 --- a/mods/ctf/ctf_flag/flag_func.lua +++ b/mods/ctf/ctf_flag/flag_func.lua @@ -16,8 +16,22 @@ local function do_capture(attname, flag, returned) end end - minetest.chat_send_all(flag_name.." has been picked up by ".. - attname.." (team "..attacker.team..")") + local team_has_flag_color = "#ffffff" + local team_lose_flag_color = "#ffffff" + if attacker.team == "red" then + team_has_flag_color = ctf_colors.colors["red"] + team_lose_flag_color = ctf_colors.colors["blue"] + end + + if attacker.team == "blue" then + team_has_flag_color = ctf_colors.colors["blue"] + team_lose_flag_color = ctf_colors.colors["red"] + end + team_has_flag_color = "#" .. tostring(team_has_flag_color):sub(3, 8) + team_lose_flag_color = "#" .. tostring(team_lose_flag_color):sub(3, 8) + + minetest.chat_send_all((minetest.colorize(team_lose_flag_color, flag_name)).." has been picked up by ".. + (minetest.colorize(team_has_flag_color, (attname.." (team "..attacker.team..")")))) ctf.action("flag", attname .. " picked up " .. flag_name) @@ -41,8 +55,22 @@ local function do_capture(attname, flag, returned) end end - minetest.chat_send_all(flag_name.." has been captured ".. - " by "..attname.." (team "..attacker.team..")") + local team_win_color = "#ffffff" + local team_lose_color = "#ffffff" + if attacker.team == "red" then + team_win_color = ctf_colors.colors["red"] + team_lose_color = ctf_colors.colors["blue"] + end + + if attacker.team == "blue" then + team_win_color = ctf_colors.colors["blue"] + team_lose_color = ctf_colors.colors["red"] + end + team_win_color = "#" .. tostring(team_win_color):sub(3, 8) + team_lose_color = "#" .. tostring(team_lose_color):sub(3, 8) + + minetest.chat_send_all((minetest.colorize(team_lose_color, flag_name)).." has been captured ".. + "by "..(minetest.colorize(team_win_color, (attname.." (team "..attacker.team..")")))) ctf.action("flag", attname .. " captured " .. flag_name) diff --git a/mods/ctf/ctf_match/matches.lua b/mods/ctf/ctf_match/matches.lua index fff445e..2e0100a 100644 --- a/mods/ctf/ctf_match/matches.lua +++ b/mods/ctf/ctf_match/matches.lua @@ -62,7 +62,18 @@ function ctf_match.check_for_winner() if not game_won then game_won = true ctf.action("match", winner .. " won!") - minetest.chat_send_all(minetest.colorize("#028704", ("Team " .. winner .. " won!"))) + + local winner_color = "#ffffff" + if winner == "red" then + winner_color = ctf_colors.colors["red"] + end + if winner == "blue" then + winner_color = ctf_colors.colors["blue"] + end + winner_color = "#" .. tostring(winner_color):sub(3, 8) + + minetest.chat_send_all(minetest.colorize(winner_color, ("Team " .. winner .. " won!"))) + for i = 1, #ctf_match.registered_on_winner do ctf_match.registered_on_winner[i](winner) end @@ -99,7 +110,7 @@ ctf_flag.register_on_capture(function(attname, flag) if fl_team and #fl_team.flags == 0 then ctf.action("match", flag.team .. " was defeated.") ctf.remove_team(flag.team) - minetest.chat_send_all(minetest.colorize("#028704", (flag.team .. " has been defeated!"))) + minetest.chat_send_all(minetest.colorize("#808080", (flag.team .. " has been defeated!"))) end ctf_match.check_for_winner()