WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   List of units in combat with me (https://www.wowinterface.com/forums/showthread.php?t=55969)

Eungavi 01-12-18 05:18 PM

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

Ammako 01-12-18 06:16 PM

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.

Eungavi 01-12-18 08:08 PM

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 :(

MunkDev 01-12-18 08:52 PM

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.

semlar 01-12-18 09:02 PM

Quote:

Originally Posted by MunkDev (Post 326469)
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.

Lolzen 01-13-18 09:19 AM

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

Eungavi 01-13-18 04:00 PM

So, the best would still be analyzing the COMBAT_LOG_EVENT_UNFILTERED. That would be super exciting, but super complex at the same time :p

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

Thanks guys!!

-Engavi


All times are GMT -6. The time now is 11:37 AM.

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