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 16 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
81 changes: 81 additions & 0 deletions mods/ctf/ctf_modebase/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ local FLAG_CAPTURE_TIMER = 60 * 3
local many_teams = false
local team_list
local teams_left
local death_messages = {{"grenades_frag",{"blown up", "bombed", "exploded"}},
{"knockback_grenade",{"sent flying", "doomed to fall"}},
{"black_hole_grenade",{"sucked into the void"}},
{"sword",{"killed", "slashed", "stabbed", "murdered"}},
{"axe",{"killed", "slashed", "murdered", "axed a question"}},
{"shovel",{"killed with a gardening mere tool"}},
{"pick",{"pickaxed to death"}},
{"ctf_ranged",{"shot", "sniped"}},
{"default_water", {"suffocated"}},
{"damage_cobble", {"mined something deadly placed"}},
{"lava", {"tried to swim in lava"}},
{"fire", {"burnt to a crisp"}}}
165135 marked this conversation as resolved.
Show resolved Hide resolved

local function calculate_killscore(player)
local match_rank = recent_rankings.players()[player] or {}
Expand Down Expand Up @@ -66,6 +78,65 @@ 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 image_index = nil
local assist_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 index, data in ipairs(death_messages) do
if weapon_image:find(data[1]) then
image_index = index
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 image_index then
local death_message = "You were "
.. death_messages[image_index][2][math.random(1,#death_messages[image_index][2])]
.. " 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
if image_index then
suicide_message = death_messages[image_index][2][math.random(1,#death_messages[image_index][2])]
else
suicide_message = "suicided"
end
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 +224,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 +253,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 +668,10 @@ return {
}

end

ctf_settings.register("send_death_message", {
type = "bool",
label = "Recieve death message",
165135 marked this conversation as resolved.
Show resolved Hide resolved
description = "When enabled, you will recieve a death message whenever you die stating who killed you.",
165135 marked this conversation as resolved.
Show resolved Hide resolved
default = "false",
})