vanilla-wow-addons – Blame information for rev 1
?pathlinks?
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 = TipBuddy_gsub(text, 'variable', value); |
||
7 | return text; |
||
8 | end, |
||
9 | |||
10 | variable - Can be anything you want and doesn't necessarily have to be preceded with a $. |
||
11 | func - This is the function called when the variable needs to be updated. |
||
12 | text - This is the entire text of the TextBox and must be returned after it is modified. |
||
13 | unit - This is the unit ID (party1, player, target, etc.) that the TextBox refers to. |
||
14 | No other parameters will be passed to your function and those 2 will always be passed. |
||
15 | text = TipBuddy_gsub(text, 'variable', value) - This line is used to replace the variable |
||
16 | with the value you generated in the preceding code. It handles trimming leading spaces |
||
17 | if value is nil or false. |
||
18 | --]] |
||
19 | |||
20 | TB_VARIABLE_FUNCTIONS = { |
||
21 | -- New Line (resets coloring) |
||
22 | ["$nl"] = { func = function(text, unit) |
||
23 | text = string.gsub(text, '$nl', "\n"); |
||
24 | return text; |
||
25 | end, |
||
26 | }, |
||
27 | |||
28 | -- Carriage Return (resets coloring) |
||
29 | ["\n"] = { func = function(text, unit) |
||
30 | text = string.gsub(text, "\n", "|r\n"); |
||
31 | return text; |
||
32 | end, |
||
33 | }, |
||
34 | -- Name |
||
35 | ["$nm"] = { func = function(text, unit) |
||
36 | local unitname = UnitName(unit); |
||
37 | if (not unitname) then unitname = unit; end |
||
38 | text = TipBuddy_gsub(text, '$nm', unitname, "nm"); |
||
39 | return text; |
||
40 | end, |
||
41 | }, |
||
42 | |||
43 | --Guild - Returns guild name for PCs, title for NPCs |
||
44 | ["$gu"] = { func = function(text, unit) |
||
45 | local value = TipBuddy.gtt_guild; |
||
46 | text = TipBuddy_gsub(text, '$gu', value, "gu"); |
||
47 | return text; |
||
48 | end, |
||
49 | }, |
||
50 | |||
51 | --Guild Title - returns the player's title rank in their guild |
||
52 | ["$gt"] = { func = function(text, unit) |
||
53 | local _, value = GetGuildInfo(unit); |
||
54 | text = TipBuddy_gsub(text, '$gt', value, "gt"); |
||
55 | return text; |
||
56 | end, |
||
57 | }, |
||
58 | |||
59 | -- Level |
||
60 | ["$lv"] = { func = function(text, unit) |
||
61 | TipBuddy.gtt_level = UnitLevel(unit); |
||
62 | local level = TipBuddy.gtt_level; |
||
63 | if (level == -1) then |
||
64 | level = "??"; |
||
65 | end |
||
66 | text = TipBuddy_gsub(text, '$lv', level, "lv"); |
||
67 | return text; |
||
68 | end, |
||
69 | }, |
||
70 | |||
71 | -- Unit's Class |
||
72 | ["$cl"] = { func = function(text, unit) |
||
73 | --local class = TipBuddy.gtt_class; |
||
74 | local class = UnitClass(unit); |
||
75 | text = TipBuddy_gsub(text, '$cl', class, "cl"); |
||
76 | return text; |
||
77 | end, |
||
78 | }, |
||
79 | |||
80 | -- Race (players only) |
||
81 | ["$rc"] = { func = function(text, unit) |
||
82 | local race = UnitRace(unit); |
||
83 | text = TipBuddy_gsub(text, '$rc', race, "rc"); |
||
84 | return text; |
||
85 | end, |
||
86 | }, |
||
87 | |||
88 | -- Faction - Horde, Alliance, or nothing (players only) |
||
89 | ["$fa"] = { func = function(text, unit) |
||
90 | local value = UnitFactionGroup(unit); |
||
91 | if (not UnitName(unit)) then value = "faction"; end |
||
92 | text = TipBuddy_gsub(text, '$fa', value, "fa"); |
||
93 | return text; |
||
94 | end, |
||
95 | }, |
||
96 | |||
97 | -- City Faction - Stormwind, Darkspear Trolls, etc. (NPCs only) |
||
98 | ["$cf"] = { func = function(text, unit) |
||
99 | local value = TipBuddy.gtt_cityfac; |
||
100 | if (not UnitName(unit)) then value = "city faction"; end |
||
101 | text = TipBuddy_gsub(text, '$cf', value, "cf"); |
||
102 | return text; |
||
103 | end, |
||
104 | }, |
||
105 | |||
106 | -- Current Health (actual) |
||
107 | ["$hc"] = { func = function(text, unit) |
||
108 | local health = TB_GetHealth_Text( unit, "current" ); |
||
109 | text = TipBuddy_gsub(text, '$hc', health, "hc"); |
||
110 | return text; |
||
111 | end, |
||
112 | }, |
||
113 | |||
114 | -- Max Health (actual) |
||
115 | ["$hm"] = { func = function(text, unit) |
||
116 | local healthmax = TB_GetHealth_Text( unit, "max" ); |
||
117 | text = TipBuddy_gsub(text, '$hm', healthmax, "hm"); |
||
118 | return text; |
||
119 | end, |
||
120 | }, |
||
121 | |||
122 | -- Health as a percent |
||
123 | ["$hp"] = { func = function(text, unit) |
||
124 | local health = TB_GetHealth_Text( unit, "percent" ); |
||
125 | text = TipBuddy_gsub(text, '$hp', health, "hp"); |
||
126 | return text; |
||
127 | end, |
||
128 | }, |
||
129 | |||
130 | -- Current Mana (actual) |
||
131 | ["$mc"] = { func = function(text, unit) |
||
132 | local mana = UnitMana(unit); |
||
133 | text = TipBuddy_gsub(text, '$mc', mana, "mc"); |
||
134 | return text; |
||
135 | end, |
||
136 | }, |
||
137 | |||
138 | -- Max Mana (actual) |
||
139 | ["$mm"] = { func = function(text, unit) |
||
140 | local manamax = UnitManaMax(unit); |
||
141 | if (not manamax) then |
||
142 | manamax = 0; |
||
143 | end |
||
144 | text = TipBuddy_gsub(text, '$mm', manamax, "mm"); |
||
145 | return text; |
||
146 | end, |
||
147 | }, |
||
148 | |||
149 | -- Mana as a percent |
||
150 | ["$mp"] = { func = function(text, unit) |
||
151 | local mana = UnitMana(unit); |
||
152 | local manamax = UnitManaMax(unit); |
||
153 | local percent = 0; |
||
154 | if (manamax == 0) then |
||
155 | percent = 0; |
||
156 | else |
||
157 | percent = math.floor(mana/manamax * 100); |
||
158 | end |
||
159 | text = TipBuddy_gsub(text, '$mp', percent, "mp"); |
||
160 | return text; |
||
161 | end, |
||
162 | }, |
||
163 | |||
164 | --[[ Death Status - DEAD, GHOST, or nothing |
||
165 | ["$ds"] = { func = function(text, unit) |
||
166 | local value; |
||
167 | if (UnitIsGhost(unit)) then |
||
168 | value = TipBuddy_TEXT.Ghost; |
||
169 | elseif (UnitIsDead(unit)) then |
||
170 | value = TipBuddy_TEXT.Dead; |
||
171 | elseif (not UnitName(unit)) then |
||
172 | value = TipBuddy_TEXT.Dead; |
||
173 | else |
||
174 | value = ""; |
||
175 | end |
||
176 | text = TipBuddy_gsub(text, '$ds', value); |
||
177 | return text; |
||
178 | end, |
||
179 | },]] |
||
180 | |||
181 | --[[In Combat - COMBAT or nothing |
||
182 | ["$ic"] = { func = function(text, unit) |
||
183 | local value = ""; |
||
184 | if (UnitAffectingCombat(unit) or (not UnitName(unit))) then |
||
185 | value = TipBuddy_TEXT.Combat; |
||
186 | end |
||
187 | text = TipBuddy_gsub(text, '$ic', value); |
||
188 | return text; |
||
189 | end, |
||
190 | },]] |
||
191 | |||
192 | -- NPC Classification - Elite, Boss, etc. |
||
193 | ["$ns"] = { func = function(text, unit) |
||
194 | local value = UnitClassification(unit); |
||
195 | if (value == "normal") then |
||
196 | value = ""; |
||
197 | elseif (value == "elite" or (not UnitName(unit))) then |
||
198 | value = TB_elite; |
||
199 | elseif (value == "worldboss") then |
||
200 | value = TB_worldboss; |
||
201 | elseif (value == "rare") then |
||
202 | value = TB_rare; |
||
203 | elseif (value == "rareelite") then |
||
204 | value = TB_rareelite; |
||
205 | end |
||
206 | text = TipBuddy_gsub(text, '$ns', value, "ns"); |
||
207 | return text; |
||
208 | end, |
||
209 | }, |
||
210 | |||
211 | -- NPC Type - Beast, Humanoid, Undead, etc. |
||
212 | ["$nt"] = { func = function(text, unit) |
||
213 | local value = UnitCreatureType(unit); |
||
214 | if (UnitIsPlayer(unit)) then value = nil; end |
||
215 | if (not UnitName(unit)) then value = "beast"; end |
||
216 | text = TipBuddy_gsub(text, '$nt', value, "nt"); |
||
217 | return text; |
||
218 | end, |
||
219 | }, |
||
220 | |||
221 | -- NPC Family - Bear, Crab, Cat, etc. |
||
222 | ["$nf"] = { func = function(text, unit) |
||
223 | local value = UnitCreatureFamily(unit); |
||
224 | if (not UnitName(unit)) then value = "cat"; end |
||
225 | text = TipBuddy_gsub(text, '$nf', value, "nf"); |
||
226 | return text; |
||
227 | end, |
||
228 | }, |
||
229 | |||
230 | -- Tapped - TAPPED or nothing |
||
231 | ["$tp"] = { func = function(text, unit) |
||
232 | local value; |
||
233 | if (UnitIsTapped(unit) and (not UnitIsTappedByPlayer(unit))) then |
||
234 | value = TB_tapped; |
||
235 | end |
||
236 | text = TipBuddy_gsub(text, '$tp', value, "tp"); |
||
237 | return text; |
||
238 | end, |
||
239 | }, |
||
240 | |||
241 | -- Unit Reaction - Hostile, Neutral, Friendly |
||
242 | ["$re"] = { func = function(text, unit) |
||
243 | local value = UnitReaction("player", unit); |
||
244 | if (value) then |
||
245 | if (value < 4) then |
||
246 | value = FACTION_STANDING_LABEL2; |
||
247 | elseif (value == 4) then |
||
248 | value = FACTION_STANDING_LABEL4; |
||
249 | else |
||
250 | value = FACTION_STANDING_LABEL5; |
||
251 | end |
||
252 | end |
||
253 | text = TipBuddy_gsub(text, '$re', value, "re"); |
||
254 | return text; |
||
255 | end, |
||
256 | }, |
||
257 | |||
258 | --PVP Rank |
||
259 | ["$pr"] = { func = function(text, unit) |
||
260 | local value = GetPVPRankInfo(UnitPVPRank(unit), unit); |
||
261 | text = TipBuddy_gsub(text, '$pr', value, "pr"); |
||
262 | return text; |
||
263 | end, |
||
264 | }, |
||
265 | |||
266 | --PVP Rank Number |
||
267 | ["$pn"] = { func = function(text, unit) |
||
268 | local value = UnitPVPRank(unit); |
||
269 | if (value > 0) then |
||
270 | value = value - 4; |
||
271 | else |
||
272 | value = nil; |
||
273 | end |
||
274 | text = TipBuddy_gsub(text, '$pn', value, "pn"); |
||
275 | return text; |
||
276 | end, |
||
277 | }, |
||
278 | |||
279 | --PVP Flagged - PvP or PvP Free For All |
||
280 | ["$pv"] = { func = function(text, unit) |
||
281 | local value; |
||
282 | if (UnitIsPVPFreeForAll(unit)) then |
||
283 | value = "FFA"; |
||
284 | elseif (UnitIsPVP(unit)) then |
||
285 | value = PVP_ENABLED; |
||
286 | end |
||
287 | text = TipBuddy_gsub(text, '$pv', value, "pv"); |
||
288 | return text; |
||
289 | end, |
||
290 | }, |
||
291 | |||
292 | --Mana Label - Mana, Energy, Rage, Focus |
||
293 | ["$ml"] = { func = function(text, unit) |
||
294 | local value = UnitPowerType(unit); |
||
295 | if (value == 0) then |
||
296 | value = MANA; |
||
297 | elseif (value == 1) then |
||
298 | value = RAGE; |
||
299 | elseif (value == 2) then |
||
300 | value = FOCUS; |
||
301 | elseif (value == 3) then |
||
302 | value = ENERGY; |
||
303 | end |
||
304 | text = TipBuddy_gsub(text, '$ml', value, "ml"); |
||
305 | return text; |
||
306 | end, |
||
307 | }, |
||
308 | |||
309 | --Unit Difficulty - Trivial, Minor, Suicide, etc. |
||
310 | ["$df"] = { func = function(text, unit) |
||
311 | local _, value = TipBuddy_GetDifficultyColor(UnitLevel(unit)); |
||
312 | text = TipBuddy_gsub(text, '$df', value, "df"); |
||
313 | return text; |
||
314 | end, |
||
315 | }, |
||
316 | |||
317 | -- Unit Target's Target Name |
||
318 | ["$tn"] = { func = function(text, unit) |
||
319 | local target = TipBuddy_Adv_TargetsTarget( unit ); |
||
320 | text = TipBuddy_gsub(text, '$tn', target, "tn"); |
||
321 | return text; |
||
322 | end, |
||
323 | }, |
||
324 | |||
325 | -- Civilian |
||
326 | --[[["$cv"] = { func = function(text, unit) |
||
327 | local value; |
||
328 | if (UnitIsCivilian(unit)) then |
||
329 | value = "Civilian"; |
||
330 | end |
||
331 | text = TipBuddy_gsub(text, '$cv', value, "cv"); |
||
332 | return text; |
||
333 | end, |
||
334 | },]] |
||
335 | |||
336 | -- Shorthand Elite Text |
||
337 | ["$cx"] = { func = function(text, unit) |
||
338 | local value = UnitClassification(unit); |
||
339 | if (value == "normal") then |
||
340 | value = nil; |
||
341 | elseif (value == "elite" or (not UnitName(unit))) then |
||
342 | value = "+"; |
||
343 | elseif (value == "worldboss") then |
||
344 | value = "++"; |
||
345 | elseif (value == "rare") then |
||
346 | value = "(R)"; |
||
347 | elseif (value == "rareelite") then |
||
348 | value = "(R)+"; |
||
349 | end |
||
350 | text = TipBuddy_gsub(text, '$cx', value, "cx"); |
||
351 | return text; |
||
352 | end, |
||
353 | }, |
||
354 | |||
355 | ---- COLORS ---- |
||
356 | -- Reaction Name |
||
357 | ["@Crn"] = { func = function(text, unit) |
||
358 | local value = getglobal("tbcolor_nam_"..TipBuddy_GetUnitReaction( unit )); |
||
359 | text = TipBuddy_gsub(text, '@Crn', value); |
||
360 | return text; |
||
361 | end, |
||
362 | }, |
||
363 | |||
364 | -- Reaction Guild |
||
365 | ["@Crg"] = { func = function(text, unit) |
||
366 | local value = getglobal("tbcolor_gld_"..TipBuddy_GetUnitReaction( unit )); |
||
367 | text = TipBuddy_gsub(text, '@Crg', value); |
||
368 | return text; |
||
369 | end, |
||
370 | }, |
||
371 | |||
372 | -- Difficulty |
||
373 | ["@Cdf"] = { func = function(text, unit) |
||
374 | local value = TipBuddy_GetDifficultyColor(UnitLevel(unit)); |
||
375 | text = TipBuddy_gsub(text, '@Cdf', value); |
||
376 | return text; |
||
377 | end, |
||
378 | }, |
||
379 | |||
380 | -- Class Color |
||
381 | ["@Ccl"] = { func = function(text, unit) |
||
382 | if (UnitClass(unit) == TB_mage) then |
||
383 | TipBuddy.gtt_classcolor = tbcolor_cls_mage; |
||
384 | elseif (UnitClass(unit) == TB_warlock) then |
||
385 | TipBuddy.gtt_classcolor = tbcolor_cls_warlock; |
||
386 | elseif (UnitClass(unit) == TB_priest) then |
||
387 | TipBuddy.gtt_classcolor = tbcolor_cls_priest; |
||
388 | elseif (UnitClass(unit) == TB_druid) then |
||
389 | TipBuddy.gtt_classcolor = tbcolor_cls_druid; |
||
390 | elseif (UnitClass(unit) == TB_shaman) then |
||
391 | TipBuddy.gtt_classcolor = tbcolor_cls_shaman; |
||
392 | elseif (UnitClass(unit) == TB_paladin) then |
||
393 | TipBuddy.gtt_classcolor = tbcolor_cls_paladin; |
||
394 | elseif (UnitClass(unit) == TB_rogue) then |
||
395 | TipBuddy.gtt_classcolor = tbcolor_cls_rogue; |
||
396 | elseif (UnitClass(unit) == TB_hunter) then |
||
397 | TipBuddy.gtt_classcolor = tbcolor_cls_hunter; |
||
398 | elseif (UnitClass(unit) == TB_warrior) then |
||
399 | TipBuddy.gtt_classcolor = tbcolor_cls_warrior; |
||
400 | else |
||
401 | TipBuddy.gtt_classcolor = tbcolor_cls_other; |
||
402 | end |
||
403 | local value = TipBuddy.gtt_classcolor; |
||
404 | text = TipBuddy_gsub(text, '@Ccl', value); |
||
405 | return text; |
||
406 | end, |
||
407 | }, |
||
408 | |||
409 | -- Target's Target Color (only color's if the unit has a target) |
||
410 | ["@Ctt"] = { func = function(text, unit) |
||
411 | local _, value = TipBuddy_Adv_TargetsTarget( unit ); |
||
412 | text = TipBuddy_gsub(text, '@Ctt', value); |
||
413 | return text; |
||
414 | end, |
||
415 | }, |
||
416 | |||
417 | |||
418 | -- Corpse Color |
||
419 | -- Will only color text if unit is a corpse |
||
420 | ["@Ccp"] = { func = function(text, unit) |
||
421 | local value; |
||
422 | if (UnitHealth(unit) <= 0) then |
||
423 | value = tbcolor_corpse; |
||
424 | --TipBuddy.gtt_classlvlcolor = tbcolor_corpse; |
||
425 | --TipBuddy.gtt_classcorpse = " "..CORPSE; |
||
426 | else |
||
427 | value = ""; |
||
428 | end |
||
429 | text = TipBuddy_gsub(text, '@Ccp', value); |
||
430 | return text; |
||
431 | end, |
||
432 | }, |
||
433 | |||
434 | -- Orange |
||
435 | ["@Cor"] = { func = function(text, unit) |
||
436 | local value = TB_NML_TXT; |
||
437 | text = TipBuddy_gsub(text, '@Cor', value); |
||
438 | return text; |
||
439 | end, |
||
440 | }, |
||
441 | -- White |
||
442 | ["@Cwt"] = { func = function(text, unit) |
||
443 | local value = TB_WHT_TXT; |
||
444 | text = TipBuddy_gsub(text, '@Cwt', value); |
||
445 | return text; |
||
446 | end, |
||
447 | }, |
||
448 | -- Grey |
||
449 | ["@Cgy"] = { func = function(text, unit) |
||
450 | local value = TB_GRY_TXT; |
||
451 | text = TipBuddy_gsub(text, '@Cgy', value); |
||
452 | return text; |
||
453 | end, |
||
454 | }, |
||
455 | -- Red |
||
456 | ["@Crd"] = { func = function(text, unit) |
||
457 | local value = TB_RED_TXT; |
||
458 | text = TipBuddy_gsub(text, '@Crd', value); |
||
459 | return text; |
||
460 | end, |
||
461 | }, |
||
462 | -- Green |
||
463 | ["@Cgn"] = { func = function(text, unit) |
||
464 | local value = TB_GRN_TXT; |
||
465 | text = TipBuddy_gsub(text, '@Cgn', value); |
||
466 | return text; |
||
467 | end, |
||
468 | }, |
||
469 | -- Yellow |
||
470 | ["@Cyw"] = { func = function(text, unit) |
||
471 | local value = TB_YLW_TXT; |
||
472 | text = TipBuddy_gsub(text, '@Cyw', value); |
||
473 | return text; |
||
474 | end, |
||
475 | }, |
||
476 | -- Blue |
||
477 | ["@Cbl"] = { func = function(text, unit) |
||
478 | local value = TB_BLE_TXT; |
||
479 | text = TipBuddy_gsub(text, '@Cbl', value); |
||
480 | return text; |
||
481 | end, |
||
482 | }, |
||
483 | -- Pink |
||
484 | ["@Cpk"] = { func = function(text, unit) |
||
485 | local value = TB_PNK_TXT; |
||
486 | text = TipBuddy_gsub(text, '@Cpk', value); |
||
487 | return text; |
||
488 | end, |
||
489 | } |
||
490 | }; |
||
491 | |||
492 | function TipBuddy_gsub(text, variable, value, tag) |
||
493 | if (not tag) then |
||
494 | tag = ""; |
||
495 | end |
||
496 | if (value and value ~= "") then |
||
497 | if (string.find(text, "<"..tag..">.-"..variable..".-<\/"..tag..">")) then |
||
498 | --TB_AddMessage("found pattern: "..variable); |
||
499 | text = string.gsub(text, "<"..tag..">(.-)"..variable.."(.-)<\/"..tag..">", "%1"..value.."%2"); |
||
500 | else |
||
501 | --TB_AddMessage("didn't find pattern...: "..variable); |
||
502 | text = string.gsub(text, variable, value); |
||
503 | end |
||
504 | elseif (string.find(text, "<"..tag..">.-"..variable..".-<\/"..tag..">")) then |
||
505 | text = string.gsub(text, "<"..tag..">.-"..variable..".-</"..tag..">", ""); |
||
506 | else |
||
507 | text = string.gsub(text, variable, "", 1); |
||
508 | end |
||
509 | --TB_AddMessage("start: "..text); |
||
510 | return text; |
||
511 | end |