Thread Tools Display Modes
01-12-18, 05:18 PM   #1
Eungavi
A Theradrim Guardian
Join Date: Nov 2017
Posts: 64
List of units in combat with me

Hiya!

Title says pretty much all.
Can you get a list of units in combat with me? To be honest, I know you can use a nameplate to search for units, but AFAIK this can only be done if the nameplate is enabled (visible). Thus I would like to ask if there is any other technique to obtain the list.

-Engavi

Last edited by Eungavi : 01-12-18 at 05:22 PM.
  Reply With Quote
01-12-18, 06:16 PM   #2
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
Looks like you might be able to use the combat log

http://www.wowinterface.com/forums/s...ad.php?t=34248

From 2010, but the idea is to scan the combat log for attacks that have you as the destination.
It wouldn't tell you about units that have aggroed on you but haven't attacked you, however. If you're in a party you can probably do as that thread says and also scan for enemies attacking party members, since that would normally put you in combat with them as well.
  Reply With Quote
01-12-18, 08:08 PM   #3
Eungavi
A Theradrim Guardian
Join Date: Nov 2017
Posts: 64
Thank you Ammako

But, doesn't being aggroed also mean that I'm in a combat? That's bit sad it won't track those units
  Reply With Quote
01-12-18, 08:52 PM   #4
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Register for UNIT_THREAT_LIST_UPDATE, then use UnitThreatSituation('player', unit), where unit is supplied as the first argument by the event.
Seems redundant to be scanning the combat log for something like this.
__________________
  Reply With Quote
01-12-18, 09:02 PM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by MunkDev View Post
Register for UNIT_THREAT_LIST_UPDATE, then use UnitThreatSituation('player', unit), where unit is supplied as the first argument by the event.
Seems redundant to be scanning the combat log for something like this.
That will only work for units with a valid UnitID like your target or mouseover.

The closest you can get to tracking what you're in combat with is to monitor the combat log for every hostile interaction between your group and enemies, storing their GUID in a table, and purging units when they die or haven't been seen within a certain timeframe.
  Reply With Quote
01-13-18, 09:19 AM   #6
Lolzen
An Aku'mai Servant
 
Lolzen's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 36
i've come up with this solution

Lua Code:
  1. -- Search a table for a specific entry
  2. -- see [url]https://stackoverflow.com/questions/33510736/check-if-array-contains-specific-value[/url]
  3. function ns.contains(table, val)
  4.     for i=1, #table do
  5.         if table[i] == val then
  6.             return true
  7.         end
  8.     end
  9.     return false
  10. end
  11.  
  12. -- Seach a table for a specific entry and return it's indes number
  13. -- see [url]https://scriptinghelpers.org/questions/10051/is-there-a-way-to-remove-a-value-from-a-table-without-knowing-its-index[/url]
  14. -- under Linear Search
  15. function ns.tablefind(tab,el)
  16.     for index, value in pairs(tab) do
  17.         if value == el then
  18.             return index
  19.         end
  20.     end
  21. end
  22.  
  23. -- Determine if any partymember is in Combat
  24. local inCombat = {}
  25. function ns.checkPartyCombat()
  26.     for name in pairs(ns.data.current) do
  27.         if UnitAffectingCombat(name) then
  28.             if not ns.contains(inCombat, name) then
  29.                 tinsert(inCombat, name)
  30.             end
  31.         else
  32.             if ns.contains(inCombat, name) then
  33.                 tremove(inCombat, ns.tablefind(inCombat, name))
  34.             end
  35.         end
  36.     end
  37.     if table.getn(inCombat) > 0 then
  38.         return true
  39.     else
  40.         return false
  41.     end
  42. end

where ns.data.current is a table that is filled per COMBAT_LOG_EVENT_UNFILTERED and emptied on PLAYER_REGEN_ENABLED
in this case we can now check ns.checkPartyCombat() which returns either true or false.

for reference here's the whole thing core.lua
  Reply With Quote
01-13-18, 04:00 PM   #7
Eungavi
A Theradrim Guardian
Join Date: Nov 2017
Posts: 64
So, the best would still be analyzing the COMBAT_LOG_EVENT_UNFILTERED. That would be super exciting, but super complex at the same time

Guess I'll have to take a time to study it.

Thanks guys!!

-Engavi
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » List of units in combat with me

Thread Tools
Display Modes

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