Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------------------------------------------------------
- -- ncSpellAlert was written by Nightcracker, and is updated, and maintained by Sauerkraut --
- --------------------------------------------------------------------------------------------
- local ncSpellalert = CreateFrame("Frame", "ncSpellalert")
- local band, bor = bit.band, bit.bor
- local enemy = bor(COMBATLOG_OBJECT_REACTION_HOSTILE, COMBATLOG_OBJECT_TYPE_PLAYER)
- -- Spell filter for various buffs/spells
- -- Why not place in config with others? [ADD TO TO DO LIST]
- local deathcoil = GetSpellInfo(47541)
- local special = {
- [GetSpellInfo(42292)] = 1, -- pvp trinket
- [GetSpellInfo(7744)] = 2, -- Will of the Forsaken (Undead Racial)
- [GetSpellInfo(57073)] = 3, -- Drinking
- [GetSpellInfo(59752)] = 4, -- Every Man for Himself (Human Racial)
- }
- -- Determine if enemy, and class color text
- local function isenemy(flags) return band(flags, enemy)==enemy end
- local function tohex(val) return string.format("%.2x", val) end
- 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
- local function colorize(name) if name then return "|cff"..getclasscolor(select(2,UnitClass(name)))..name.."|r" else return nil end end
- local function createmessageframe(name)
- local f = CreateFrame("MessageFrame", name, UIParent)
- f:SetPoint("LEFT", UIParent)
- f:SetPoint("RIGHT", UIParent)
- f:SetHeight(25)
- f:SetInsertMode("TOP")
- f:SetFrameStrata("HIGH")
- f:SetTimeVisible(1)
- f:SetFadeDuration(3)
- f:SetFont(STANDARD_TEXT_FONT, 23, "OUTLINE")
- return f
- end
- -- Creates the frame to output Spell and Buff Alert messages
- local spell = createmessageframe("SpellAlertFrame")
- spell:SetPoint("TOP", 0, -200)
- local buff = createmessageframe("BuffAlertFrame")
- buff:SetPoint("BOTTOM", spell, "TOP", 0, 2)
- -- Is PVP only selected in the Config?
- function ncSpellalert:PLAYER_LOGIN()
- if ncSpellalertDB.CONFIG.pvponly then
- self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
- self:ZONE_CHANGED_NEW_AREA()
- else
- self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
- self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
- end
- self:UnregisterEvent("PLAYER_LOGIN")
- end
- -- Set to only be active while in PVP zones, such as BGs, or Arenas unless selected in config
- function ncSpellalert:ZONE_CHANGED_NEW_AREA()
- local pvp = GetZonePVPInfo()
- if not pvp or pvp ~= "sanctuary" then
- self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
- self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
- else
- self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
- self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
- end
- end
- -- If allunits is set to false, this decides which units to track
- local function isallowedunit(guid)
- for key, val in pairs(ncSpellalertDB.CONFIG.units) do
- if UnitGUID(unit, val) then return true end
- end
- return false
- end
- -- Scans combat log for enemy spellcasts/heals and casted buffs/debuffs
- function ncSpellalert:COMBAT_LOG_EVENT_UNFILTERED(event, timestamp, eventType, hideCaster, sourceGUID, sourcename, sourceFlags, sourceFlags2, destGUID, destname, destFlags, destFlags2, spellid, spellname)
- if (spellname==deathcoil and select(2, UnitClass(sourceGUID))=="DEATHKNIGHT") or spellid == 59752 or spellid == 42292 or spellid == 7744 then return end -- ignores
- if eventType == "SPELL_AURA_APPLIED" and ncSpellalertDB.BUFF_SPELLS[spellname] and isenemy(destFlags) and (ncSpellalertDB.CONFIG.allunits or isallowedunit(destGUID)) then
- buff:AddMessage(format(ACTION_SPELL_AURA_APPLIED_BUFF_FULL_TEXT_NO_SOURCE, nil, "|cff00ff00"..spellname.."|r", nil, colorize(destname)))
- elseif eventType == "SPELL_CAST_START" and isenemy(sourceFlags) and (ncSpellalertDB.CONFIG.allunits or isallowedunit(sourceGUID)) then
- local color
- if ncSpellalertDB.HARMFUL_SPELLS[spellname] then
- color = "ff0000"
- elseif ncSpellalertDB.HEALING_SPELLS[spellname] then
- color = "ffff00"
- end
- if color then
- local template
- if sourcename and destname then
- template = ACTION_SPELL_CAST_START_FULL_TEXT_NO_SOURCE
- elseif sourcename then
- template = ACTION_SPELL_CAST_START_FULL_TEXT_NO_DEST
- elseif destname then
- template = ACTION_SPELL_CAST_START_FULL_TEXT
- end
- spell:AddMessage(format(template, colorize(sourcename), "|cff"..color..spellname.."|r", nil, colorize(destname)))
- end
- end
- end
- -- If cast succeeds, print message to SpellAlert frame
- function ncSpellalert:UNIT_SPELLCAST_SUCCEEDED(event, unit, spell, rank)
- event = special[spell]
- if event and UnitIsEnemy("player", unit) then
- if event == 1 then
- buff:AddMessage(format("%s used a |cff00ff00PvP trinket|r.", colorize(UnitName(unit))))
- elseif event == 2 then
- buff:AddMessage(format("%s used |cff00ff00Will of the Forsaken|r.", colorize(UnitName(unit))))
- elseif event == 3 then
- buff:AddMessage(format("%s is drinking.", colorize(UnitName(unit))))
- elseif event == 4 then
- buff:AddMessage(format("%s used Every Man for Himself.", colorize(UnitName(unit))))
- end
- end
- end
- ncSpellalert:SetScript("OnEvent", function(self, event, ...) self[event](self, event, ...) end)
- ncSpellalert:RegisterEvent("PLAYER_LOGIN")
Add Comment
Please, Sign In to add comment