Sauerkraut

ncSpellAlert.lua

Jun 28th, 2011
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.21 KB | None | 0 0
  1. --------------------------------------------------------------------------------------------
  2. -- ncSpellAlert was written by Nightcracker, and is updated, and maintained by Sauerkraut --
  3. --------------------------------------------------------------------------------------------
  4.  
  5. local ncSpellalert = CreateFrame("Frame", "ncSpellalert")  
  6. local band, bor = bit.band, bit.bor
  7. local enemy = bor(COMBATLOG_OBJECT_REACTION_HOSTILE, COMBATLOG_OBJECT_TYPE_PLAYER)
  8.  
  9.  
  10. -- Spell filter for various buffs/spells
  11. -- Why not place in config with others? [ADD TO TO DO LIST]
  12. local deathcoil = GetSpellInfo(47541)
  13. local special = {
  14.     [GetSpellInfo(42292)] = 1,  --  pvp trinket
  15.     [GetSpellInfo(7744)] = 2,   -- Will of the Forsaken (Undead Racial)
  16.     [GetSpellInfo(57073)] = 3,  -- Drinking
  17.     [GetSpellInfo(59752)] = 4,  -- Every Man for Himself (Human Racial)
  18. }
  19.  
  20.  
  21. -- Determine if enemy, and class color text
  22. local function isenemy(flags) return band(flags, enemy)==enemy end
  23. local function tohex(val) return string.format("%.2x", val) end
  24. local function getclasscolor(class) local color = RAID_CLASS_COLORS[class] if not color then return "ffffff" end return tohex(color.r*255)..tohex(color.g*255)..tohex(color.b*255) end
  25. local function colorize(name) if name then return "|cff"..getclasscolor(select(2,UnitClass(name)))..name.."|r" else return nil end end
  26.  
  27.  
  28. local function createmessageframe(name)
  29.     local f = CreateFrame("MessageFrame", name, UIParent)
  30.     f:SetPoint("LEFT", UIParent)
  31.     f:SetPoint("RIGHT", UIParent)
  32.     f:SetHeight(25)
  33.     f:SetInsertMode("TOP")
  34.     f:SetFrameStrata("HIGH")
  35.     f:SetTimeVisible(1)
  36.     f:SetFadeDuration(3)
  37.     f:SetFont(STANDARD_TEXT_FONT, 23, "OUTLINE")
  38.     return f
  39. end
  40.  
  41.  
  42. -- Creates the frame to output Spell and Buff Alert messages
  43. local spell = createmessageframe("SpellAlertFrame")
  44. spell:SetPoint("TOP", 0, -200)
  45. local buff = createmessageframe("BuffAlertFrame")
  46. buff:SetPoint("BOTTOM", spell, "TOP", 0, 2)
  47.  
  48.  
  49. -- Is PVP only selected in the Config?
  50. function ncSpellalert:PLAYER_LOGIN()
  51.     if ncSpellalertDB.CONFIG.pvponly then
  52.         self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
  53.         self:ZONE_CHANGED_NEW_AREA()
  54.     else
  55.         self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  56.         self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
  57.     end
  58.     self:UnregisterEvent("PLAYER_LOGIN")
  59. end
  60.  
  61. -- Set to only be active while in PVP zones, such as BGs, or Arenas unless selected in config
  62. function ncSpellalert:ZONE_CHANGED_NEW_AREA()
  63.     local pvp = GetZonePVPInfo()
  64.     if not pvp or pvp ~= "sanctuary" then
  65.         self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  66.         self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
  67.     else
  68.         self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  69.         self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
  70.     end
  71. end
  72.  
  73.  
  74. -- If allunits is set to false, this decides which units to track
  75. local function isallowedunit(guid)
  76.     for key, val in pairs(ncSpellalertDB.CONFIG.units) do
  77.         if UnitGUID(unit, val) then return true end
  78.     end
  79.     return false
  80. end
  81.  
  82.  
  83. -- Scans combat log for enemy spellcasts/heals and casted buffs/debuffs
  84. function ncSpellalert:COMBAT_LOG_EVENT_UNFILTERED(event, timestamp, eventType, hideCaster, sourceGUID, sourcename, sourceFlags, sourceFlags2, destGUID, destname, destFlags, destFlags2, spellid, spellname)
  85.     if (spellname==deathcoil and select(2, UnitClass(sourceGUID))=="DEATHKNIGHT") or spellid == 59752 or spellid == 42292 or spellid == 7744 then return end -- ignores
  86.  
  87.     if eventType == "SPELL_AURA_APPLIED" and ncSpellalertDB.BUFF_SPELLS[spellname] and isenemy(destFlags) and (ncSpellalertDB.CONFIG.allunits or isallowedunit(destGUID)) then
  88.         buff:AddMessage(format(ACTION_SPELL_AURA_APPLIED_BUFF_FULL_TEXT_NO_SOURCE, nil, "|cff00ff00"..spellname.."|r", nil, colorize(destname)))
  89.     elseif eventType == "SPELL_CAST_START" and isenemy(sourceFlags) and (ncSpellalertDB.CONFIG.allunits or isallowedunit(sourceGUID)) then
  90.         local color    
  91.        
  92.         if ncSpellalertDB.HARMFUL_SPELLS[spellname] then
  93.             color = "ff0000"
  94.         elseif ncSpellalertDB.HEALING_SPELLS[spellname] then
  95.             color = "ffff00"
  96.         end
  97.        
  98.         if color then
  99.             local template
  100.             if sourcename and destname then
  101.                 template = ACTION_SPELL_CAST_START_FULL_TEXT_NO_SOURCE
  102.             elseif sourcename then
  103.                 template = ACTION_SPELL_CAST_START_FULL_TEXT_NO_DEST
  104.             elseif destname then
  105.                 template = ACTION_SPELL_CAST_START_FULL_TEXT
  106.             end
  107.             spell:AddMessage(format(template, colorize(sourcename), "|cff"..color..spellname.."|r", nil, colorize(destname)))
  108.         end
  109.     end
  110. end
  111.  
  112.  
  113. -- If cast succeeds, print message to SpellAlert frame
  114. function ncSpellalert:UNIT_SPELLCAST_SUCCEEDED(event, unit, spell, rank)
  115.     event = special[spell]
  116.     if event and UnitIsEnemy("player", unit) then
  117.         if event == 1 then
  118.             buff:AddMessage(format("%s used a |cff00ff00PvP trinket|r.", colorize(UnitName(unit))))
  119.         elseif event == 2 then 
  120.             buff:AddMessage(format("%s used |cff00ff00Will of the Forsaken|r.", colorize(UnitName(unit))))
  121.         elseif event == 3 then
  122.             buff:AddMessage(format("%s is drinking.", colorize(UnitName(unit))))
  123.         elseif event == 4 then
  124.             buff:AddMessage(format("%s used Every Man for Himself.", colorize(UnitName(unit))))
  125.         end
  126.     end
  127. end
  128.  
  129.  
  130. ncSpellalert:SetScript("OnEvent", function(self, event, ...) self[event](self, event, ...) end)
  131. ncSpellalert:RegisterEvent("PLAYER_LOGIN")
Add Comment
Please, Sign In to add comment