Lua Code:
local guids = {}
local f = CreateFrame("Frame")
function f:NAME_PLATE_UNIT_ADDED(unit)
guids[UnitGUID(unit)] = unit
end
function f:NAME_PLATE_UNIT_REMOVED(unit)
guids[UnitGUID(unit)] = nil
end
function f:COMBAT_LOG_EVENT_UNFILTERED()
local timestamp, subevent, _, sourceGUID, sourceName, sourceFlags, _, destGUID, destName, _, _, spellID, spellName = CombatLogGetCurrentEventInfo()
if subevent == "SPELL_CAST_START" then
local unit = guids[sourceGUID]
if unit and UnitIsUnit(unit.."target", "player") and bit.band(sourceFlags, COMBATLOG_OBJECT_REACTION_HOSTILE) > 0 then
print( format("%s is casting %s on me", sourceName, GetSpellLink(spellID)) )
end
end
end
f:SetScript("OnEvent", function(self, event, ...)
f[event](self, ...)
end)
f:RegisterEvent("NAME_PLATE_UNIT_ADDED")
f:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")