View Single Post
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