1
0
Fork 0

Merge pull request 'Fix assist death messages rarely showing up' (#3265) from CyberMango/MineClone2:dev/mango/assist_death_messages_fix into master

Reviewed-on: MineClone2/MineClone2#3265
Reviewed-by: ancientmarinerdev <ancientmariner_dev@proton.me>
This commit is contained in:
ancientmarinerdev 2023-01-22 23:31:58 +00:00
commit 9a276489d1
1 changed files with 15 additions and 14 deletions

View File

@ -1,5 +1,7 @@
local S = minetest.get_translator(minetest.get_current_modname()) local S = minetest.get_translator(minetest.get_current_modname())
local ASSIST_TIMEOUT_SEC = 5
mcl_death_messages = { mcl_death_messages = {
assist = {}, assist = {},
messages = { messages = {
@ -181,8 +183,10 @@ local function get_killer_message(obj, messages, reason)
end end
local function get_assist_message(obj, messages, reason) local function get_assist_message(obj, messages, reason)
if messages.assist and mcl_death_messages.assist[obj] then -- Avoid a timing issue if the assist passes its timeout.
return messages._translator(messages.assist, mcl_util.get_object_name(obj), mcl_death_messages.assist[obj].name) local assist_details = mcl_death_messages.assist[obj]
if messages.assist and assist_details then
return messages._translator(messages.assist, mcl_util.get_object_name(obj), assist_details.name)
end end
end end
@ -232,20 +236,17 @@ mcl_damage.register_on_death(function(obj, reason)
end) end)
mcl_damage.register_on_damage(function(obj, damage, reason) mcl_damage.register_on_damage(function(obj, damage, reason)
if obj:get_hp() - damage > 0 then if (obj:get_hp() - damage > 0) and reason.source and
if reason.source then (reason.source:is_player() or obj:get_luaentity()) then
mcl_death_messages.assist[obj] = {name = mcl_util.get_object_name(reason.source), timeout = 5} -- To avoid timing issues we cancel the previous job before adding a new one.
else if mcl_death_messages.assist[obj] then
mcl_death_messages.assist[obj] = nil mcl_death_messages.assist[obj].job:cancel()
end end
end
end)
minetest.register_globalstep(function(dtime) -- Add a new assist object with a timeout job.
for obj, tbl in pairs(mcl_death_messages.assist) do local new_job = minetest.after(ASSIST_TIMEOUT_SEC, function()
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 mcl_death_messages.assist[obj] = nil
end end)
mcl_death_messages.assist[obj] = {name = mcl_util.get_object_name(reason.source), job = new_job}
end end
end) end)