diff --git a/mods/ctf_bounties/init.lua b/mods/ctf_bounties/init.lua index d1f4be3..35cc524 100644 --- a/mods/ctf_bounties/init.lua +++ b/mods/ctf_bounties/init.lua @@ -21,10 +21,7 @@ local function announce_all() end local function bounty_player(target) - if bountied_player then - minetest.chat_send_all("Player " .. bountied_player .. " no longer has a bounty on their head!") - end - + local prev = bountied_player bountied_player = target -- Score * K/D @@ -44,6 +41,19 @@ local function bounty_player(target) end bounty_score = math.floor(bounty_score) + if prev then + for _, player in pairs(minetest.get_connected_players()) do + local name = player:get_player_name() + if bountied_player ~= name then + local _, prev_color = ctf_colors.get_color(prev, ctf.player(prev)) + minetest.chat_send_player(player:get_player_name(), + minetest.colorize("#fff326", "Player ") .. + minetest.colorize(prev_color:gsub("0x", "#"), prev) .. + minetest.colorize("#fff326", " no longer has a bounty on their head!")) + end + end + end + minetest.after(0.1, announce_all) end @@ -67,15 +77,11 @@ local function bounty_find_new_target() end minetest.after(math.random(500, 1000), bounty_find_new_target) -minetest.register_on_leaveplayer(function(player) - if bountied_player == player:get_player_name() then - bountied_player = nil - end -end) - minetest.register_on_joinplayer(function(player) - if bountied_player then - announce(player:get_player_name()) + local name = player:get_player_name() + if bountied_player and + bountied_player ~= name then + announce(name) end end)