vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 This is the basic template for adding a variable:
3  
4 ["variable"] = { func = function(text, unit)
5 code that creates the value that replaces your variable
6 text = DUF_gsub(text, 'variable', value);
7 return text;
8 end,
9 events = {"event", "event2", ...} },
10  
11 variable - Can be anything you want and doesn't necessarily have to be preceded with a $.
12 func - This is the function called when the variable needs to be updated.
13 text - This is the entire text of the TextBox and must be returned after it is modified.
14 unit - This is the unit ID (party1, player, target, etc.) that the TextBox refers to.
15 No other parameters will be passed to your function and those 2 will always be passed.
16 text = DUF_gsub(text, 'variable', value) - This line is used to replace the variable with the value you generated in the preceding code. It handles trimming leading spaces if value is nil or false.
17 events - List all the events here that will cause the variable to update. You can enter as many as you want. Variables are only updated when event's unit is the same as the TextBox's unit. PARTY_MEMBERS_CHANGED and PLAYER_TARGET_CHANGED are registered automatically and appropriately for each textbox and need not be defined as events.
18 --]]
19  
20 DUF_VARIABLE_FUNCTIONS = {
21 -- New Line
22 ["$nl"] = { func = function(text, unit)
23 text = string.gsub(text, '$nl', "\n");
24 return text;
25 end,
26 events = {} },
27  
28 -- Raid Group
29 ["$rg"] = { func = function(text, unit)
30 local value;
31 for i=1, GetNumRaidMembers() do
32 if (UnitIsUnit("raid"..i, unit)) then
33 _, _, value = GetRaidRosterInfo(i);
34 break;
35 end
36 end
37 text = DUF_gsub(text, '$rg', value);
38 return text;
39 end,
40 events = {"RAID_ROSTER_UPDATE"} },
41  
42 -- Honor Progress
43 ["$hn"] = { func = function(text, unit)
44 local value = GetPVPRankProgress();
45 value = math.floor(value * 100);
46 text = string.gsub(text, '$hn', value);
47 return text;
48 end,
49 events = {"PLAYER_PVP_KILLS_CHANGED", "PLAYER_PVP_RANK_CHANGED"} },
50  
51 -- Name
52 ["$nm"] = { func = function(text, unit)
53 local unitname = UnitName(unit);
54 if (not unitname) then unitname = unit; end
55 text = DUF_gsub(text, '$nm', unitname);
56 return text;
57 end,
58 events = {"UNIT_NAME_UPDATE"} },
59  
60 -- Level
61 ["$lv"] = { func = function(text, unit)
62 local level = UnitLevel(unit);
63 if (level == -1) then
64 if (UnitClassification(unit) == "worldboss") then
65 level = "61+";
66 else
67 level = ">"..(UnitLevel("player") + 10);
68 end
69 end
70 text = DUF_gsub(text, '$lv', level);
71 return text;
72 end,
73 events = {"UNIT_LEVEL"} },
74  
75 -- Next Level
76 ["$xn"] = { func = function(text, unit)
77 local level = UnitLevel(unit) + 1;
78 text = DUF_gsub(text, '$xn', level);
79 return text;
80 end,
81 events = {"UNIT_LEVEL"} },
82  
83 -- Player Class
84 ["$cl"] = { func = function(text, unit)
85 local class = UnitClass(unit);
86 if (class == "") then class = "class"; end
87 if (UnitIsPlayer(unit)) then
88 text = DUF_gsub(text, '$cl', class);
89 else
90 text = DUF_gsub(text, '$cl', "");
91 end
92 return text;
93 end,
94 events = {"UNIT_NAME_UPDATE"} },
95  
96 -- Mob Class
97 ["$cy"] = { func = function(text, unit)
98 local class = UnitClass(unit);
99 if (not class) then class = "class"; end
100 if (not UnitIsPlayer(unit)) then
101 text = DUF_gsub(text, '$cy', class);
102 else
103 text = DUF_gsub(text, '$cy', "");
104 end
105 return text;
106 end,
107 events = {} },
108  
109 -- Current Health
110 ["$hc"] = { func = function(text, unit)
111 local health = DUF_Get_Health(unit);
112 text = DUF_gsub(text, '$hc', health);
113 return text;
114 end,
115 events = {"UNIT_HEALTH"} },
116  
117 -- Max Health
118 ["$hm"] = { func = function(text, unit)
119 local healthmax = DUF_Get_MaxHealth(unit);
120 text = DUF_gsub(text, '$hm', healthmax);
121 return text;
122 end,
123 events = {"UNIT_MAXHEALTH"} },
124  
125 -- Damage Taken, i.e. lost health
126 ["$dt"] = { func = function(text, unit)
127 local damage = DUF_Get_HealthDamage(unit);
128 text = DUF_gsub(text, '$dt', damage);
129 return text;
130 end,
131 events = {"UNIT_HEALTH", "UNIT_MAXHEALTH"} },
132  
133 -- Damage as a percent
134 ["$dp"] = { func = function(text, unit)
135 local damage = UnitHealthMax(unit) - UnitHealth(unit);
136 local healthmax = UnitHealthMax(unit);
137 if (healthmax == 0) then
138 damage = 0;
139 else
140 damage = math.floor(damage/healthmax * 100);
141 end
142 text = DUF_gsub(text, '$dp', damage);
143 return text;
144 end,
145 events = {"UNIT_HEALTH", "UNIT_MAXHEALTH"} },
146  
147 -- Health as a percent
148 ["$hp"] = { func = function(text, unit)
149 local percent = 0;
150 local health = UnitHealth(unit);
151 local healthmax = UnitHealthMax(unit);
152 if (healthmax > 0) then
153 percent = math.floor(health/healthmax * 100);
154 else
155 percent = 0;
156 end
157 text = DUF_gsub(text, '$hp', percent);
158 return text;
159 end,
160 events = {"UNIT_HEALTH", "UNIT_MAXHEALTH"} },
161  
162 -- Current Mana
163 ["$mc"] = { func = function(text, unit)
164 local mana = UnitMana(unit);
165 text = DUF_gsub(text, '$mc', mana, 1);
166 return text;
167 end,
168 events = {"UNIT_MANA", "UNIT_RAGE", "UNIT_ENERGY", "UNIT_FOCUS", "UNIT_DISPLAYPOWER"} },
169  
170 -- Max Mana
171 ["$mm"] = { func = function(text, unit)
172 local manamax = UnitManaMax(unit);
173 if (not manamax) then
174 manamax = 0;
175 end
176 text = DUF_gsub(text, '$mm', manamax, 1);
177 return text;
178 end,
179 events = {"UNIT_MAXMANA", "UNIT_MAXRAGE", "UNIT_MAXENERGY", "UNIT_MAXFOCUS", "UNIT_DISPLAYPOWER"} },
180  
181 -- Mana as a percent
182 ["$mp"] = { func = function(text, unit)
183 local mana = UnitMana(unit);
184 local manamax = UnitManaMax(unit);
185 local percent = 0;
186 if (manamax == 0) then
187 percent = 0;
188 else
189 percent = math.floor(mana/manamax * 100);
190 end
191 text = DUF_gsub(text, '$mp', percent, 1);
192 return text;
193 end,
194 events = {"UNIT_MAXMANA", "UNIT_MAXRAGE", "UNIT_MAXENERGY", "UNIT_MAXFOCUS", "UNIT_MANA", "UNIT_RAGE", "UNIT_ENERGY", "UNIT_FOCUS", "UNIT_DISPLAYPOWER"} },
195  
196 -- Mana Used
197 ["$mx"] = { func = function(text, unit)
198 local mana = UnitMana(unit);
199 local manamax = UnitManaMax(unit);
200 local damage = manamax - mana;
201 text = DUF_gsub(text, '$mx', damage, 1);
202 return text;
203 end,
204 events = {"UNIT_MAXMANA", "UNIT_MAXRAGE", "UNIT_MAXENERGY", "UNIT_MAXFOCUS", "UNIT_MANA", "UNIT_RAGE", "UNIT_ENERGY", "UNIT_FOCUS", "UNIT_DISPLAYPOWER"} },
205  
206 -- Mana Used as a percent
207 ["$my"] = { func = function(text, unit)
208 local mana = UnitMana(unit);
209 local manamax = UnitManaMax(unit);
210 local damage = manamax - mana;
211 if (manamax == 0) then
212 damage = 0;
213 else
214 damage = math.floor(damage/manamax * 100);
215 end
216 text = DUF_gsub(text, '$my', damage);
217 return text;
218 end,
219 events = {"UNIT_MAXMANA", "UNIT_MAXRAGE", "UNIT_MAXENERGY", "UNIT_MAXFOCUS", "UNIT_MANA", "UNIT_RAGE", "UNIT_ENERGY", "UNIT_FOCUS", "UNIT_DISPLAYPOWER"} },
220  
221 -- Race
222 ["$rc"] = { func = function(text, unit)
223 local race = UnitRace(unit);
224 if (not UnitName(unit)) then race = "race"; end
225 text = DUF_gsub(text, '$rc', race);
226 return text;
227 end,
228 events = {"UNIT_NAME_UPDATE"} },
229  
230 -- Class Abbreviation
231 ["$ca"] = { func = function(text, unit)
232 local value = DUF_CLASSABBREV[UnitClass(unit)];
233 if (not UnitName(unit)) then value = "CA"; end
234 text = DUF_gsub(text, '$ca', value);
235 return text;
236 end,
237 events = {"UNIT_NAME_UPDATE"} },
238  
239 -- Race Abbreviation
240 ["$ra"] = { func = function(text, unit)
241 local value = DUF_RACEABBREV[UnitRace(unit)];
242 if (not UnitName(unit)) then value = "RA"; end
243 text = DUF_gsub(text, '$ra', value);
244 return text;
245 end,
246 events = {"UNIT_NAME_UPDATE"} },
247  
248 -- Death Status - DEAD, GHOST, or nothing
249 ["$ds"] = { func = function(text, unit)
250 local value;
251 if (UnitIsGhost(unit)) then
252 value = DUF_TEXT.Ghost;
253 elseif (UnitIsDead(unit)) then
254 value = DUF_TEXT.Dead;
255 elseif (not UnitName(unit)) then
256 value = DUF_TEXT.Dead;
257 else
258 value = nil;
259 end
260 text = DUF_gsub(text, '$ds', value);
261 return text;
262 end,
263 events = {"UNIT_HEALTH"} },
264  
265 -- Faction - Horde, Alliance, or nothing
266 ["$fa"] = { func = function(text, unit)
267 local value = UnitFactionGroup(unit);
268 if (not UnitName(unit)) then value = "faction"; end
269 text = DUF_gsub(text, '$fa', value);
270 return text;
271 end,
272 events = {"UNIT_FACTION"} },
273  
274 -- Keybinding
275 ["$kb"] = { func = function(text, unit)
276 local value;
277 if (unit == "player") then
278 value = DL_Get_KeybindingText("TARGETSELF");
279 elseif (unit == "pet") then
280 value = DL_Get_KeybindingText("TARGETPET");
281 elseif (unit == "party1") then
282 value = DL_Get_KeybindingText("TARGETPARTYMEMBER1");
283 elseif (unit == "party2") then
284 value = DL_Get_KeybindingText("TARGETPARTYMEMBER2");
285 elseif (unit == "party3") then
286 value = DL_Get_KeybindingText("TARGETPARTYMEMBER3");
287 elseif (unit == "party4") then
288 value = DL_Get_KeybindingText("TARGETPARTYMEMBER4");
289 elseif (unit == "partypet1") then
290 value = DL_Get_KeybindingText("TARGETPARTYPET1");
291 elseif (unit == "partypet2") then
292 value = DL_Get_KeybindingText("TARGETPARTYPET2");
293 elseif (unit == "partypet3") then
294 value = DL_Get_KeybindingText("TARGETPARTYPET3");
295 elseif (unit == "partypet4") then
296 value = DL_Get_KeybindingText("TARGETPARTYPET4");
297 end
298 text = DUF_gsub(text, '$kb', value);
299 return text;
300 end,
301 events = {"UPDATE_BINDINGS"} },
302  
303 -- Is Visible
304 ["$iv"] = { func = function(text, unit)
305 local value;
306 if (not UnitIsVisible(unit)) then
307 value = DUF_TEXT.OutOfRange;
308 end
309 text = DUF_gsub(text, '$iv', value);
310 return text;
311 end,
312 events = {} },
313  
314 -- In Combat - COMBAT or nothing
315 ["$ic"] = { func = function(text, unit)
316 local value = "";
317 if (UnitAffectingCombat(unit) or (not UnitName(unit))) then
318 value = DUF_TEXT.Combat;
319 end
320 text = DUF_gsub(text, '$ic', value);
321 return text;
322 end,
323 events = {} },
324  
325 -- Offline Status - OFFLINE or nothing
326 ["$of"] = { func = function(text, unit)
327 local value;
328 if (UnitIsConnected(unit)) then
329 value = nil;
330 else
331 value = DUF_TEXT.Offline;
332 end
333 text = DUF_gsub(text, '$of', value);
334 return text;
335 end,
336 events = {} },
337  
338 -- Creature Classification - Elite, Boss, etc.
339 ["$cc"] = { func = function(text, unit)
340 local value = UnitClassification(unit);
341 if (value == "normal") then
342 value = nil;
343 elseif (value == "elite" or (not UnitName(unit))) then
344 value = DUF_TEXT.Elite;
345 elseif (value == "worldboss") then
346 value = DUF_TEXT.Boss;
347 elseif (value == "rare") then
348 value = DUF_TEXT.Rare;
349 elseif (value == "rareelite") then
350 value = DUF_TEXT.RareElite;
351 end
352 text = DUF_gsub(text, '$cc', value);
353 return text;
354 end,
355 events = {"UNIT_CLASSIFICATION_CHANGED"} },
356  
357 -- Creature Type - Beast, Humanoid, Undead, etc.
358 ["$ct"] = { func = function(text, unit)
359 local value = UnitCreatureType(unit);
360 if (UnitIsPlayer(unit)) then value = nil; end
361 if (not UnitName(unit)) then value = "beast"; end
362 text = DUF_gsub(text, '$ct', value);
363 return text;
364 end,
365 events = {"UNIT_CLASSIFICATION_CHANGED"} },
366  
367 -- Creature Family - Bear, Crab, Cat, etc.
368 ["$cf"] = { func = function(text, unit)
369 local value = UnitCreatureFamily(unit);
370 if (not UnitName(unit)) then value = "cat"; end
371 text = DUF_gsub(text, '$cf', value);
372 return text;
373 end,
374 events = {"UNIT_CLASSIFICATION_CHANGED"} },
375  
376 -- Health Regen per Second
377 ["$hr"] = { func = function(text, unit)
378 text = DUF_gsub(text, '$hr', this.healthregen);
379 return text;
380 end,
381 events = {"UNIT_HEALTH"} },
382  
383 -- Mana Regen per Second
384 ["$mr"] = { func = function(text, unit)
385 text = DUF_gsub(text, '$mr', this.manaregen);
386 return text;
387 end,
388 events = {"UNIT_MANA", "UNIT_RAGE", "UNIT_ENERGY", "UNIT_FOCUS"} },
389  
390 -- Health Regen per Tick
391 ["$ht"] = { func = function(text, unit)
392 text = DUF_gsub(text, '$ht', this.healthregentick);
393 return text;
394 end,
395 events = {"UNIT_HEALTH"} },
396  
397 -- Mana Regen per Tick
398 ["$mt"] = { func = function(text, unit)
399 text = DUF_gsub(text, '$mt', this.manaregentick);
400 return text;
401 end,
402 events = {"UNIT_MANA", "UNIT_RAGE", "UNIT_ENERGY", "UNIT_FOCUS"} },
403  
404 -- Recent Damage - shows all combat text: damage, blocks, evasions, etc.
405 ["$rd"] = { func = function(text, unit)
406 text = DUF_gsub(text, '$rd', this.damagetext);
407 return text;
408 end,
409 events = {"UNIT_COMBAT"} },
410  
411 -- Recent Heals
412 ["$rh"] = { func = function(text, unit)
413 text = DUF_gsub(text, '$rh', this.healtext);
414 return text;
415 end,
416 events = {"UNIT_COMBAT"} },
417  
418 -- Sex
419 ["$sx"] = { func = function(text, unit)
420 local value = DUF_UnitSex(unit);
421 text = DUF_gsub(text, '$sx', value);
422 return text;
423 end,
424 events = {"UNIT_NAME_UPDATE"} },
425  
426 -- Sex Abbreviation
427 ["$sa"] = { func = function(text, unit)
428 local value = DUF_SEXABBREV[DUF_UnitSex(unit)];
429 text = DUF_gsub(text, '$sa', value);
430 return text;
431 end,
432 events = {"UNIT_NAME_UPDATE"} },
433  
434 -- Tapped - TAPPED or nothing
435 ["$do"] = { func = function(text, unit)
436 local value;
437 if (UnitIsTapped(unit) and (not UnitIsTappedByPlayer(unit))) then
438 value = DUF_TEXT.Tapped
439 end
440 text = DUF_gsub(text, '$do', value);
441 return text;
442 end,
443 events = {"UNIT_DYNAMIC_FLAGS", "PLAYER_FLAGS_CHANGED"} },
444  
445 -- Unit Reaction - Hostile, Neutral, Friendly
446 ["$re"] = { func = function(text, unit)
447 local value = UnitReaction("player", unit);
448 if (value) then
449 if (value < 4) then
450 value = DUF_TEXT.Hostile;
451 elseif (value == 4) then
452 value = DUF_TEXT.Neutral;
453 else
454 value = DUF_TEXT.Friendly;
455 end
456 end
457 text = DUF_gsub(text, '$re', value);
458 return text;
459 end,
460 events = {} },
461  
462 --PVP Rank
463 ["$pr"] = { func = function(text, unit)
464 local value = GetPVPRankInfo(UnitPVPRank(unit), unit);
465 text = DUF_gsub(text, '$pr', value);
466 return text;
467 end,
468 events = {"UNIT_PVP_UPDATE"} },
469  
470 --PVP Rank Number
471 ["$pn"] = { func = function(text, unit)
472 local value = UnitPVPRank(unit);
473 if (value > 0) then
474 value = value - 4;
475 else
476 value = nil;
477 end
478 text = DUF_gsub(text, '$pn', value);
479 return text;
480 end,
481 events = {"UNIT_PVP_UPDATE"} },
482  
483 --PVP Tagged - PvP or PvP Free For All
484 ["$pt"] = { func = function(text, unit)
485 local value;
486 if (UnitIsPVPFreeForAll(unit)) then
487 value = DUF_TEXT.PVPFree;
488 elseif (UnitIsPVP(unit)) then
489 value = DUF_TEXT.PVP;
490 end
491 text = DUF_gsub(text, '$pt', value);
492 return text;
493 end,
494 events = {"UNIT_PVP_UPDATE"} },
495  
496 --Combo Points as a number
497 ["$cp"] = { func = function(text, unit)
498 local value = GetComboPoints();
499 if (value == 0) then
500 value = "";
501 end
502 text = DUF_gsub(text, '$cp', value);
503 return text;
504 end,
505 events = {"PLAYER_COMBO_POINTS"} },
506  
507 --Mana Label - Mana, Energy, Rage, Focus
508 ["$ml"] = { func = function(text, unit)
509 local value = UnitPowerType(unit);
510 if (value == 0) then
511 value = DUF_TEXT.Mana;
512 elseif (value == 1) then
513 value = DUF_TEXT.Rage;
514 elseif (value == 2) then
515 value = DUF_TEXT.Focus;
516 elseif (value == 3) then
517 value = DUF_TEXT.Energy;
518 end
519 text = DUF_gsub(text, '$ml', value);
520 return text;
521 end,
522 events = {"UNIT_DISPLAYPOWER"} },
523  
524 --Current XP
525 ["$xc"] = { func = function(text, unit)
526 local currentxp = UnitXP(unit);
527 if (not currentxp) then
528 currentxp = 0;
529 end
530 text = DUF_gsub(text, '$xc', currentxp);
531 return text;
532 end,
533 events = {"PLAYER_XP_UPDATE", "UPDATE_EXHAUSTION", "PLAYER_LEVEL_UP", "PLAYER_UPDATE_RESTING"} },
534  
535 --Total XP Needed to Level
536 ["$xl"] = { func = function(text, unit)
537 local maxxp = UnitXPMax(unit);
538 if (not maxxp) then
539 maxxp = 0;
540 end
541 text = DUF_gsub(text, '$xl', maxxp);
542 return text;
543 end,
544 events = {"PLAYER_XP_UPDATE", "UPDATE_EXHAUSTION", "PLAYER_LEVEL_UP", "PLAYER_UPDATE_RESTING"} },
545  
546 --Net XP Needed to Level
547 ["$xd"] = { func = function(text, unit)
548 local currentxp = UnitXP(unit);
549 if (not currentxp) then
550 currentxp = 0;
551 end
552 local maxxp = UnitXPMax(unit);
553 if (not maxxp) then
554 maxxp = 0;
555 end
556 local value = maxxp - currentxp;
557 text = DUF_gsub(text, '$xd', value);
558 return text;
559 end,
560 events = {"PLAYER_XP_UPDATE", "UPDATE_EXHAUSTION", "PLAYER_LEVEL_UP", "PLAYER_UPDATE_RESTING"} },
561  
562 --Percent XP Gained This Level
563 ["$xy"] = { func = function(text, unit)
564 local currentxp = UnitXP(unit);
565 if (not currentxp) then
566 currentxp = 0;
567 end
568 local maxxp = UnitXPMax(unit);
569 if (not maxxp) then
570 maxxp = 0;
571 end
572 local value;
573 if (maxxp == 0) then
574 value = 0;
575 else
576 value = math.floor(currentxp / maxxp * 100);
577 end
578 text = DUF_gsub(text, '$xy', value);
579 return text;
580 end,
581 events = {"PLAYER_XP_UPDATE", "UPDATE_EXHAUSTION", "PLAYER_LEVEL_UP", "PLAYER_UPDATE_RESTING"} },
582  
583 --Percent XP Until Level
584 ["$xx"] = { func = function(text, unit)
585 local currentxp = UnitXP(unit);
586 if (not currentxp) then
587 currentxp = 0;
588 end
589 local maxxp = UnitXPMax(unit);
590 if (not maxxp) then
591 maxxp = 0;
592 end
593 local value;
594 if (maxxp == 0) then
595 value = 0;
596 else
597 value = math.floor(currentxp / maxxp * 100);
598 end
599 value = 100 - value;
600 text = DUF_gsub(text, '$xx', value);
601 return text;
602 end,
603 events = {"PLAYER_XP_UPDATE", "UPDATE_EXHAUSTION", "PLAYER_LEVEL_UP", "PLAYER_UPDATE_RESTING"} },
604  
605 --Rested XP
606 ["$xr"] = { func = function(text, unit)
607 local value = GetXPExhaustion();
608 if (value) then
609 value = math.floor(value / 2);
610 else
611 value = 0;
612 end
613 text = DUF_gsub(text, '$xr', value);
614 return text;
615 end,
616 events = {"PLAYER_XP_UPDATE", "UPDATE_EXHAUSTION", "PLAYER_LEVEL_UP", "PLAYER_UPDATE_RESTING"} },
617  
618 --Rested XP Percentage courtesy of Dsanai
619 ["$xb"] = { func = function(text, unit)
620 local restXP = GetXPExhaustion();
621 local nextlevelXP = UnitXPMax("player");
622 local PercentRest = 0;
623 if (restXP) then
624 PercentRest = DL_round(restXP / nextlevelXP * 100, 0);
625 end
626 text = DUF_gsub(text, '$xb', PercentRest);
627 return text;
628 end,
629 events = {"PLAYER_XP_UPDATE", "UPDATE_EXHAUSTION", "PLAYER_LEVEL_UP", "PLAYER_UPDATE_RESTING"} },
630  
631 --Creature Difficulty - Trivial, Minor, Suicide, etc.
632 ["$cd"] = { func = function(text, unit)
633 local diff = UnitLevel(unit) - UnitLevel("player");
634 local difficulty;
635 if (UnitLevel(unit) == -1) then
636 difficulty = 6;
637 elseif (diff < -GetQuestGreenRange()) then
638 difficulty = 1;
639 elseif (diff < -2) then
640 difficulty = 2;
641 elseif (diff < 3) then
642 difficulty = 3;
643 elseif (diff < 5) then
644 difficulty = 4;
645 elseif (diff < 11) then
646 difficulty = 5;
647 else
648 difficulty = 6;
649 end
650 text = DUF_gsub(text, '$cd', DUF_TEXT["LevelDifference"..difficulty]);
651 return text;
652 end,
653 events = {"UNIT_LEVEL"} },
654  
655 --Guild
656 ["$gu"] = { func = function(text, unit)
657 local value = GetGuildInfo(unit);
658 text = DUF_gsub(text, '$gu', value);
659 return text;
660 end,
661 events = {"UNIT_NAME_UPDATE"} },
662  
663 -- Unit Target's Name
664 ["$tn"] = { func = function(text, unit)
665 local value = this.targetname;
666 if (not value) then
667 value = DUF_TEXT.NoTarget;
668 elseif (UnitIsUnit(unit.."target", "player")) then
669 value = DUF_TEXT.You;
670 elseif (UnitIsUnit(unit.."target", "target")) then
671 value = DUF_TEXT.YourTarget;
672 end
673 text = DUF_gsub(text, '$tn', value);
674 return text;
675 end,
676 events = {} },
677  
678 -- Unit Target's Health
679 ["$th"] = { func = function(text, unit)
680 local value = this.targethealth;
681 if (not this.targetname) then
682 value = nil;
683 end
684 text = DUF_gsub(text, '$th', value);
685 return text;
686 end,
687 events = {} },
688  
689 -- Unit Target's Max Health
690 ["$tx"] = { func = function(text, unit)
691 local value = this.targethealthmax;
692 if (not this.targetname) then
693 value = nil;
694 end
695 text = DUF_gsub(text, '$tx', value);
696 return text;
697 end,
698 events = {} },
699  
700 -- Unit Target's Mana
701 ["$tm"] = { func = function(text, unit)
702 local value = this.targetmana;
703 if (not this.targetname) then
704 value = nil;
705 end
706 text = DUF_gsub(text, '$tm', value);
707 return text;
708 end,
709 events = {} },
710  
711 -- Unit's Target's Max Mana
712 ["$ty"] = { func = function(text, unit)
713 local value = this.targetmanamax;
714 if (not this.targetname) then
715 value = nil;
716 end
717 text = DUF_gsub(text, '$ty', value);
718 return text;
719 end,
720 events = {} },
721  
722 -- Unit's Target's Health Percent
723 ["$ta"] = { func = function(text, unit)
724 local value;
725 if (this.targethealth and this.targethealthmax) then
726 if (this.targethealthmax == 0) then
727 value = 0;
728 else
729 value = math.ceil(this.targethealth / this.targethealthmax * 100);
730 end
731 end
732 if (not this.targetname) then
733 value = nil;
734 end
735 text = DUF_gsub(text, '$ta', value);
736 return text;
737 end,
738 events = {} },
739  
740 -- Unit's Target's Mana Percent
741 ["$tb"] = { func = function(text, unit)
742 local value;
743 if (this.targetmana and this.targetmanamax) then
744 if (this.targetmanamax == 0) then
745 value = 0;
746 else
747 value = math.ceil(this.targetmana / this.targetmanamax * 100);
748 end
749 end
750 if (not this.targetname) then
751 value = nil;
752 end
753 text = DUF_gsub(text, '$tb', value);
754 return text;
755 end,
756 events = {} },
757  
758 -- Unit's Target's Level
759 ["$tl"] = { func = function(text, unit)
760 local value = this.targetlevel;
761 if (not this.targetname) then
762 value = nil;
763 end
764 text = DUF_gsub(text, '$tl', value);
765 return text;
766 end,
767 events = {} },
768  
769 -- Unit's Target's Type
770 ["$tt"] = { func = function(text, unit)
771 local value = this.targettype;
772 if (not this.targetname) then
773 value = nil;
774 end
775 text = DUF_gsub(text, '$tt', value);
776 return text;
777 end,
778 events = {} },
779  
780 -- Color Code
781 ["$co"] = { func = function(text, unit)
782 text = DUF_gsub(text, '$co', '|c');
783 return text;
784 end,
785 events = {} },
786  
787 -- Pet Current XP
788 ["$px"] = { func = function(text, unit)
789 local value = GetPetExperience();
790 text = DUF_gsub(text, '$px', value);
791 return text;
792 end,
793 events = {"UNIT_PET_EXPERIENCE"} },
794  
795 -- Pet XP Needed to Level
796 ["$py"] = { func = function(text, unit)
797 local _,value = GetPetExperience();
798 text = DUF_gsub(text, '$py', value);
799 return text;
800 end,
801 events = {"UNIT_PET_EXPERIENCE"} },
802  
803 -- Pet XP Percent Complete
804 ["$pc"] = { func = function(text, unit)
805 local min,max = GetPetExperience();
806 local value = 0;
807 if (max and min and max > 0) then
808 value = DL_round(min / max * 100, 0);
809 end
810 text = DUF_gsub(text, '$pc', value);
811 return text;
812 end,
813 events = {"UNIT_PET_EXPERIENCE"} },
814  
815 -- Pet XP Percent Needed
816 ["$pp"] = { func = function(text, unit)
817 local min,max = GetPetExperience();
818 local value = 0;
819 if (max and min and max > 0) then
820 value = DL_round(min / max * 100, 0);
821 value = 100 - value;
822 end
823 text = DUF_gsub(text, '$pp', value);
824 return text;
825 end,
826 events = {"UNIT_PET_EXPERIENCE"} },
827  
828 -- Pet XP To Go
829 ["$pg"] = { func = function(text, unit)
830 local min,max = GetPetExperience();
831 local value = 0;
832 if (max and min and max > 0) then
833 value = max - min;
834 end
835 text = DUF_gsub(text, '$pg', value);
836 return text;
837 end,
838 events = {"UNIT_PET_EXPERIENCE"} },
839  
840 -- Pet Happiness
841 ["$ph"] = { func = function(text, unit)
842 local value = GetPetHappiness();
843 text = DUF_gsub(text, '$ph', value);
844 return text;
845 end,
846 events = {"UNIT_HAPPINESS"} },
847  
848 -- NPC
849 ["$np"] = { func = function(text, unit)
850 local value;
851 if (not UnitIsPlayer(unit)) then
852 value = "NPC";
853 end
854 text = DUF_gsub(text, '$np', value);
855 return text;
856 end,
857 events = {} },
858  
859 -- Civilian
860 ["$cv"] = { func = function(text, unit)
861 local value;
862 if (UnitIsCivilian(unit)) then
863 value = "Civilian";
864 end
865 text = DUF_gsub(text, '$cv', value);
866 return text;
867 end,
868 events = {} },
869  
870 -- Shorthand Elite Text
871 ["$cx"] = { func = function(text, unit)
872 local value = UnitClassification(unit);
873 if (value == "normal") then
874 value = nil;
875 elseif (value == "elite" or (not UnitName(unit))) then
876 value = "+";
877 elseif (value == "worldboss") then
878 value = "++";
879 elseif (value == "rare") then
880 value = "(R)";
881 elseif (value == "rareelite") then
882 value = "(R)+";
883 end
884 text = DUF_gsub(text, '$cx', value);
885 return text;
886 end,
887 events = {"UNIT_CLASSIFICATION_CHANGED"} },
888  
889 -- Reaction Color Context
890 ["$cr"] = { func = function(text, unit)
891 local value;
892 local r, g, b = DUF_Get_ReactionColor(unit);
893 if (r and g and b) then
894 value = "|cFF"..string.format("%02X%02X%02X", r * 255.0, g * 255.0, b * 255.0);
895 end
896 text = DUF_gsub(text, '$cr', value);
897 return text;
898 end,
899 events = {} },
900  
901 -- Class Color Context
902 ["$cw"] = { func = function(text, unit)
903 local value;
904 local r, g, b = DUF_Get_ClassColor(unit);
905 if (r and g and b) then
906 value = "|cFF"..string.format("%02X%02X%02X", r * 255.0, g * 255.0, b * 255.0);
907 end
908 text = DUF_gsub(text, '$cw', value);
909 return text;
910 end,
911 events = {} },
912  
913 -- Mana Color Context
914 ["$cm"] = { func = function(text, unit)
915 local value;
916 local r, g, b = DUF_Get_ManaColor(unit, DUF_Settings[DUF_INDEX][DUF_FRAME_DATA[unit].index].TextBox[this:GetID()].textcolor);
917 if (r and g and b) then
918 value = "|cFF"..string.format("%02X%02X%02X", r * 255.0, g * 255.0, b * 255.0);
919 end
920 text = DUF_gsub(text, '$cm', value);
921 return text;
922 end,
923 events = {} },
924  
925 -- Health Color Context
926 ["$ch"] = { func = function(text, unit)
927 local value;
928 local r, g, b = DUF_Get_HealthColor(unit, DUF_Settings[DUF_INDEX][DUF_FRAME_DATA[unit].index].TextBox[this:GetID()].textcolor);
929 if (r and g and b) then
930 value = "|cFF"..string.format("%02X%02X%02X", r * 255.0, g * 255.0, b * 255.0);
931 end
932 text = DUF_gsub(text, '$ch', value);
933 return text;
934 end,
935 events = {} },
936  
937 -- Difficulty Color Context
938 ["$cq"] = { func = function(text, unit)
939 local value;
940 local r, g, b = DUF_Get_DifficultyColor(unit);
941 if (r and g and b) then
942 value = "|cFF"..string.format("%02X%02X%02X", r * 255.0, g * 255.0, b * 255.0);
943 end
944 text = DUF_gsub(text, '$cq', value);
945 return text;
946 end,
947 events = {} },
948  
949 -- Powertype Color
950 ["$cz"] = { func = function(text, unit)
951 local color, value;
952 local unit = this:GetParent().unit;
953 local pt = UnitPowerType(unit);
954 if (pt == 0) then
955 color = DUF_Settings[DUF_INDEX][DUF_FRAME_DATA[unit].index].StatusBar[2].manacolor;
956 elseif (pt == 1) then
957 color = DUF_Settings[DUF_INDEX][DUF_FRAME_DATA[unit].index].StatusBar[2].ragecolor;
958 elseif (pt == 2) then
959 color = DUF_Settings[DUF_INDEX][DUF_FRAME_DATA[unit].index].StatusBar[2].focuscolor;
960 elseif (pt == 3) then
961 color = DUF_Settings[DUF_INDEX][DUF_FRAME_DATA[unit].index].StatusBar[2].energycolor;
962 end
963 if (color.r and color.g and color.b) then
964 value = "|cFF"..string.format("%02X%02X%02X", color.r * 255.0, color.g * 255.0, color.b * 255.0);
965 end
966 text = DUF_gsub(text, '$cz', value);
967 return text;
968 end,
969 events = {"UNIT_DISPLAYPOWER"} },
970  
971 -- Watched Faction
972 ["$wf"] = { func = function(text, unit)
973 local name = GetWatchedFactionInfo();
974 if (not name) then name = "" end
975 text = string.gsub(text, '$wf', name);
976 return text;
977 end,
978 events = {"UPDATE_FACTION"} },
979  
980 -- Watched Faction Max
981 ["$wm"] = { func = function(text, unit)
982 local _, _, min, max = GetWatchedFactionInfo();
983 text = string.gsub(text, '$wm', max - min);
984 return text;
985 end,
986 events = {"UPDATE_FACTION", "PLAYER_LEVEL_UP"} },
987  
988 -- Watched Faction Current
989 ["$wc"] = { func = function(text, unit)
990 local _, _, min, _, value = GetWatchedFactionInfo();
991 text = string.gsub(text, '$wc', value - min);
992 return text;
993 end,
994 events = {"UPDATE_FACTION", "PLAYER_LEVEL_UP"} },
995  
996 -- Watched Faction Percent
997 ["$wp"] = { func = function(text, unit)
998 local _, _, min, max, value = GetWatchedFactionInfo();
999 text = string.gsub(text, '$wp', DL_round((value-min)/(max - min)*100, 0));
1000 return text;
1001 end,
1002 events = {"UPDATE_FACTION", "PLAYER_LEVEL_UP"} },
1003  
1004 -- Watched Faction Reaction
1005 ["$wr"] = { func = function(text, unit)
1006 local _, reaction = GetWatchedFactionInfo();
1007 reaction = GetText("FACTION_STANDING_LABEL"..reaction, UnitSex("player"))
1008 if (not reaction) then reaction = "" end
1009 text = string.gsub(text, '$wr', reaction);
1010 return text;
1011 end,
1012 events = {"UPDATE_FACTION", "PLAYER_LEVEL_UP"} },
1013 };
1014  
1015 function DUF_UnitSex(unit)
1016 value = UnitSex(unit);
1017 if (value == 2) then
1018 value = DUF_TEXT.Male;
1019 elseif (value == 3) then
1020 value = DUF_TEXT.Female;
1021 else
1022 value = DUF_TEXT.Neuter;
1023 end
1024 return value;
1025 end
1026  
1027 function DUF_gsub(text, variable, value)
1028 if (value) then
1029 text = string.gsub(text, variable, value);
1030 elseif (string.find(text, " "..variable)) then
1031 text = string.gsub(text, " "..variable, "");
1032 else
1033 text = string.gsub(text, variable, "");
1034 end
1035 return text;
1036 end