Skip to content

Commit d0ab30c

Browse files
165135farooqkzLoneWolfHT
authored
Add Death Messages (#1179)
* Add ctf_death_message * Update features.lua with death message * Attempt to fix luacheck warnings * Attempt to fix luacheck warnings... again * Update features.lua * Luacheck attempt #3 * Luacheck Attempt #3 * Put death message in features.lua * Delete init.lua * Delete mod.conf * Update features.lua * did I seriously forget to take that out * Fix registering setting multiple times * how did I forget that again * move settings register out of ctf_modebase.features * I should enable spellcheck Co-authored-by: Farooq Karimi Zadeh <fkz@riseup.net> * Change description a tiny bit Co-authored-by: Farooq Karimi Zadeh <fkz@riseup.net> * I should learn more about lua data structures * Appeasing luacheck * Replacing something I shouldn't have removed * Update mods/ctf/ctf_modebase/features.lua Co-authored-by: LoneWolfHT <lonewolf04361@gmail.com> * Update mods/ctf/ctf_modebase/features.lua Co-authored-by: LoneWolfHT <lonewolf04361@gmail.com> --------- Co-authored-by: Farooq Karimi Zadeh <fkz@riseup.net> Co-authored-by: LoneWolfHT <lonewolf04361@gmail.com>
1 parent c8ef744 commit d0ab30c

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

mods/ctf/ctf_modebase/features.lua

+78
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ local FLAG_CAPTURE_TIMER = 60 * 3
176176
local many_teams = false
177177
local team_list
178178
local teams_left
179+
local death_messages = {
180+
["grenades_frag"] = {"blown up", "fragged"},
181+
["knockback_grenade"] = {"sent flying", "doomed to fall"},
182+
["black_hole_grenade"] = {"sucked into the void"},
183+
["sword"] = {"killed", "sliced up"},
184+
["axe"] = {"killed", "chopped up",},
185+
["shovel"] = {"killed with the tool that dug your grave"},
186+
["pick"] = {"killed", "mistaken for mese ore"},
187+
["ctf_ranged"] = {"shot"},
188+
["rifle"] = {"sniped"},
189+
["default_water"] = {"drowned", "over-hydrated"},
190+
["damage_cobble"] = {"mined a little too much damage cobble"},
191+
["lava"] = {"tried to swim in lava", "took a hot bath"},
192+
["fire"] = {"burnt to a crisp"},
193+
}
179194

180195
local function calculate_killscore(player)
181196
local match_rank = recent_rankings.players()[player] or {}
@@ -257,6 +272,59 @@ local function get_suicide_image(reason)
257272
return image
258273
end
259274

275+
local function send_death_message(player, killer, weapon_image)
276+
local death_setting = ctf_settings.get(minetest.get_player_by_name(player), "send_death_message")
277+
local assist_message = ""
278+
local weapon_message
279+
local hitters = ctf_combat_mode.get_other_hitters(player, killer)
280+
281+
local k_teamcolor = ctf_teams.get(killer)
282+
if k_teamcolor then
283+
k_teamcolor = ctf_teams.team[k_teamcolor].color
284+
end
285+
for key, data in pairs(death_messages) do
286+
if weapon_image:find(tostring(key)) then
287+
weapon_message = data[math.random(1,#data)]
288+
end
289+
end
290+
291+
if #hitters > 0 then
292+
assist_message = ", assisted by "
293+
for index, pname in ipairs(hitters) do
294+
local a_teamcolor = ctf_teams.get(pname)
295+
if a_teamcolor then
296+
a_teamcolor = ctf_teams.team[a_teamcolor].color
297+
end
298+
if index == 1 then
299+
assist_message = assist_message .. minetest.colorize(a_teamcolor, pname)
300+
elseif index == #hitters then
301+
assist_message = assist_message .. ", and " .. minetest.colorize(a_teamcolor, pname)
302+
else
303+
assist_message = assist_message .. ", " .. minetest.colorize(a_teamcolor, pname)
304+
end
305+
end
306+
end
307+
308+
if (death_setting == "true") then
309+
if player ~= killer then
310+
if weapon_message then
311+
local death_message = "You were " .. weapon_message
312+
.. " by " .. minetest.colorize(k_teamcolor, killer) .. assist_message .. "."
313+
minetest.chat_send_player(player, death_message)
314+
else
315+
local death_message = "You were killed by "
316+
.. minetest.colorize(k_teamcolor, killer) .. assist_message .. "."
317+
minetest.chat_send_player(player, death_message)
318+
end
319+
end
320+
if player == killer and #hitters == 0 then
321+
local suicide_message = weapon_message or "suicided"
322+
local death_message = "You " .. suicide_message .. assist_message .. "."
323+
minetest.chat_send_player(player, death_message)
324+
end
325+
end
326+
end
327+
260328
local function tp_player_near_flag(player)
261329
local tname = ctf_teams.get(player)
262330
if not tname then return end
@@ -356,8 +424,10 @@ local function end_combat_mode(player, reason, killer, weapon_image)
356424
if reason ~= "punch" or killer == player then
357425
if reason == "punch" then
358426
ctf_kill_list.add(player, player, weapon_image)
427+
send_death_message(player, killer, weapon_image)
359428
else
360429
ctf_kill_list.add("", player, get_suicide_image(reason))
430+
send_death_message(player, player, get_suicide_image(reason))
361431
end
362432

363433
killer, weapon_image = ctf_combat_mode.get_last_hitter(player)
@@ -389,6 +459,7 @@ local function end_combat_mode(player, reason, killer, weapon_image)
389459
text = killer .. " " .. S("killed you for") .. " " .. rewards.score .." " .. S("points!"),
390460
color = "warning",
391461
})
462+
send_death_message(player, killer, weapon_image)
392463
end
393464

394465
-- share kill score with other hitters
@@ -969,3 +1040,10 @@ return {
9691040
}
9701041

9711042
end
1043+
1044+
ctf_settings.register("send_death_messages", {
1045+
type = "bool",
1046+
label = "Receive death messages.",
1047+
description = "When enabled, you will receive a death message whenever you die stating who killed you.",
1048+
default = "true",
1049+
})

0 commit comments

Comments
 (0)