Thread Tools Display Modes
02-01-24, 09:59 AM   #1
Kajuvra
A Murloc Raider
Join Date: Feb 2024
Posts: 4
Printing when a player has died in raid chat.

So in my race addon its important to know when someone dies and have that announced to raid chat by the raid leader and i think im going about this all wrong.

In the OnPlayerDead function:
It checks if a race is in progress (GnomeRunner.raceInProgress).
If a race is in progress, it announces the player's death using GnomeRunner.AnnouncePlayerDeath(playerName) in the raid chat.
It also sends an addon message (PLAYER_DEAD: playerName) to the raid leader using C_ChatInfo.SendAddonMessage.
This way, when a player dies, the addon both announces it in the raid chat and sends an addon message to the raid leader. The raid leader's addon can then listen for these messages and handle them accordingly.

Code:
-- New function to announce player deaths in raid chat
function GnomeRunner.AnnouncePlayerDeath(playerName)
    SendChatMessage(playerName .. " has died!", "RAID")
end
Code:
-- Modify the existing OnPlayerDead function
function GnomeRunner.OnPlayerDead()
    GnomeRunner.CheckPlayer()

    if GnomeRunner.raceInProgress then
        local playerName = UnitName("player")

        if UnitIsGroupLeader("player") then
            GnomeRunner.AnnouncePlayerDeath(playerName) -- Announce player death in raid chat
        else
            C_ChatInfo.SendAddonMessage (GnomeRunner.addonPrefix, "PLAYER_DEAD:" .. playerName, "WHISPER", GnomeRunner.raidLeader)
        end

        GnomeRunner.totalDeaths = GnomeRunner.totalDeaths + 1
    end
end
  Reply With Quote
02-01-24, 12:08 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
You can use PLAYER_DEAD when the user has died. For raid/party members, I'd rather track their health by UNIT_HEALTH to detect if/when they die than rely on addon messages. It's hardly secure by any means. Any knowledgeable user can block them or send fake messages. If you insist on using addon chat messages, at least check using the sender name from CHAT_MSG_ADDON instead of including it in the message. At the very least, it'll provide a barrier from one person sending a message that a competitor has died.

I speak from experience of having made an addon message sniffer tool specifically to monitor messages going in and out of the local machine as part of a development toolkit.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
02-02-24, 06:34 AM   #3
Kajuvra
A Murloc Raider
Join Date: Feb 2024
Posts: 4
i still don't think im doing this right. Please forgive me this is my first time coding in Lua. Now the player see's the Debug message in that they died but its just got getting back to the raid leader so they can tell the raid someone died while updating how many people have died so far if you'd like to review the entire code https://github.com/kajuvra/GnomeRunner/


Code:
C_ChatInfo.RegisterAddonMessagePrefix(GnomeRunner.addonPrefix)
Code:
function GnomeRunner.OnUnitHealth(unit)
    if unit == "player" and UnitHealth("player") == 0 then
        -- Player has died, trigger death announcement
        print("DEBUG: Player has died!")
        GnomeRunner.OnPlayerDead()
    end
end
Code:
-- Part of the code to receive the message and play the sound
function GnomeRunner.OnChatMsgAddon(prefix, message, channel, sender)
    if prefix == GnomeRunner.addonPrefix then
        print("Addon message received:", message)

        if message == "START_RACE" then
            print("Received START_RACE. Playing sound.")
            PlaySoundFile(GnomeRunner.soundFile)
        elseif message == "START_RACE_SOUND" then
            PlaySoundFile(GnomeRunner.soundFile)
        elseif strmatch(message, "PLAYER_DEAD:") then
            -- Add debug message for receiving PLAYER_DEAD message
            print("Received PLAYER_DEAD message.")
            local _, deadPlayer = strsplit(":", message)
            GnomeRunner.AnnouncePlayerDeath(deadPlayer)
        end
    end
end

function GnomeRunner.OnPlayerDead()
    if GnomeRunner.raceInProgress then
        if not GnomeRunner.lastDeadPlayer or not GnomeRunner.lastDeadPlayerHealth then
            print("Error: Unable to retrieve player name or health for death announcement.")
            return
        end

        if UnitIsGroupLeader("player") then
            GnomeRunner.AnnouncePlayerDeath(GnomeRunner.lastDeadPlayer)
            -- Add debug message for sending PLAYER_DEAD message
            print("Sending PLAYER_DEAD message.")
            C_ChatInfo.SendAddonMessage(GnomeRunner.addonPrefix, "PLAYER_DEAD:" .. GnomeRunner.lastDeadPlayer, "RAID")  -- Add this line to broadcast the death to the raid
        else
            C_ChatInfo.SendAddonMessage(GnomeRunner.addonPrefix, "PLAYER_DEAD:" .. GnomeRunner.lastDeadPlayer, "WHISPER", GnomeRunner.raidLeader)
            -- Add debug message for sending PLAYER_DEAD message
            print("Sending PLAYER_DEAD message to raid leader.")
        end

        GnomeRunner.totalDeaths = GnomeRunner.totalDeaths + 1
    end
end

-- New function to announce player deaths in raid chat
function GnomeRunner.AnnouncePlayerDeath(playerName)
    SendChatMessage(playerName .. " has died!", "RAID")
end

Last edited by Kajuvra : 02-03-24 at 12:48 AM.
  Reply With Quote
02-03-24, 12:35 AM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
I don't see anything standing out at the moment. I'd suggest making sure you have error alerts turned on, I think they're off by default.
The command is /console scriptErrors 1



PS:
"Lua" (pronounced LOO-ah) means "Moon" in Portuguese. As such, it is neither an acronym nor an abbreviation, but a noun. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!
-Lua: about - Lua.org
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 02-03-24 at 12:43 AM.
  Reply With Quote
02-03-24, 06:13 AM   #5
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
You could also see if Bugsack and Buggrabber find anything.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
02-03-24, 06:18 AM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
Have you tested that part with it whispering *player* to see if it whispers back to you ( assuming you are testing it ). If that appears to work in place of the GnomeRunner.raidLeader value. Have you double checked that that value equates to a valid value for the command ?
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Printing when a player has died in raid chat.


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off