vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- |
2 | -- AggroAlert |
||
3 | -- v1.5 |
||
4 | -- By Sathanas of Khadgar |
||
5 | -- |
||
6 | -- Creates a movable frame that will display the target's target (if any), and allow for |
||
7 | -- visible warning on player gaining aggro. |
||
8 | -- |
||
9 | -- To move the AggroAlert bubble, use Shift+Left Button and drag it to a new position. |
||
10 | -- |
||
11 | -- Clicking on the AggroAlert bubble will target the unit named in the bubble |
||
12 | -- |
||
13 | -- v1.5 Changes: |
||
14 | -- |
||
15 | -- Updated TOC for 1.7 patch. |
||
16 | -- Added an option in the /agg warning command to disable all text warnings. |
||
17 | -- |
||
18 | -- |
||
19 | -- v1.4 Changes: |
||
20 | -- |
||
21 | -- Removed buggy call command. Seeing a pattern here? |
||
22 | -- Background of the AggroAlert bubble is now a healthbar for the named unit in the bubble. |
||
23 | -- |
||
24 | -- |
||
25 | -- v1.3 Changes: |
||
26 | -- |
||
27 | -- Ditched the buggy spell alert that was in 1.3 beta. It sucked. |
||
28 | -- Added Healer Mode, the bubble will display "- Tank" or "- Idle" when targetting an ally, showing |
||
29 | -- whether their target is currently aggrod on them (i.e. the ally is tanking) or not. |
||
30 | -- Also added the new command "/agg call" which turns on automatic announcment of targets target changes |
||
31 | -- in the appropriate channel. When your target changes targets (i.e. the main tank loses aggro) |
||
32 | -- AggroAlert will broadcast a message to the channel, example "Target Change! Onyxia is now engaged on SomeDumbGuy!", |
||
33 | -- this alert disables itself when you change targets or exit combat, and must be turned on individually each |
||
34 | -- time with "/agg call", this is done mainly since this is a very situational feature. |
||
35 | -- |
||
36 | -- |
||
37 | -- v1.2 Changes: |
||
38 | -- |
||
39 | -- Slash commands have changed, use "/agg mode" to toggle modes, and "/agg warning" to toggle between |
||
40 | -- the original smaller warning, and a new gigantic one. |
||
41 | -- Hopefully fixed all the errors caused by stun/sap/poly etc |
||
42 | -- |
||
43 | -- |
||
44 | -- v1.1 Changes: |
||
45 | -- |
||
46 | -- AggroAlert now uses the slash command /aggroalert or /agg to toggle between 2 modes: |
||
47 | -- DPS Mode will alert you visibly on screen when the targetted unit targets onto you (You pulled aggro) |
||
48 | -- Tank Mode will alert you when the targeted unit CEASES targetting on you (Someone else pulled aggro) |
||
49 | -- |
||
50 | -- |
||
51 | |||
52 | local aggroWarningCount = 0; |
||
53 | local PlayerName = UnitName("player"); |
||
54 | |||
55 | AggroAlertMode = {}; |
||
56 | AggroAlertWarning = {}; |
||
57 | |||
58 | function AggroAlert_OnLoad() |
||
59 | this:RegisterEvent("PLAYER_TARGET_CHANGED"); |
||
60 | this:RegisterEvent("UNIT_COMBAT"); |
||
61 | this:RegisterEvent("PLAYER_REGEN_DISABLED"); |
||
62 | this:RegisterEvent("PLAYER_REGEN_ENABLED"); |
||
63 | this:RegisterEvent("VARIABLES_LOADED"); |
||
64 | end |
||
65 | |||
66 | function AggroAlert_Command(cmd) |
||
67 | if (cmd) then |
||
68 | if (cmd == "mode") then |
||
69 | if (AggroAlertMode[PlayerName] == 0) then -- DPS Mode |
||
70 | AggroAlertMode[PlayerName] = 1; |
||
71 | DEFAULT_CHAT_FRAME:AddMessage("AggroAlert is now operating in Tank Mode",1,0,0); |
||
72 | elseif (AggroAlertMode[PlayerName] == 1) then -- Tank Mode |
||
73 | AggroAlertMode[PlayerName] = 2; |
||
74 | DEFAULT_CHAT_FRAME:AddMessage("AggroAlert is now operating in Healer Mode",1,0,0); |
||
75 | elseif (AggroAlertMode[PlayerName] == 2) then |
||
76 | AggroAlertMode[PlayerName] = 0; |
||
77 | DEFAULT_CHAT_FRAME:AddMessage("AggroAlert is now operating in DPS Mode",1,0,0); |
||
78 | end |
||
79 | elseif (cmd == "warning") then |
||
80 | if (AggroAlertWarning[PlayerName] == 0) then -- Little Warning |
||
81 | AggroAlertWarning[PlayerName] = 1; |
||
82 | DEFAULT_CHAT_FRAME:AddMessage("AggroAlert Warning style set to Giganto Mode",1,0,0); |
||
83 | elseif (AggroAlertWarning[PlayerName] == 1) then -- Big Warning |
||
84 | AggroAlertWarning[PlayerName] = 2; |
||
85 | DEFAULT_CHAT_FRAME:AddMessage("AggroAlert Warning text disabled",1,0,0); |
||
86 | elseif (AggroAlertWarning[PlayerName] == 2) then -- Warning Off |
||
87 | AggroAlertWarning[PlayerName] = 0; |
||
88 | DEFAULT_CHAT_FRAME:AddMessage("AggroAlert Warning style set to Small Mode",1,0,0); |
||
89 | end |
||
90 | else |
||
91 | DEFAULT_CHAT_FRAME:AddMessage("Valid AggroAlert commands are:",1,0,0); |
||
92 | DEFAULT_CHAT_FRAME:AddMessage("/agg mode - Toggle operating mode between DPS ,Tank, and Healer modes.",1,0,0); |
||
93 | DEFAULT_CHAT_FRAME:AddMessage("/agg warning - Toggle between small, large, and no warning text.",1,0,0); |
||
94 | end |
||
95 | end |
||
96 | end |
||
97 | |||
98 | function AggroAlert_OnEvent(event) |
||
99 | if( event == "PLAYER_TARGET_CHANGED" or event == "UNIT_COMBAT" or event == "PLAYER_REGEN_DISABLED") then |
||
100 | AggroAlert_Go(); |
||
101 | end |
||
102 | if (event == "PLAYER_REGEN_ENABLED") then |
||
103 | aggroWarningCount = 0; |
||
104 | AggroAlert_Call = 0; |
||
105 | CallTime = 0; |
||
106 | AggroAlert_Go(); |
||
107 | end |
||
108 | if (event == "VARIABLES_LOADED") then |
||
109 | |||
110 | if (AggroAlertMode == nil) then |
||
111 | AggroAlertMode = {}; |
||
112 | end |
||
113 | if (AggroAlertWarning == nil) then |
||
114 | AggroAlertWarning = {}; |
||
115 | end |
||
116 | |||
117 | if (AggroAlertMode[PlayerName] == nil) then |
||
118 | AggroAlertMode[PlayerName] = {}; |
||
119 | AggroAlertMode[PlayerName] = 0; |
||
120 | DEFAULT_CHAT_FRAME:AddMessage("AggroAlert is setting initial mode..."); |
||
121 | end |
||
122 | if (AggroAlertWarning[PlayerName] == nil) then |
||
123 | AggroAlertWarning[PlayerName] = {}; |
||
124 | AggroAlertWarning[PlayerName] = 0; |
||
125 | DEFAULT_CHAT_FRAME:AddMessage("AggroAlert is setting initial warning style..."); |
||
126 | end |
||
127 | |||
128 | SLASH_AGGROALERT1 = "/aggroalert"; |
||
129 | SLASH_AGGROALERT2 = "/agg"; |
||
130 | SlashCmdList["AGGROALERT"] = AggroAlert_Command; |
||
131 | end |
||
132 | end |
||
133 | |||
134 | function AggroAlert_Go() |
||
135 | if (UnitName("target")) then |
||
136 | -- Player has something targetted |
||
137 | if (UnitIsCorpse("target")) then AggroAlert(); |
||
138 | elseif (UnitIsDead("target")) then AggroAlert(); |
||
139 | else AggroAlert("Idle"); |
||
140 | end |
||
141 | if (UnitAffectingCombat("target")) then |
||
142 | -- Target is in an active combat situation |
||
143 | if (UnitIsDead("targettarget") or UnitIsCorpse("targettarget")) then |
||
144 | -- Im thinking targetting something that is targetting a corpse or dead thing is causing crashes |
||
145 | -- Hence this safety check. If it is, we do nothing and hide the bubble. |
||
146 | AggroAlert(); |
||
147 | else |
||
148 | if (UnitName("targettarget")) then |
||
149 | -- Stupid mobs dont have targets when they are trapped/polyd/sapped/stunned, check for this |
||
150 | |||
151 | if (AggroAlertMode[PlayerName] == 0) then -- DPS Mode |
||
152 | if (UnitName("targettarget") == UnitName("player")) then |
||
153 | -- Its coming right for us! |
||
154 | AggroAlert("*** YOU ***",0,1); |
||
155 | if (aggroWarningCount == 0) then |
||
156 | if (AggroAlertWarning[PlayerName] == 0) then |
||
157 | UIErrorsFrame:AddMessage(UnitName("target").." has changed targets to you!",1,0,0,1,3); |
||
158 | elseif (AggroAlertWarning[PlayerName] == 1) then |
||
159 | AggroAlertFadingFrame_Show(UnitName("target").." has changed targets to you!"); |
||
160 | elseif (AggroAlertWarning[PlayerName] == 2) then |
||
161 | -- Warning disabled, left in for future additions that may require this condition |
||
162 | end |
||
163 | aggroWarningCount = 1; |
||
164 | end |
||
165 | else |
||
166 | -- Whew it isnt fighting us |
||
167 | AggroAlert(UnitName("targettarget"),1,0); |
||
168 | aggroWarningCount = 0; |
||
169 | end |
||
170 | elseif (AggroAlertMode[PlayerName] == 1) then -- Tank mode |
||
171 | if (UnitName("targettarget") == UnitName("player")) then |
||
172 | -- Its coming right for us! (A good thing, im tanking it) |
||
173 | AggroAlert("*** YOU ***",1,0); |
||
174 | aggroWarningCount = 0; |
||
175 | else |
||
176 | -- Some dumb hunter pulled aggro |
||
177 | AggroAlert(UnitName("targettarget"),0,1); |
||
178 | if (aggroWarningCount == 0) then |
||
179 | if (AggroAlertWarning[PlayerName] == 0) then |
||
180 | UIErrorsFrame:AddMessage("You have lost aggro to "..UnitName("targettarget").."!",1,0,0,1,3); |
||
181 | elseif (AggroAlertWarning[PlayerName] == 1) then |
||
182 | AggroAlertFadingFrame_Show("You have lost aggro to "..UnitName("targettarget").."!"); |
||
183 | elseif (AggroAlertWarning[PlayerName] == 2) then |
||
184 | -- Warning disabled, left in for future additions that may require this condition |
||
185 | end |
||
186 | aggroWarningCount = 1; |
||
187 | end |
||
188 | end |
||
189 | elseif (AggroAlertMode[PlayerName] == 2) then -- Healer Mode |
||
190 | if (UnitIsPlayer("target")) then |
||
191 | if (UnitIsFriend("player", "target")) then |
||
192 | if (UnitIsUnit("target", "targettargettarget")) then -- The target and the targets target target (whew) are the same |
||
193 | AggroAlert(UnitName("targettarget").." - Tank",1,0); |
||
194 | if (aggroWarningCount == 0) then |
||
195 | if (AggroAlertWarning[PlayerName] == 0) then |
||
196 | UIErrorsFrame:AddMessage(UnitName("target").." is now tanking "..UnitName("targettarget"),1,0,0,1,3); |
||
197 | elseif (AggroAlertWarning[PlayerName] == 1) then |
||
198 | AggroAlertFadingFrame_Show(UnitName("target").." is now tanking "..UnitName("targettarget")); |
||
199 | elseif (AggroAlertWarning[PlayerName] == 2) then |
||
200 | -- Warning disabled, left in for future additions that may require this condition |
||
201 | end |
||
202 | aggroWarningCount = 1; |
||
203 | end |
||
204 | else -- Lazy warrior isnt tanking anything! |
||
205 | AggroAlert(UnitName("targettarget").." - Idle",1,0); |
||
206 | aggroWarningCount = 0; |
||
207 | end |
||
208 | else |
||
209 | if (UnitName("targettarget") == UnitName("player")) then |
||
210 | -- Its coming right for us! |
||
211 | AggroAlert("*** YOU ***",0,1); |
||
212 | if (aggroWarningCount == 0) then |
||
213 | if (AggroAlertWarning[PlayerName] == 0) then |
||
214 | UIErrorsFrame:AddMessage(UnitName("target").." has changed targets to you!",1,0,0,1,3); |
||
215 | elseif (AggroAlertWarning[PlayerName] == 1) then |
||
216 | AggroAlertFadingFrame_Show(UnitName("target").." has changed targets to you!"); |
||
217 | elseif (AggroAlertWarning[PlayerName] == 2) then |
||
218 | -- Warning disabled, left in for future additions that may require this condition |
||
219 | end |
||
220 | aggroWarningCount = 1; |
||
221 | end |
||
222 | else |
||
223 | -- Whew it isnt fighting us |
||
224 | AggroAlert(UnitName("targettarget"),1,0); |
||
225 | aggroWarningCount = 0; |
||
226 | end |
||
227 | end |
||
228 | else |
||
229 | if (UnitName("targettarget") == UnitName("player")) then |
||
230 | -- Its coming right for us! |
||
231 | AggroAlert("*** YOU ***",0,1); |
||
232 | if (aggroWarningCount == 0) then |
||
233 | if (AggroAlertWarning[PlayerName] == 0) then |
||
234 | UIErrorsFrame:AddMessage(UnitName("target").." has changed targets to you!",1,0,0,1,3); |
||
235 | elseif (AggroAlertWarning[PlayerName] == 1) then |
||
236 | AggroAlertFadingFrame_Show(UnitName("target").." has changed targets to you!"); |
||
237 | elseif (AggroAlertWarning[PlayerName] == 2) then |
||
238 | -- Warning disabled, left in for future additions that may require this condition |
||
239 | end |
||
240 | aggroWarningCount = 1; |
||
241 | end |
||
242 | else |
||
243 | -- Whew it isnt fighting us |
||
244 | AggroAlert(UnitName("targettarget"),1,0); |
||
245 | aggroWarningCount = 0; |
||
246 | end |
||
247 | end |
||
248 | end |
||
249 | end |
||
250 | end |
||
251 | end |
||
252 | else |
||
253 | -- Player has nothing targetted |
||
254 | AggroAlert(); |
||
255 | end |
||
256 | end |
||
257 | |||
258 | |||
259 | function AggroAlert(text, swords, skull) |
||
260 | AggroAlert_Skull:Hide(); |
||
261 | AggroAlert_Swords:Hide(); |
||
262 | AggroAlert_Bubble:Hide(); |
||
263 | AggroAlert_Frame:Show(); |
||
264 | AggroAlert_Text:Show(); |
||
265 | |||
266 | if (text == nil) then |
||
267 | AggroAlert_Skull:Hide(); |
||
268 | AggroAlert_Swords:Hide(); |
||
269 | AggroAlert_Bubble:Hide(); |
||
270 | AggroAlert_Frame:Hide(); |
||
271 | AggroAlert_Text:Hide(); |
||
272 | else |
||
273 | AggroAlert_Text:SetText(text); |
||
274 | AggroAlert_Frame:SetWidth(AggroAlert_Text:GetWidth() + 30); |
||
275 | AggroAlert_Bar:SetWidth(AggroAlert_Frame:GetWidth() - 6); |
||
276 | if (UnitIsFriend("targettarget","player") or UnitInParty("targettarget") or UnitInRaid("targettarget")) then |
||
277 | AggroAlert_Bar:SetAlpha(.5); |
||
278 | elseif (UnitIsUnit("targettarget","player")) then |
||
279 | AggroAlert_Bar:SetAlpha(.6); |
||
280 | else |
||
281 | AggroAlert_Bar:SetAlpha(.4); |
||
282 | end |
||
283 | if (UnitHealthMax("targettarget") > 100) then |
||
284 | local thingy = UnitHealth("targettarget") / UnitHealthMax("targettarget"); |
||
285 | thingy = thingy * 100; |
||
286 | AggroAlert_Bar:SetValue(thingy); |
||
287 | else |
||
288 | AggroAlert_Bar:SetValue(UnitHealth("targettarget")); |
||
289 | end |
||
290 | if (swords == 1) then |
||
291 | AggroAlert_Bubble:Show(); |
||
292 | AggroAlert_Swords:Show(); |
||
293 | end |
||
294 | if (skull == 1) then |
||
295 | AggroAlert_Bubble:Show(); |
||
296 | AggroAlert_Skull:Show(); |
||
297 | end |
||
298 | end |
||
299 | end |
||
300 | |||
301 | function AggroAlert_TargetUnit() |
||
302 | AssistUnit("target"); |
||
303 | aggroWarningCount = 0; |
||
304 | end |
||
305 | |||
306 | -- |
||
307 | -- Fade in/out frame stuff |
||
308 | -- Ripped/modified from FadingFrame from Blizzard |
||
309 | -- |
||
310 | |||
311 | function AggroAlertFadingFrame_OnLoad() |
||
312 | AggroAlert_BigWarning:Hide(); |
||
313 | end |
||
314 | |||
315 | function AggroAlertFadingFrame_Show(message) |
||
316 | AggroAlertstartTime = GetTime(); |
||
317 | if (message) then |
||
318 | AggroAlert_BigWarning_Text:SetText(message); |
||
319 | end |
||
320 | AggroAlert_BigWarning:Show(); |
||
321 | end |
||
322 | |||
323 | |||
324 | function AggroAlertFadingFrame_OnUpdate() |
||
325 | local elapsed = GetTime() - AggroAlertstartTime; |
||
326 | local fadeInTime = 0.2; |
||
327 | if ( elapsed < fadeInTime ) then |
||
328 | local alpha = (elapsed / fadeInTime); |
||
329 | AggroAlert_BigWarning:SetAlpha(alpha); |
||
330 | return; |
||
331 | end |
||
332 | local holdTime = 2.5; |
||
333 | if ( elapsed < (fadeInTime + holdTime) ) then |
||
334 | AggroAlert_BigWarning:SetAlpha(1.0); |
||
335 | return; |
||
336 | end |
||
337 | local fadeOutTime = 2; |
||
338 | if ( elapsed < (fadeInTime + holdTime + fadeOutTime) ) then |
||
339 | local alpha = 1.0 - ((elapsed - holdTime - fadeInTime) / fadeOutTime); |
||
340 | AggroAlert_BigWarning:SetAlpha(alpha); |
||
341 | return; |
||
342 | end |
||
343 | AggroAlert_BigWarning:Hide(); |
||
344 | end |