View Single Post
05/03/14, 11:38 AM   #6
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
This code probably looks a bit better:

Lua Code:
  1. local bossCount = 0
  2. local bossUnitTags = {}
  3. for i = 1, MAX_BOSSES do         --global constant MAX_BOSSES = 6
  4.    bossTags[i] = "boss" .. i
  5. end
  6.  
  7. local function OnBossesChanged()
  8.    bossCount = 0
  9.    for i, bossTag in ipairs(bossUnitTags) do
  10.       if DoesUnitExist(bossTag) then
  11.          bossCount = bossCount + 1
  12.       end
  13.    end
  14. end
  15.  
  16. EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_BOSSES_CHANGED, OnBossesChanged)
  17.  
  18. --returns true if unit is boss
  19. function IsUnitBoss(unitTag)
  20.    if bossCount > 0 and unitTag ~= nil then
  21.       for i, bossTag in ipairs(bossUnitTags) do
  22.          if GetUnitName(unitTag) == GetUnitName(bossTag) then
  23.             return true
  24.          end
  25.       end
  26.    end
  27.    
  28.    return false
  29. end
  Reply With Quote