-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkillfeed.lua
More file actions
147 lines (122 loc) · 4.29 KB
/
Copy pathkillfeed.lua
File metadata and controls
147 lines (122 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
-- killfeed.lua
-- SavedVariables: KillFeedDB
local KillFeedMessages = {}
local MAX_MESSAGES = 5
local DISPLAY_TIME = 6 -- seconds
local killfeedEnabled = true
SLASH_KILLFEED1 = "/kf"
SlashCmdList["KILLFEED"] = function(msg)
msg = msg:lower()
if msg == "1" or msg == "on" then
killfeedEnabled = true
print("KillFeed enabled.")
elseif msg == "0" or msg == "off" then
killfeedEnabled = false
print("KillFeed disabled.")
else
print("Usage: /kf 1 | 0")
end
end
local function ColorName(name, class)
local color = class and RAID_CLASS_COLORS[class]
if not color then
return name
end
return string.format("|cff%02x%02x%02x%s|r", color.r * 255, color.g * 255, color.b * 255, name)
end
local function GetClassByName(name)
for i = 1, GetNumRaidMembers() do
local unit, _, _, _, class = GetRaidRosterInfo(i)
if unit == name then return class end
end
for i = 1, GetNumPartyMembers() do
local unit = "party" .. i
if UnitName(unit) == name then
local _, class = UnitClass(unit)
return class
end
end
return nil
end
local function ReanchorMessages()
for i, msg in ipairs(KillFeedMessages) do
msg:ClearAllPoints()
msg:SetPoint("TOPLEFT", 10, -((i - 1) * 20))
end
end
local function FadeOutAndRemove(msgFrame)
local alpha = 1
local fader = CreateFrame("Frame")
fader:SetScript("OnUpdate", function(self, elapsed)
alpha = alpha - elapsed * 0.5
if alpha <= 0 then
msgFrame:Hide()
msgFrame:SetParent(nil)
for i, m in ipairs(KillFeedMessages) do
if m == msgFrame then
table.remove(KillFeedMessages, i)
break
end
end
ReanchorMessages()
self:SetScript("OnUpdate", nil)
self:Hide()
else
msgFrame:SetAlpha(alpha)
end
end)
end
local function CreateMessageFrame()
local container = CreateFrame("Frame", nil, KillFeedContent)
container:SetSize(280, 20)
local text = container:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
text:SetJustifyH("LEFT")
text:SetPoint("LEFT", 0, 0)
text:SetWidth(260)
container.text = text
return container
end
local function AddKillMessage(killer, killerClass, spell, victim, victimClass, spellID)
if #KillFeedMessages >= MAX_MESSAGES then
local old = table.remove(KillFeedMessages, 1)
old:Hide()
old:SetParent(nil)
end
local msgFrame = CreateMessageFrame()
msgFrame:SetParent(KillFeedContent)
msgFrame:SetAlpha(1)
msgFrame:Show()
local formatted
if not killerClass or not spell or not victimClass then
formatted = string.format("%s killed %s", killer, victim)
else
formatted = string.format("%s {%s} %s",
ColorName(killer, killerClass),
spell,
ColorName(victim, victimClass)
)
end
msgFrame.text:SetText(formatted)
table.insert(KillFeedMessages, msgFrame)
ReanchorMessages()
C_Timer.After(DISPLAY_TIME, function()
FadeOutAndRemove(msgFrame)
end)
end
-- Event handling
local frame = CreateFrame("Frame")
frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
frame:SetScript("OnEvent", function()
if not killfeedEnabled then return end
local _, eventType, _, sourceGUID, sourceName, sourceFlags, _, destGUID, destName, destFlags, _, spellID, spellName = CombatLogGetCurrentEventInfo()
if not (sourceName and destName) then return end
local sourceIsPlayer = bit.band(sourceFlags, COMBATLOG_OBJECT_TYPE_PLAYER) > 0
local destIsPlayer = bit.band(destFlags, COMBATLOG_OBJECT_TYPE_PLAYER) > 0
if not (sourceIsPlayer and destIsPlayer) then return end
if eventType == "SPELL_DAMAGE" or eventType == "SWING_DAMAGE" or eventType == "RANGE_DAMAGE" then
local killerClass = GetClassByName(sourceName)
local victimClass = GetClassByName(destName)
local spell = spellName or "<melee>"
AddKillMessage(sourceName, killerClass, spell, destName, victimClass, spellID)
end
end)