WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Simple addon classic (https://www.wowinterface.com/forums/showthread.php?t=58267)

Zarzar290 10-12-20 11:51 AM

Simple addon classic
 
In our guild we have a player who dies a lot, it's a running joke in our raids now. I'm looking to get an addon that will only work during raids and will announce in raid warning "(Player name) has died. This is his (total number of deaths) death" so it will have to keep track of how many times he has died. I have no idea where to start and any help would be greatly appreciated.

DahkCeles 10-12-20 03:02 PM

Perhaps try the addon "Recount". It won't automatically spam the chat as the person dies, but it will track deaths on one of its pages and you can broadcast that to chat.

To build it yourself, take a look at: https://wow.gamepedia.com/COMBAT_LOG...Special_Events

SDPhantom 10-13-20 11:09 PM

Sounds familiar. :rolleyes:

Cheekiness aside, there are a few ways to detect a party/raid member's death.

I would actually watch UNIT_HEALTH and react when UnitHealth() returns zero. The combat log has a limited range and can miss deaths if they happen far away.

I may be tempted to make this myself whenever I find the time just for the fun of it.

gmarco 10-14-20 03:54 AM

Hi,

if you do it I'll surely install it :)

Thanks :)

SDPhantom 10-14-20 08:36 AM

I have some prototype code. Right now, it reports everyone.
Lua Code:
  1. local DeathCounter,DeathData,PlayerGUID=CreateFrame("Frame"),{},UnitGUID("player");
  2. DeathCounter:RegisterEvent("GROUP_ROSTER_UPDATE");
  3. DeathCounter:SetScript("OnEvent",function(self,event,unit)
  4.     if event=="GROUP_ROSTER_UPDATE" then
  5.         if IsInRaid(LE_PARTY_CATEGORY_HOME) and not IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then--    Check for raid, but not battleground
  6.             for guid in next,DeathData do-- Remove members when they leave
  7.                 if guid~=PlayerGUID and not IsGUIDInGroup(guid) then
  8.                     DeathData[guid]=nil;--  Cleanup if no longer in group
  9.                 end
  10.             end
  11.             self:RegisterEvent("UNIT_HEALTH");--    Activate death watch (doesn't matter if it's already active)
  12.         else--  No longer in a valid group
  13.             table.wipe(DeathData);--    Clear all raid members
  14.             self:UnregisterEvent("UNIT_HEALTH");--  Deactivate death watch (saves performance)
  15.         end
  16.     elseif event=="UNIT_HEALTH" then
  17.         local guid,dead=UnitGUID(unit),UnitIsDead(unit);
  18.         if guid==PlayerGUID or IsGUIDInGroup(guid) then
  19.             local data=DeathData[guid]; if data then
  20.                 if dead and not data.WasDead then-- TLDR: Did unit just die?
  21.                     data.Deaths=data.Deaths+1;--    Increment deaths
  22.                     if UnitIsGroupLeader("player") or UnitIsGroupAssistant("player") then-- Can't send RAID_WARNING if not either of these
  23.                         SendChatMessage(("DeathCounter: %s has died %d time(s) so far."):format(UnitName(unit),data.Deaths),"RAID_WARNING");
  24.                     end
  25.                 end
  26.                 data.WasDead=dead;--    Update living state
  27.             else DeathData[guid]={WasDead=dead,Deaths=0}; end-- Using the first health update to initialize data (if they join while dead, it doesn't count)
  28.         end
  29.     end
  30. end);



PS: I may be one of those.
All I can say is I make the other casters go...

Zarzar290 10-15-20 09:11 AM

Thanks for the replies everyone. SDPhantom that looks great! Is there anyway I can edit it to only watch the health of one person in the raid?

SDPhantom 10-16-20 03:49 AM

This one takes a slightly different approach and lets you add/remove players with slash commands.
Lua Code:
  1. local DeathCounter,DeathData,PlayerGUID=CreateFrame("Frame"),{},UnitGUID("player");
  2. DeathCounter:SetScript("OnEvent",function(self,event,unit)
  3.     if event=="GROUP_ROSTER_UPDATE" then
  4.         if IsInGroup() and not IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then-- Check for party/raid, but not battleground
  5.             for guid,data in pairs(DeathData) do--  Remove members when they leave
  6.                 if guid~=PlayerGUID and not IsGUIDInGroup(guid) then
  7.                     DeathData[guid]=nil;--  Cleanup if no longer in group
  8.                     print(("%s was removed from watch list."):format(data.Name));
  9.                 end
  10.             end
  11.  
  12.             if not next(DeathData) then self:UnregisterAllEvents(); end--   Disable if empty
  13.         else--  No longer in a valid group
  14.             table.wipe(DeathData);--    Clear all raid members
  15.             self:UnregisterAllEvents();--   Disable
  16.             print("Watch list cleared.");
  17.         end
  18.     elseif event=="UNIT_HEALTH" then
  19.         local guid,dead=UnitGUID(unit),UnitIsDead(unit);
  20.         local data=DeathData[guid]; if data then
  21.             if dead and not data.WasDead then-- TLDR: Did unit just die?
  22.                 data.Deaths=data.Deaths+1;--    Increment deaths
  23.                 if not IsInRaid() or UnitIsGroupLeader("player") or UnitIsGroupAssistant("player") then--   Can't send RAID_WARNING if not either of these
  24.                     SendChatMessage(("DeathCounter: %s has died %d time(s)."):format(UnitName(unit),data.Deaths),"RAID_WARNING");
  25.                 end
  26.             end
  27.             data.WasDead=dead;--    Update living state
  28.         end
  29.     end
  30. end);
  31.  
  32. function SlashCmdList.DEATHCOUNTER_ADDUNIT(unit)
  33. --  Test Group
  34.     if not IsInGroup() then print("You must be in a party/raid to use this command."); return; end
  35.     if IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then print("You cannot use this command in a battleground."); return; end
  36.  
  37. --  Test Unit
  38.     if (unit or "")=="" then unit="target"; end
  39.     if not (UnitIsPlayer(unit) and (UnitInParty(unit) or UnitInRaid(unit))) then print("Unit must be a player in your party/raid."); return; end
  40.  
  41.     if IsInRaid() and not (UnitIsGroupLeader("player") or UnitIsGroupAssistant("player")) then
  42.         print("Warning: Raid warnings can only be sent by a raid leader or assistant.\nDeaths will still be counted.");
  43.     end
  44.  
  45.     local name,guid=UnitName(unit),UnitGUID(unit);
  46.     if not DeathData[guid] then
  47.         DeathData[guid]={Name=name,WasDead=UnitIsDead(unit),Deaths=0};--    Add unit
  48.         DeathCounter:RegisterEvent("GROUP_ROSTER_UPDATE");--    Register group changes
  49.         DeathCounter:RegisterEvent("UNIT_HEALTH");--    Enable death watch
  50.         print(("Now watching %s."):format(name));
  51.     else print(("Already watching %s."):format(name)); end
  52. end
  53. SLASH_DEATHCOUNTER_ADDUNIT1="/dcadd";
  54.  
  55. function SlashCmdList.DEATHCOUNTER_REMUNIT(unit)
  56.     if (unit or "")=="" then unit="target"; end
  57.     if not next(DeathData) then print("Watch list is empty."); return; end
  58.     if not UnitIsPlayer(unit) then print("Unit must be a player."); return; end
  59.  
  60.     local name,guid=UnitName(unit),UnitGUID(unit);
  61.     if DeathData[guid] then
  62.         DeathData[guid]=nil;--  Remove entry
  63.         if not next(DeathData) then DeathCounter:UnregisterAllEvents(); end--   Disable if empty
  64.         print(("%s was removed from watch list."):format(name));
  65.     else print(("%s not found in watch list."):format(name)); end
  66. end
  67. SLASH_DEATHCOUNTER_REMUNIT1="/dcrem";
  68.  
  69. function SlashCmdList.DEATHCOUNTER_CLEAR()
  70.     if next(DeathData) then
  71.         table.wipe(DeathData);--    Clear
  72.         DeathCounter:UnregisterAllEvents();--   Disable
  73.         print("Watch list cleared.");
  74.     else print("Watch list is empty."); end
  75. end
  76. SLASH_DEATHCOUNTER_CLEAR1="/dcclr";

Usage:
/dcadd unit - Adds unit to list of players being watched.
/dcrem unit - Removes unit from list of players being watched.
/dcclr - Clears watch list.

Notes: Only players in your party/raid can be added to the watch list. They will be automatically removed if they leave the group. The list is also cleared if you leave the group. Even though these commands are written to take a UnitID, keep in mind the names of players in your party/raid are also valid UnitIDs.

gmarco 10-16-20 09:49 PM

Hi SDPhantom,

I have packed your code in an addon and I am using without error.

Some questions:

1) Is it supposed to run in retail too ? I play retail and I have no errors, but I was not in a raid yet :)

2) Does this line:
Lua Code:
  1. if IsInGroup() and not IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then -- Check for party/raid, but not battleground

include also the dungeon 5 man and m+ and the addon is supposed to track deaths in these ?


3) Is it possible to print a summary of all deaths ?

Thanks :)

SDPhantom 10-17-20 04:08 AM

Quote:

Originally Posted by gmarco (Post 337237)
1) Is it supposed to run in retail too ? I play retail and I have no errors, but I was not in a raid yet :)

It was coded with Classic in mind, where the Battleground groups piggyback off Instance groups.



Quote:

Originally Posted by gmarco (Post 337237)
2) Does this line:
Lua Code:
  1. if IsInGroup() and not IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then -- Check for party/raid, but not battleground

include also the dungeon 5 man and m+ and the addon is supposed to track deaths in these ?

The difference isn't as much the kind of content you run, but the type of group you run with. A Home group is when you make a premade group and walk into an instance to run it. Instance groups are formed when you queue into the LFD/LFR system.



Quote:

Originally Posted by gmarco (Post 337237)
3) Is it possible to print a summary of all deaths ?

Not in its current state. The first version adds members as they join your group and removes them when they leave. The data only persists as long as the member is in your group, which makes it difficult for summaries to be shown if someone leaves before you display it. The second version relies on the user to manually add members to track as per request of the OP. Just like the previous version, it also removes these members when they leave.

gmarco 10-17-20 04:38 AM

Ah ,

I have missed this :)

Quote:

The second version relies on the user to manually add members to track as per request of the OP. Just like the previous version, it also removes these members when they leave.
So if I want to track all the deaths of the group I should use the version 1 ?

About question nr.2:

So, in retail, if I leave:
Lua Code:
  1. if IsInGroup() and not IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then

It is disabled only in LFR, not in the group finder we usually use to make m+ (Dungeons & Raids --> Premade Groups --> Dungeons) .

About question nr.3:

The v1 automagically adds members as they join my party (group) and remove them as they leave.
The v2 need the members to be added manually with the / command.

Is possible print a summary of the table death for the member that are currently tracked (the ones in the group for v1 and the manually added for the v2 when they are in the group :) ? If one meber leave I lost him in the summary but I am fine to print the numbers of others party member :)

Thanks.

gmarco 10-17-20 04:52 AM

Hi again...

just to adds functionality could be done that in the default state it starts in v1, but when we used a manual add it commute to version v2 wiping all the data and track only the manual ones ? :)

Then the problem is to return in the v1 :) with another command ? :))
/dcmode auto ?
/dcadd auto|groups|party ?

Thanks :)

SDPhantom 10-17-20 06:26 AM

Quote:

Originally Posted by gmarco (Post 337244)
So, in retail, if I leave:
Lua Code:
  1. if IsInGroup() and not IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then

It is disabled only in LFR, not in the group finder we usually use to make m+ (Dungeons & Raids --> Premade Groups --> Dungeons) .

Correct.


Quote:

Originally Posted by gmarco (Post 337244)
The v1 automagically adds members as they join my party (group) and remove them as they leave.
The v2 need the members to be added manually with the / command.

Is possible print a summary of the table death for the member that are currently tracked (the ones in the group for v1 and the manually added for the v2 when they are in the group :) ? If one member leave I lost him in the summary but I am fine to print the numbers of others party member :)

Sure. You'll probably want to add the player's name to the table since I don't recall a way to retrieve it using just their GUID.



Quote:

Originally Posted by gmarco (Post 337245)
just to adds functionality could be done that in the default state it starts in v1, but when we used a manual add it commute to version v2 wiping all the data and track only the manual ones ? :)

The functional difference between the two is line 27 of v1 and line 28 of v2. You'll also want to go over the group update logic to make sure the events are registered when you want them to. v1 has GROUP_ROSTER_UPDATE registered permanently and switches UNIT_HEALTH based on group type while v2 switches both events based on if there's anyone in the watch list.

PS: I would be wary of how spammy v1 can get on a raid wipe if you keep the raid warning message intact.

gmarco 10-17-20 08:02 AM

Hi SdPhantom,

thanks for the reply ... are you sure about the lines 27 and 28 of v1 and v2 ?

I read them in the code above :)

Thanks.

SDPhantom 10-18-20 02:16 AM

Quote:

Originally Posted by gmarco (Post 337251)
thanks for the reply ... are you sure about the lines 27 and 28 of v1 and v2 ?

Notice how I said functionally different, meaning between the two, that else clause is the difference between auto-registering members and not. I also pointed out that the event logic was changed between the two in order to support the difference between the manual and automatic methods.

Aside from those, v2 has more status messages to make it more user-friendly and had lightened the group restriction to include party.

Zarzar290 10-18-20 07:09 PM

The addon doesn't seem to be working for me. The slash commands just say type /help for a listing of a few commands. Doesn't seem to be picking up the addon. Not sure why.

SDPhantom 10-19-20 12:02 AM

Quote:

Originally Posted by Zarzar290 (Post 337300)
The addon doesn't seem to be working for me. The slash commands just say type /help for a listing of a few commands. Doesn't seem to be picking up the addon. Not sure why.

Line 51 was missing an end parenthesis, this was fixed.


All times are GMT -6. The time now is 05:59 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI