Thread Tools Display Modes
07-29-10, 03:22 PM   #1
duelle
A Murloc Raider
Join Date: Jul 2010
Posts: 6
Question Finding Mobs in fight and retrieving threat info

Hello,

I'm quite new to WoW-Lua-Programming and want to learn the rest of it "by doing".
I'm a part-time tank and would like to develop an addon that shows me a list of mobs that attack a party or raid member that is no tank.
So I can see whether there are untanked mobs.

I searched the WoW-API but did not find any function that can return me a list of mobs in fight.

Afterwards I need to retrieve threat information for each of them.
So far I found just a function that can give me aggro information if the mob is in my target/focus or so.

Could you give me any hints to solve those problems?

Thank you for your help!

Greetz
duelle
  Reply With Quote
07-29-10, 04:56 PM   #2
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
What you might do is scan for the GUID when you mouseover or target a mob (and/or when your partymembers target a mob), check if it has threat from someone in your party, and add it to a table.

You can use the UNIT_DIED subevent in COMBAT_LOG_EVENT_UNFILTERED to see when a mob dies.

Or you might like to try out the addon MagicTargets(http://wow.curse.com/downloads/wow-a...c-targets.aspx).

Last edited by ravagernl : 07-29-10 at 05:04 PM.
  Reply With Quote
07-29-10, 05:21 PM   #3
duelle
A Murloc Raider
Join Date: Jul 2010
Posts: 6
Lightbulb

Thank you for the fast reply.

Assuming one mob was "forgotten" by the tank and attacks a healer because of heal aggro. If nobody targets this mob it would never be in the list derived from targets/focuses/mouseovers isn't it?

Is there another way to find the mobs that are in fight?
Perhaps via the combat log or another WoW-API function?

In what extent could I use the UNIT_DIED event for that addon?
When it is dead I don't want to care about it or am I misunderstanding you?
  Reply With Quote
07-29-10, 05:32 PM   #4
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
When the mob is dead, you need to remove it from the list of mobs that you are tracking.

You can indeed find out about a mob attacking your healer via the combat log. Just see if the source GUID is not in your party and the destination GUID is in your party.

There's 2 functions to query for threat:
http://www.wowwiki.com/API_UnitThreatSituation
http://www.wowwiki.com/API_UnitDetailedThreatSituation
  Reply With Quote
07-29-10, 05:44 PM   #5
duelle
A Murloc Raider
Join Date: Jul 2010
Posts: 6
Post

Originally Posted by mrruben5 View Post
When the mob is dead, you need to remove it from the list of mobs that you are tracking.
That's for sure a very good point - didn't mention that yet^^

Originally Posted by mrruben5 View Post
You can indeed find out about a mob attacking your healer via the combat log. Just see if the source GUID is not in your party and the destination GUID is in your party.

There's 2 functions to query for threat:
http://www.wowwiki.com/API_UnitThreatSituation
http://www.wowwiki.com/API_UnitDetailedThreatSituation
As far as I understand that, I would parse the combat log for attacks of non-party/raid members on party/raid members ... retrieve their name/id and then check whether they are a tank. If not I would list the attacking mob as not being tanked.
Do you agree ?

Thanks a lot so far!

P.S.: Hope that my english is understandable - if not don't hesitate to ask .. then I'll try my best to explain it more exactly or in other words...

Last edited by duelle : 07-29-10 at 05:46 PM.
  Reply With Quote
07-29-10, 06:24 PM   #6
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Yes

To keep track of party GUID's you can register for the event PARTY_MEMBERS_CHANGED:

lua Code:
  1. local guidtounit = {}
  2.  
  3. function addon:PARTY_MEMBERS_CHANGED()
  4.     wipe(guidtounit)
  5.     guidtounit[UnitGUID('player')] = 'player'
  6.     if UnitExists('pet') do
  7.         guidtounit[UnitGUID('pet')] = 'pet'
  8.     end
  9.     for i= 1, GetNumPartyMembers() do
  10.         guidtounit[UnitGUID('party'..i)] = 'party'..i
  11.         if UnitExists('party'..i..'pet') do
  12.             guidtounit[UnitGUID('party'..i..'pet')] = 'party'..i..'pet'
  13.         end
  14.     end
  15. end
Or you could also check using http://wowprogramming.com/docs/api/CombatLog_Object_IsA

Last edited by ravagernl : 07-29-10 at 06:26 PM.
  Reply With Quote
07-29-10, 06:47 PM   #7
duelle
A Murloc Raider
Join Date: Jul 2010
Posts: 6
Post

Thank you a lot!

That's a great idea to store a list of all raid/group members.
I will play around with those things tomorrow (or later this day )

Just noting it down in here:
  • Every time the group changes refresh the [GUID -> unitId] table
  • Check the CombatLog for attacks of non-raid members on raid-members (which I luckily now have in a table )
  • If the attacked raid-member is not marked as a tank (or whatever gives the raid-member the right to tank a mob^^) add the attacking mob to a list
  • Display the list in some way (this will be the last step to take - gui )

Further notes concerning functions I will probably use:
  • UnitPlayerOrPetInRaid(uId) -> returns wheter the given uId is a player or pet in raid
  • UnitPlayerOrPetInParty(uId) -> same as above for party
  • guid = UnitGUID(uId) -> retrieves the GUID for the given unit
  • UnitDetailedThreatSituation
  • UnitThreatSituation

Gonna go to sleep now ... good night/morning
  Reply With Quote
07-29-10, 08:09 PM   #8
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
isTank, isHeal, isDPS = UnitGroupRolesAssigned(Unit);
  Reply With Quote
07-30-10, 04:21 AM   #9
duelle
A Murloc Raider
Join Date: Jul 2010
Posts: 6
Post

There's one further thing that came to my mind this morning:

Assuming there are two mobs with the same name.
One of them attacks my healer and one myself as tank.
Now my addon would get the guid and the name of the healer-attacking one.

But I can't target a mob via guid isn't it?
So eventually I would target the wrong one if I wrote a frame that allowed me to target the untanked one - because they both have the same name and therefore I can't really distinguish between them.

I thought about creating a list of mobs as I have a list of raid/party members - but that does not solve the problem above.

Which would be the easiest way to check wheter I'm in party or in raid?
Perhaps via the member count?

You gave me the hint
Code:
isMatch = CombatLog_Object_IsA(unitFlags, mask)
I understand what it does - but don't understand how to use it yet.
Because I don't really know where to pass it one Combatlog-"Line" it should filter.

Last edited by duelle : 07-30-10 at 04:31 AM.
  Reply With Quote
08-02-10, 09:27 AM   #10
duelle
A Murloc Raider
Join Date: Jul 2010
Posts: 6
Post

Hi,

I started programming the last days.

UPDATE:
The most important functions seem to work - except the slash command which is currently not that important though.

The question from the post before is still open: Can I form a targetting command that uses the guid so I can identify a mob out of multiple mobs with the same name?

The code can of course be optimized a lot ... additionaly I need to add a check whether the attacked unit is tank or not.

Here is the code:
lua Code:
  1. local prefix = "[DX-LostMobs]";
  2. local outputChannel =  "SAY";
  3.  
  4. SLASH_DX_LM_1 = "/lm";
  5. SLASH_DX_LM_2 = "/lostmobs";
  6.  
  7. --SlashCmdList["DX_LOST_MOBS"] = function(msg)
  8. --  print(prefix..msg);
  9. -- end;
  10.  
  11. local LostMobs = {};
  12. guidtounit = {};
  13. guidtomob = {};
  14. untanked = {};
  15. local srcGuid,srcName,tarGuid,tarName;
  16.  
  17. function onEvent(self,event,...)
  18.   local temp,_  = select(2,...);
  19.   if event == "COMBAT_LOG_EVENT_UNFILTERED" then
  20.     if temp == "UNIT_DIED" then
  21.       --return onEvent(self,select(2,...),...);
  22.       print("Some unit died - checking moblist....");
  23.       UnitDied(event,...);
  24.     else
  25.       return ParseCombatLog(select(3,...));
  26.     end;
  27.   elseif event == "PARTY_MEMBERS_CHANGED" then
  28.     return PartyMembersChanged();
  29.   end;
  30. end;
  31.  
  32. function ParseCombatLog(...)
  33.  
  34.   srcGuid,srcName,_,tarGuid,tarName,_ = ...;
  35.   if (not IsRaidOrPartyMember(srcGuid)) and IsRaidOrPartyMember(tarGuid) then
  36.     if not guidtomob[srcGuid] then
  37.       guidtomob[srcGuid] = srcName;
  38.     end;
  39.     print(prefix..srcName.." is attacking "..tarName);
  40.   end;
  41. end;
  42.  
  43. function IsRaidOrPartyMember(id)
  44.   if guidtounit[id] or guidtounit[UnitGUID(id)] then
  45.     return 1;
  46.   else
  47.     return nil;
  48.   end;
  49. end;
  50.  
  51.  
  52. function UnitDied(event,...)
  53.  
  54.   local guid,name,_ = select(6,...);
  55.  
  56.   if not (UnitPlayerOrPetInRaid(guid) or UnitPlayerOrPetInParty(guid)) then
  57.     print(guidtomob);
  58.     tremoveKey(guidtomob,guid);
  59.     print(guidtomob);
  60.   end;
  61. end;
  62.  
  63.  
  64. function PartyMembersChanged()
  65.   print("Something changed within the group!");
  66.   wipe(guidtounit);
  67.   guidtounit[UnitGUID('player')] = 'player';
  68.   if UnitExists('pet') then
  69.       guidtounit[UnitGUID('pet')] = 'pet';
  70.   end;
  71.   for i= 1, GetNumPartyMembers() do
  72.       guidtounit[UnitGUID('party'..i)] = 'party'..i;
  73.       if UnitExists('party'..i..'pet') then
  74.           guidtounit[UnitGUID('party'..i..'pet')] = 'party'..i..'pet';
  75.       end;
  76.   end;
  77.   print(prefix.."Party-Data updated - "..#guidtounit.." Members in list");
  78. end;
  79.  
  80. function tremoveKey(table,key)
  81.   local element = table[key];
  82.   table[key] = nil;
  83.   return element;
  84. end;
  85.  
  86.  
  87. local frame = CreateFrame("Frame");
  88. frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
  89. frame:RegisterEvent("PARTY_MEMBERS_CHANGED");
  90. frame:SetScript("onEvent",onEvent);

Last edited by duelle : 08-02-10 at 11:27 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Finding Mobs in fight and retrieving threat info


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