From d84f39dfd2ff3d8fd7aeeb4ba77c42753cbe3a9f Mon Sep 17 00:00:00 2001 From: cloudbells Date: Thu, 2 Dec 2021 10:37:54 +0100 Subject: [PATCH 1/4] Fixed double guild/addon message --- Hardcore.lua | 91 ++++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/Hardcore.lua b/Hardcore.lua index 94ef10e5..173f8b72 100644 --- a/Hardcore.lua +++ b/Hardcore.lua @@ -59,6 +59,7 @@ Hardcore_Character = { --[[ Local variables ]]-- local debug = false +local isPlayerDead -- Used to prevent double guild/addon messages. local pulses = {} local alert_msg_time = { PULSE = {}, @@ -540,6 +541,8 @@ function Hardcore:UNIT_SPELLCAST_SUCCEEDED(...) end function Hardcore:PLAYER_ENTERING_WORLD() + isPlayerDead = UnitIsDeadOrGhost("player") + Hardcore_Frame:RegisterForDrag("LeftButton") Hardcore_Alerts_Button:SetText(Hardcore_Settings.notify and "Disable alerts" or "Enable alerts") @@ -565,50 +568,53 @@ function Hardcore:PLAYER_ALIVE() end function Hardcore:PLAYER_DEAD() - -- Screenshot - C_Timer.After(PICTURE_DELAY, Screenshot) - - -- Update deaths - if #Hardcore_Character.deaths == 0 or (#Hardcore_Character.deaths > 0 and Hardcore_Character.deaths[#Hardcore_Character.deaths].player_alive_trigger ~= nil) then - table.insert(Hardcore_Character.deaths, { - player_dead_trigger = date("%m/%d/%y %H:%M:%S"), - player_alive_trigger = nil - }) - end + if not isPlayerDead then + -- Screenshot + C_Timer.After(PICTURE_DELAY, Screenshot) + + -- Update deaths + if #Hardcore_Character.deaths == 0 or (#Hardcore_Character.deaths > 0 and Hardcore_Character.deaths[#Hardcore_Character.deaths].player_alive_trigger ~= nil) then + table.insert(Hardcore_Character.deaths, { + player_dead_trigger = date("%m/%d/%y %H:%M:%S"), + player_alive_trigger = nil + }) + end - -- Send message to guild - local playerGreet = GENDER_GREETING[UnitSex("player")] - local name = UnitName("player") - local _, _, classID = UnitClass("player") - local class = CLASSES[classID] - local level = UnitLevel("player") - local zone, mapID - if IsInInstance() then - zone = GetInstanceInfo() - else - mapID = C_Map.GetBestMapForUnit("player") - zone = C_Map.GetMapInfo(mapID).name + -- Send message to guild + local playerGreet = GENDER_GREETING[UnitSex("player")] + local name = UnitName("player") + local _, _, classID = UnitClass("player") + local class = CLASSES[classID] + local level = UnitLevel("player") + local zone, mapID + if IsInInstance() then + zone = GetInstanceInfo() + else + mapID = C_Map.GetBestMapForUnit("player") + zone = C_Map.GetMapInfo(mapID).name + end + local messageFormat = "Our brave %s, %s the %s, has died at level %d in %s" + local messageString = messageFormat:format(playerGreet, name, class, level, zone) + if not (Last_Attack_Source == nil) then + messageString = string.format("%s to a %s", messageString, Last_Attack_Source) + Last_Attack_Source = nil + end + + if not (recent_msg["text"] == nil) then + local playerPronoun = GENDER_POSSESSIVE_PRONOUN[UnitSex("player")] + messageString = string.format("%s. %s last words were \"%s\"", messageString, playerPronoun, recent_msg["text"]) + end + + SendChatMessage(messageString, "GUILD") + + -- Send addon message + local deathData = string.format("%s%s%s", level, COMM_FIELD_DELIM, mapID and mapID or "") + local commMessage = COMM_COMMANDS[3] .. COMM_COMMAND_DELIM .. deathData + if CTL then + CTL:SendAddonMessage("ALERT", COMM_NAME, commMessage, "GUILD") + end + isPlayerDead = true end - local messageFormat = "Our brave %s, %s the %s, has died at level %d in %s" - local messageString = messageFormat:format(playerGreet, name, class, level, zone) - if not (Last_Attack_Source == nil) then - messageString = string.format("%s to a %s", messageString, Last_Attack_Source) - Last_Attack_Source = nil - end - - if not (recent_msg["text"] == nil) then - local playerPronoun = GENDER_POSSESSIVE_PRONOUN[UnitSex("player")] - messageString = string.format("%s. %s last words were \"%s\"", messageString, playerPronoun, recent_msg["text"]) - end - - SendChatMessage(messageString, "GUILD") - - -- Send addon message - local deathData = string.format("%s%s%s", level, COMM_FIELD_DELIM, mapID and mapID or "") - local commMessage = COMM_COMMANDS[3] .. COMM_COMMAND_DELIM .. deathData - if CTL then - CTL:SendAddonMessage("ALERT", COMM_NAME, commMessage, "GUILD") - end end function Hardcore:PLAYER_TARGET_CHANGED() @@ -636,6 +642,7 @@ function Hardcore:PLAYER_TARGET_CHANGED() end function Hardcore:PLAYER_UNGHOST() + isPlayerDead = false if UnitIsDeadOrGhost("player") == 1 then return end -- prevent message on ghost login or zone From 9a68fdec28617c543a9278a02b642b5956135fb4 Mon Sep 17 00:00:00 2001 From: cloudbells Date: Tue, 7 Dec 2021 14:04:31 +0100 Subject: [PATCH 2/4] Checking for pet death - Now only checking CLEU events that target the player. - Replaced name check with GUID check in CLEU. - If the pet name is the last damage source on the player, PLAYER_DEAD will now do nothing. --- Hardcore.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Hardcore.lua b/Hardcore.lua index 173f8b72..ebadecd3 100644 --- a/Hardcore.lua +++ b/Hardcore.lua @@ -569,6 +569,10 @@ end function Hardcore:PLAYER_DEAD() if not isPlayerDead then + if Last_Attack_Source == UnitName("pet") then -- If the pet died first, do nothing. + return + end + -- Screenshot C_Timer.After(PICTURE_DELAY, Screenshot) @@ -595,6 +599,7 @@ function Hardcore:PLAYER_DEAD() end local messageFormat = "Our brave %s, %s the %s, has died at level %d in %s" local messageString = messageFormat:format(playerGreet, name, class, level, zone) + if not (Last_Attack_Source == nil) then messageString = string.format("%s to a %s", messageString, Last_Attack_Source) Last_Attack_Source = nil @@ -872,15 +877,10 @@ function Hardcore:CHAT_MSG_ADDON(prefix, datastr, scope, sender) end function Hardcore:COMBAT_LOG_EVENT_UNFILTERED(...) - -- local time, token, hidding, source_serial, source_name, caster_flags, caster_flags2, target_serial, target_name, target_flags, target_flags2, ability_id, ability_name, ability_type, extraSpellID, extraSpellName, extraSchool = CombatLogGetCurrentEventInfo() - local _, ev, _, _, source_name, _, _, _, _, _, _, _, _, _, _, _, _ = CombatLogGetCurrentEventInfo() - - if not (source_name == PLAYER_NAME) then - if not (source_name == nil) then - if string.find(ev, "DAMAGE") ~= nil then - Last_Attack_Source = source_name - end - end + print(...) + local _, subEvent, _, sourceGUID, sourceName, _, _, destGUID = CombatLogGetCurrentEventInfo() + if destGUID == PLAYER_GUID and sourceGUID ~= PLAYER_GUID and sourceName and subEvent:find("DAMAGE") then + Last_Attack_Source = sourceName end end From 72d84b57f1a6132db4cb5daf5f845d072eede90f Mon Sep 17 00:00:00 2001 From: cloudbells Date: Tue, 7 Dec 2021 14:07:55 +0100 Subject: [PATCH 3/4] Replaced spaces with tabs --- Hardcore.lua | 174 +++++++++++++++++++++++++-------------------------- 1 file changed, 86 insertions(+), 88 deletions(-) diff --git a/Hardcore.lua b/Hardcore.lua index ebadecd3..78e7cf6c 100644 --- a/Hardcore.lua +++ b/Hardcore.lua @@ -541,8 +541,8 @@ function Hardcore:UNIT_SPELLCAST_SUCCEEDED(...) end function Hardcore:PLAYER_ENTERING_WORLD() - isPlayerDead = UnitIsDeadOrGhost("player") - + isPlayerDead = UnitIsDeadOrGhost("player") + Hardcore_Frame:RegisterForDrag("LeftButton") Hardcore_Alerts_Button:SetText(Hardcore_Settings.notify and "Disable alerts" or "Enable alerts") @@ -568,58 +568,57 @@ function Hardcore:PLAYER_ALIVE() end function Hardcore:PLAYER_DEAD() - if not isPlayerDead then - if Last_Attack_Source == UnitName("pet") then -- If the pet died first, do nothing. - return - end - - -- Screenshot - C_Timer.After(PICTURE_DELAY, Screenshot) - - -- Update deaths - if #Hardcore_Character.deaths == 0 or (#Hardcore_Character.deaths > 0 and Hardcore_Character.deaths[#Hardcore_Character.deaths].player_alive_trigger ~= nil) then - table.insert(Hardcore_Character.deaths, { - player_dead_trigger = date("%m/%d/%y %H:%M:%S"), - player_alive_trigger = nil - }) - end - - -- Send message to guild - local playerGreet = GENDER_GREETING[UnitSex("player")] - local name = UnitName("player") - local _, _, classID = UnitClass("player") - local class = CLASSES[classID] - local level = UnitLevel("player") - local zone, mapID - if IsInInstance() then - zone = GetInstanceInfo() - else - mapID = C_Map.GetBestMapForUnit("player") - zone = C_Map.GetMapInfo(mapID).name - end - local messageFormat = "Our brave %s, %s the %s, has died at level %d in %s" - local messageString = messageFormat:format(playerGreet, name, class, level, zone) - - if not (Last_Attack_Source == nil) then - messageString = string.format("%s to a %s", messageString, Last_Attack_Source) - Last_Attack_Source = nil - end - - if not (recent_msg["text"] == nil) then - local playerPronoun = GENDER_POSSESSIVE_PRONOUN[UnitSex("player")] - messageString = string.format("%s. %s last words were \"%s\"", messageString, playerPronoun, recent_msg["text"]) - end - - SendChatMessage(messageString, "GUILD") - - -- Send addon message - local deathData = string.format("%s%s%s", level, COMM_FIELD_DELIM, mapID and mapID or "") - local commMessage = COMM_COMMANDS[3] .. COMM_COMMAND_DELIM .. deathData - if CTL then - CTL:SendAddonMessage("ALERT", COMM_NAME, commMessage, "GUILD") - end - isPlayerDead = true - end + if not isPlayerDead then + if Last_Attack_Source == UnitName("pet") then -- If the pet died first, do nothing. + return + end + + -- Screenshot + C_Timer.After(PICTURE_DELAY, Screenshot) + + -- Update deaths + if #Hardcore_Character.deaths == 0 or (#Hardcore_Character.deaths > 0 and Hardcore_Character.deaths[#Hardcore_Character.deaths].player_alive_trigger ~= nil) then + table.insert(Hardcore_Character.deaths, { + player_dead_trigger = date("%m/%d/%y %H:%M:%S"), + player_alive_trigger = nil + }) + end + + -- Send message to guild + local playerGreet = GENDER_GREETING[UnitSex("player")] + local name = UnitName("player") + local _, _, classID = UnitClass("player") + local class = CLASSES[classID] + local level = UnitLevel("player") + local zone, mapID + if IsInInstance() then + zone = GetInstanceInfo() + else + mapID = C_Map.GetBestMapForUnit("player") + zone = C_Map.GetMapInfo(mapID).name + end + local messageFormat = "Our brave %s, %s the %s, has died at level %d in %s" + local messageString = messageFormat:format(playerGreet, name, class, level, zone) + if not (Last_Attack_Source == nil) then + messageString = string.format("%s to a %s", messageString, Last_Attack_Source) + Last_Attack_Source = nil + end + + if not (recent_msg["text"] == nil) then + local playerPronoun = GENDER_POSSESSIVE_PRONOUN[UnitSex("player")] + messageString = string.format("%s. %s last words were \"%s\"", messageString, playerPronoun, recent_msg["text"]) + end + + SendChatMessage(messageString, "GUILD") + + -- Send addon message + local deathData = string.format("%s%s%s", level, COMM_FIELD_DELIM, mapID and mapID or "") + local commMessage = COMM_COMMANDS[3] .. COMM_COMMAND_DELIM .. deathData + if CTL then + CTL:SendAddonMessage("ALERT", COMM_NAME, commMessage, "GUILD") + end + isPlayerDead = true + end end function Hardcore:PLAYER_TARGET_CHANGED() @@ -647,7 +646,7 @@ function Hardcore:PLAYER_TARGET_CHANGED() end function Hardcore:PLAYER_UNGHOST() - isPlayerDead = false + isPlayerDead = false if UnitIsDeadOrGhost("player") == 1 then return end -- prevent message on ghost login or zone @@ -876,41 +875,40 @@ function Hardcore:CHAT_MSG_ADDON(prefix, datastr, scope, sender) end end -function Hardcore:COMBAT_LOG_EVENT_UNFILTERED(...) - print(...) +function Hardcore:COMBAT_LOG_EVENT_UNFILTERED() local _, subEvent, _, sourceGUID, sourceName, _, _, destGUID = CombatLogGetCurrentEventInfo() if destGUID == PLAYER_GUID and sourceGUID ~= PLAYER_GUID and sourceName and subEvent:find("DAMAGE") then - Last_Attack_Source = sourceName + Last_Attack_Source = sourceName end end function Hardcore:CHAT_MSG_SAY(...) if self:SetRecentMsg(...) then - recent_msg["type"] = 0 + recent_msg["type"] = 0 end end function Hardcore:CHAT_MSG_GUILD(...) if self:SetRecentMsg(...) then - recent_msg["type"] = 2 + recent_msg["type"] = 2 end end function Hardcore:CHAT_MSG_PARTY(...) if self:SetRecentMsg(...) then - recent_msg["type"] = 1 + recent_msg["type"] = 1 end end function Hardcore:SetRecentMsg(...) local text, sn, LN, CN, p2, sF, zcI, cI, cB, unu, lI, senderGUID = ... if PLAYERGUID == nil then - PLAYERGUID = UnitGUID("player") + PLAYERGUID = UnitGUID("player") end if senderGUID == PLAYERGUID then - recent_msg["text"] = text - return true + recent_msg["text"] = text + return true end return false end @@ -987,30 +985,30 @@ function Hardcore:ShowAlertFrame(styleConfig, message) end function Hardcore:Add(data, sender) - -- Display the death locally if alerts are not toggled off. - if Hardcore_Settings.notify then - local level = 0 - local mapID - if data then - level, mapID = string.split(COMM_FIELD_DELIM, data) - level = tonumber(level) - mapID = tonumber(mapID) - end - if type(level) == "number" then - for i = 1, GetNumGuildMembers() do - local name, _, _, guildLevel, _, zone, _, _, _, _, class = GetGuildRosterInfo(i) - if name == sender then - if mapID then - local mapData = C_Map.GetMapInfo(mapID) -- In case some idiot sends an invalid map ID, it won't cause mass lua errors. - zone = mapData and mapData.name or zone -- If player is in an instance, will have to get zone from guild roster. - end - level = level > 0 and level < 61 and level or guildLevel -- If player is using an older version of the addon, will have to get level from guild roster. - local messageFormat = "%s the %s%s|r has died at level %d in %s" - local messageString = messageFormat:format(name:gsub("%-.*", ""), "|c" .. RAID_CLASS_COLORS[class].colorStr, class, level, zone) - Hardcore:ShowAlertFrame(ALERT_STYLES.death, messageString) - end - end - end + -- Display the death locally if alerts are not toggled off. + if Hardcore_Settings.notify then + local level = 0 + local mapID + if data then + level, mapID = string.split(COMM_FIELD_DELIM, data) + level = tonumber(level) + mapID = tonumber(mapID) + end + if type(level) == "number" then + for i = 1, GetNumGuildMembers() do + local name, _, _, guildLevel, _, zone, _, _, _, _, class = GetGuildRosterInfo(i) + if name == sender then + if mapID then + local mapData = C_Map.GetMapInfo(mapID) -- In case some idiot sends an invalid map ID, it won't cause mass lua errors. + zone = mapData and mapData.name or zone -- If player is in an instance, will have to get zone from guild roster. + end + level = level > 0 and level < 61 and level or guildLevel -- If player is using an older version of the addon, will have to get level from guild roster. + local messageFormat = "%s the %s%s|r has died at level %d in %s" + local messageString = messageFormat:format(name:gsub("%-.*", ""), "|c" .. RAID_CLASS_COLORS[class].colorStr, class, level, zone) + Hardcore:ShowAlertFrame(ALERT_STYLES.death, messageString) + end + end + end end end From e62347f82ae795bc4b547eeb5d3b25a446e769f9 Mon Sep 17 00:00:00 2001 From: cloudbells Date: Tue, 7 Dec 2021 15:30:03 +0100 Subject: [PATCH 4/4] Removed death check on login --- Hardcore.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Hardcore.lua b/Hardcore.lua index 78e7cf6c..bba736c3 100644 --- a/Hardcore.lua +++ b/Hardcore.lua @@ -59,7 +59,7 @@ Hardcore_Character = { --[[ Local variables ]]-- local debug = false -local isPlayerDead -- Used to prevent double guild/addon messages. +local isPlayerDead = nil -- Used to prevent double guild/addon messages. local pulses = {} local alert_msg_time = { PULSE = {}, @@ -541,8 +541,6 @@ function Hardcore:UNIT_SPELLCAST_SUCCEEDED(...) end function Hardcore:PLAYER_ENTERING_WORLD() - isPlayerDead = UnitIsDeadOrGhost("player") - Hardcore_Frame:RegisterForDrag("LeftButton") Hardcore_Alerts_Button:SetText(Hardcore_Settings.notify and "Disable alerts" or "Enable alerts")