Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Death Message #1179

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions mods/ctf/ctf_modebase/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ local FLAG_CAPTURE_TIMER = 60 * 3
local many_teams = false
local team_list
local teams_left
local death_messages = {
["grenades_frag"] = {"blown up", "fragged"},
["knockback_grenade"] = {"sent flying", "doomed to fall"},
["black_hole_grenade"] = {"sucked into the void"},
["sword"] = {"killed", "sliced up"},
["axe"] = {"killed", "chopped up",},
["shovel"] = {"killed with the tool that dug your grave"},
["pick"] = {"killed", "mistaken for mese ore"},
["ctf_ranged"] = {"shot"},
["rifle"] = {"sniped"},
["default_water"] = {"drowned", "over-hydrated"},
["damage_cobble"] = {"mined a little too much damage cobble"},
["lava"] = {"tried to swim in lava", "took a hot bath"},
["fire"] = {"burnt to a crisp"},
}

local function calculate_killscore(player)
local match_rank = recent_rankings.players()[player] or {}
Expand Down Expand Up @@ -66,6 +81,59 @@ local function get_suicide_image(reason)
return image
end

local function send_death_message(player, killer, weapon_image)
local death_setting = ctf_settings.get(minetest.get_player_by_name(player), "send_death_message")
local assist_message = ""
local weapon_message
local hitters = ctf_combat_mode.get_other_hitters(player, killer)

local k_teamcolor = ctf_teams.get(killer)
if k_teamcolor then
k_teamcolor = ctf_teams.team[k_teamcolor].color
end
for key, data in pairs(death_messages) do
if weapon_image:find(tostring(key)) then
weapon_message = data[math.random(1,#data)]
end
end

if #hitters > 0 then
assist_message = ", assisted by "
for index, pname in ipairs(hitters) do
local a_teamcolor = ctf_teams.get(pname)
if a_teamcolor then
a_teamcolor = ctf_teams.team[a_teamcolor].color
end
if index == 1 then
assist_message = assist_message .. minetest.colorize(a_teamcolor, pname)
elseif index == #hitters then
assist_message = assist_message .. ", and " .. minetest.colorize(a_teamcolor, pname)
else
assist_message = assist_message .. ", " .. minetest.colorize(a_teamcolor, pname)
end
end
end

if (death_setting == "true") then
if player ~= killer then
if weapon_message then
local death_message = "You were " .. weapon_message
.. " by " .. minetest.colorize(k_teamcolor, killer) .. assist_message .. "."
minetest.chat_send_player(player, death_message)
else
local death_message = "You were killed by "
.. minetest.colorize(k_teamcolor, killer) .. assist_message .. "."
minetest.chat_send_player(player, death_message)
end
end
if player == killer and #hitters == 0 then
local suicide_message = weapon_message or "suicided"
local death_message = "You " .. suicide_message .. assist_message .. "."
minetest.chat_send_player(player, death_message)
end
end
end

local function tp_player_near_flag(player)
local tname = ctf_teams.get(player)
if not tname then return end
Expand Down Expand Up @@ -153,8 +221,10 @@ local function end_combat_mode(player, reason, killer, weapon_image)
if ctf_teams.get(player) then
if reason == "punch" then
ctf_kill_list.add(player, player, weapon_image)
send_death_message(player, killer, weapon_image)
else
ctf_kill_list.add("", player, get_suicide_image(reason))
send_death_message(player, player, get_suicide_image(reason))
end
end

Expand All @@ -180,6 +250,7 @@ local function end_combat_mode(player, reason, killer, weapon_image)

if ctf_teams.get(killer) then
ctf_kill_list.add(killer, player, weapon_image, comment)
send_death_message(player, killer, weapon_image)
end

-- share kill score with other hitters
Expand Down Expand Up @@ -594,3 +665,10 @@ return {
}

end

ctf_settings.register("send_death_messages", {
type = "bool",
label = "Receive death messages.",
description = "When enabled, you will receive a death message whenever you die stating who killed you.",
default = "true",
})