From cd63f32cdda8f395d220d05abb504c56e10c3a01 Mon Sep 17 00:00:00 2001 From: CyberMango Date: Thu, 5 Jan 2023 23:28:44 +0200 Subject: [PATCH 1/6] Fixed and optimized assist death messages. Still left many log messages, a longer timeout and some unclean parts. --- mods/HUD/mcl_death_messages/init.lua | 41 +++++++++++++++++++--------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/mods/HUD/mcl_death_messages/init.lua b/mods/HUD/mcl_death_messages/init.lua index 13ed23668..4157b0064 100644 --- a/mods/HUD/mcl_death_messages/init.lua +++ b/mods/HUD/mcl_death_messages/init.lua @@ -1,5 +1,7 @@ local S = minetest.get_translator(minetest.get_current_modname()) +ASSIST_TIMEOUT_SEC = 10 + mcl_death_messages = { assist = {}, messages = { @@ -181,8 +183,16 @@ local function get_killer_message(obj, messages, reason) end local function get_assist_message(obj, messages, reason) - if messages.assist and mcl_death_messages.assist[obj] then - return messages._translator(messages.assist, mcl_util.get_object_name(obj), mcl_death_messages.assist[obj].name) + -- Avoid a timing issue if the assist passes its timeout. + local assist_details = mcl_death_messages.assist[obj] + if messages.assist then + print("TODO message.assist exists!")--TODO make this 1 condition again + if assist_details then + print("TODO There is an assist message object!")--TODO + return messages._translator(messages.assist, mcl_util.get_object_name(obj), assist_details.name) + end + else--TODO remove this else + print("TODO There was no assist message!") end end @@ -224,6 +234,9 @@ mcl_damage.register_on_death(function(obj, reason) get_fallback_message(obj, messages, reason) if send_to == true then + if not message or message == "" then + message = "there was not message" + end minetest.chat_send_all(message) else minetest.chat_send_player(send_to, message) @@ -232,20 +245,22 @@ mcl_damage.register_on_death(function(obj, reason) end) mcl_damage.register_on_damage(function(obj, damage, reason) + print("TODO ", reason.type .. " caused damage ") if obj:get_hp() - damage > 0 then if reason.source then - mcl_death_messages.assist[obj] = {name = mcl_util.get_object_name(reason.source), timeout = 5} - else - mcl_death_messages.assist[obj] = nil - end - end -end) + print("TODO reason had a source") + -- To avoid timing issues we cancel the previous job before adding a new one. + if mcl_death_messages.assist[obj] then + print("TODO job is being caceled") + mcl_death_messages.assist[obj].job:cancel() + end -minetest.register_globalstep(function(dtime) - for obj, tbl in pairs(mcl_death_messages.assist) do - tbl.timeout = tbl.timeout - dtime - if not obj:is_player() and not obj:get_luaentity() or tbl.timeout > 0 then - mcl_death_messages.assist[obj] = nil + -- Add a new assist object with a timeout job. + local new_job = minetest.after(ASSIST_TIMEOUT_SEC, function() + print("TODO in job") + mcl_death_messages.assist[obj] = nil + end) + mcl_death_messages.assist[obj] = {name = mcl_util.get_object_name(reason.source), job = new_job} end end end) From 96cd2657dbdf9f2b01e77b27b49797d347d67c03 Mon Sep 17 00:00:00 2001 From: CyberMango Date: Thu, 5 Jan 2023 23:51:10 +0200 Subject: [PATCH 2/6] Cleanup and removed debug prints. --- mods/HUD/mcl_death_messages/init.lua | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/mods/HUD/mcl_death_messages/init.lua b/mods/HUD/mcl_death_messages/init.lua index 4157b0064..2f2347222 100644 --- a/mods/HUD/mcl_death_messages/init.lua +++ b/mods/HUD/mcl_death_messages/init.lua @@ -1,6 +1,6 @@ local S = minetest.get_translator(minetest.get_current_modname()) -ASSIST_TIMEOUT_SEC = 10 +ASSIST_TIMEOUT_SEC = 5 mcl_death_messages = { assist = {}, @@ -151,11 +151,6 @@ mcl_death_messages = { plain = "@1 went off with a bang", item = "@1 went off with a bang due to a firework fired from @3 by @2", -- order is intentional }, - sweet_berry = { - _translator = S, - plain = "@1 died a sweet death", - assist = "@1 was poked to death by a sweet berry bush whilst trying to escape @2", - }, -- Missing snowballs: The Minecraft wiki mentions them but the MC source code does not. }, } @@ -185,14 +180,8 @@ end local function get_assist_message(obj, messages, reason) -- Avoid a timing issue if the assist passes its timeout. local assist_details = mcl_death_messages.assist[obj] - if messages.assist then - print("TODO message.assist exists!")--TODO make this 1 condition again - if assist_details then - print("TODO There is an assist message object!")--TODO - return messages._translator(messages.assist, mcl_util.get_object_name(obj), assist_details.name) - end - else--TODO remove this else - print("TODO There was no assist message!") + if messages.assist and assist_details then + return messages._translator(messages.assist, mcl_util.get_object_name(obj), assist_details.name) end end @@ -234,9 +223,6 @@ mcl_damage.register_on_death(function(obj, reason) get_fallback_message(obj, messages, reason) if send_to == true then - if not message or message == "" then - message = "there was not message" - end minetest.chat_send_all(message) else minetest.chat_send_player(send_to, message) @@ -245,19 +231,15 @@ mcl_damage.register_on_death(function(obj, reason) end) mcl_damage.register_on_damage(function(obj, damage, reason) - print("TODO ", reason.type .. " caused damage ") if obj:get_hp() - damage > 0 then if reason.source then - print("TODO reason had a source") -- To avoid timing issues we cancel the previous job before adding a new one. if mcl_death_messages.assist[obj] then - print("TODO job is being caceled") mcl_death_messages.assist[obj].job:cancel() end -- Add a new assist object with a timeout job. local new_job = minetest.after(ASSIST_TIMEOUT_SEC, function() - print("TODO in job") mcl_death_messages.assist[obj] = nil end) mcl_death_messages.assist[obj] = {name = mcl_util.get_object_name(reason.source), job = new_job} From a1d98c080f30ff7b5e6dfdce4d93180916736471 Mon Sep 17 00:00:00 2001 From: CyberMango Date: Fri, 6 Jan 2023 01:07:11 +0200 Subject: [PATCH 3/6] Now only allowing players and lua entities to do assist kills. --- mods/HUD/mcl_death_messages/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/HUD/mcl_death_messages/init.lua b/mods/HUD/mcl_death_messages/init.lua index 2f2347222..8fe387bd8 100644 --- a/mods/HUD/mcl_death_messages/init.lua +++ b/mods/HUD/mcl_death_messages/init.lua @@ -232,7 +232,7 @@ end) mcl_damage.register_on_damage(function(obj, damage, reason) if obj:get_hp() - damage > 0 then - if reason.source then + if reason.source and (reason.source:is_player() or obj:get_luaentity()) then -- To avoid timing issues we cancel the previous job before adding a new one. if mcl_death_messages.assist[obj] then mcl_death_messages.assist[obj].job:cancel() From 06435e0f4cb9b663b1c4b7df3c184c66b725b1cc Mon Sep 17 00:00:00 2001 From: CyberMango Date: Fri, 6 Jan 2023 01:13:39 +0200 Subject: [PATCH 4/6] Mixed 2 conditions into 1. --- mods/HUD/mcl_death_messages/init.lua | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/mods/HUD/mcl_death_messages/init.lua b/mods/HUD/mcl_death_messages/init.lua index 8fe387bd8..b31d7703f 100644 --- a/mods/HUD/mcl_death_messages/init.lua +++ b/mods/HUD/mcl_death_messages/init.lua @@ -231,18 +231,17 @@ mcl_damage.register_on_death(function(obj, reason) end) mcl_damage.register_on_damage(function(obj, damage, reason) - if obj:get_hp() - damage > 0 then - if reason.source and (reason.source:is_player() or obj:get_luaentity()) then - -- To avoid timing issues we cancel the previous job before adding a new one. - if mcl_death_messages.assist[obj] then - mcl_death_messages.assist[obj].job:cancel() - end - - -- Add a new assist object with a timeout job. - local new_job = minetest.after(ASSIST_TIMEOUT_SEC, function() - mcl_death_messages.assist[obj] = nil - end) - mcl_death_messages.assist[obj] = {name = mcl_util.get_object_name(reason.source), job = new_job} + if (obj:get_hp() - damage > 0) and reason.source and + (reason.source:is_player() or obj:get_luaentity()) then + -- To avoid timing issues we cancel the previous job before adding a new one. + if mcl_death_messages.assist[obj] then + mcl_death_messages.assist[obj].job:cancel() end + + -- Add a new assist object with a timeout job. + local new_job = minetest.after(ASSIST_TIMEOUT_SEC, function() + mcl_death_messages.assist[obj] = nil + end) + mcl_death_messages.assist[obj] = {name = mcl_util.get_object_name(reason.source), job = new_job} end end) From 4ec506b534b7659f867872e2ea9751c3a04d1769 Mon Sep 17 00:00:00 2001 From: CyberMango Date: Fri, 6 Jan 2023 13:08:23 +0200 Subject: [PATCH 5/6] Turned a global constant into local. --- mods/HUD/mcl_death_messages/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/HUD/mcl_death_messages/init.lua b/mods/HUD/mcl_death_messages/init.lua index b31d7703f..3a74bd604 100644 --- a/mods/HUD/mcl_death_messages/init.lua +++ b/mods/HUD/mcl_death_messages/init.lua @@ -1,6 +1,6 @@ local S = minetest.get_translator(minetest.get_current_modname()) -ASSIST_TIMEOUT_SEC = 5 +local ASSIST_TIMEOUT_SEC = 5 mcl_death_messages = { assist = {}, From e2cbd4267cbcadd6f2a3a5cc09007bfd8eda0342 Mon Sep 17 00:00:00 2001 From: CyberMango Date: Fri, 13 Jan 2023 23:02:39 +0200 Subject: [PATCH 6/6] Added back sweet berries death messages. --- mods/HUD/mcl_death_messages/init.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mods/HUD/mcl_death_messages/init.lua b/mods/HUD/mcl_death_messages/init.lua index 3a74bd604..00de9228c 100644 --- a/mods/HUD/mcl_death_messages/init.lua +++ b/mods/HUD/mcl_death_messages/init.lua @@ -151,6 +151,11 @@ mcl_death_messages = { plain = "@1 went off with a bang", item = "@1 went off with a bang due to a firework fired from @3 by @2", -- order is intentional }, + sweet_berry = { + _translator = S, + plain = "@1 died a sweet death", + assist = "@1 was poked to death by a sweet berry bush whilst trying to escape @2", + }, -- Missing snowballs: The Minecraft wiki mentions them but the MC source code does not. }, }