vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 DYKey = nil;
2 local pre_UseAction;
3 DYVar = { init, attack, once, combat, hate, shot = true, crazy = true, cast = true, target, dead, friend, yellow, class, mount, buff, debuff, use = true, aiminit, dk = true, invul = true, panic, usetimer = 0; };
4 function DefendYourself_OnLoad()
5 SlashCmdList["DEFENDSLASH"] = DefendYourself_Main_ChatCommandHandler;
6 SLASH_DEFENDSLASH1 = "/defendyourself";
7 SLASH_DEFENDSLASH2 = "/dy";
8 this:RegisterEvent("VARIABLES_LOADED");
9 this:RegisterEvent("PLAYER_ENTER_COMBAT");
10 this:RegisterEvent("PLAYER_LEAVE_COMBAT");
11 this:RegisterEvent("PLAYER_REGEN_ENABLED");
12 this:RegisterEvent("PLAYER_REGEN_DISABLED");
13 this:RegisterEvent("PLAYER_TARGET_CHANGED");
14 this:RegisterEvent("START_AUTOREPEAT_SPELL");
15 this:RegisterEvent("STOP_AUTOREPEAT_SPELL");
16 this:RegisterEvent("PLAYER_CONTROL_LOST");
17 this:RegisterEvent("PLAYER_CONTROL_GAINED");
18 this:RegisterEvent("SPELLCAST_START");
19 this:RegisterEvent("SPELLCAST_STOP");
20 this:RegisterEvent("INSTANCE_BOOT_START");
21 this:RegisterEvent("INSTANCE_BOOT_STOP");
22 this:RegisterEvent("UI_ERROR_MESSAGE");
23 this:RegisterEvent("CHAT_MSG_COMBAT_PARTY_HITS");
24 this:RegisterEvent("CHAT_MSG_COMBAT_PARTY_MISSES");
25 this:RegisterEvent("CHAT_MSG_COMBAT_CREATURE_VS_PARTY_HITS");
26 this:RegisterEvent("CHAT_MSG_COMBAT_CREATURE_VS_PARTY_MISSES");
27 this:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS");
28 this:RegisterEvent("CHAT_MSG_SPELL_AURA_GONE_SELF");
29  
30 end
31  
32 function UUIToggleDY()
33 if( DYmenu:IsVisible() ) then
34 DYmenu:Hide();
35 else
36 DYmenu:Show();
37 end
38 end
39  
40 function DY_RegisterUltimateUI()
41 if(UltimateUI_RegisterButton) then
42 UltimateUI_RegisterButton (
43 "DefendYourself",
44 "Options",
45 "|cFF00CC00DefendYourself|r\nHelps with automated combat actions such as\nauto-attacking, ignoring enemies with debuffs like\nsheep, etc.",
46 "Interface\\Icons\\Ability_Defend",
47 UUIToggleDY
48 );
49 end
50 end
51  
52 function DefendYourself_OnEvent(event, arg1, arg2, arg3)
53 if (not DYVar.class and UnitClass("player")) then
54 local _, tempclassname = UnitClass("player");
55 DYVar.class = strlower(tempclassname);
56 end
57 if event == "VARIABLES_LOADED" then
58 DYVar.init = true;
59 DefendYourself_UnitSave();
60 DY_RegisterUltimateUI();
61 if(myAddOnsList) then
62 myAddOnsList.DefendYourself = {name = DEFEND_CONFIG_HEADER, description = DEFEND_CONFIG_HEADER_INFO, version = DEFEND_CONFIG_VERSION, category = MYADDONS_CATEGORY_COMBAT, frame = "DefendYourselfFrame", optionsframe = "DYmenu"};
63 end
64 if not DYKey.On and DYKey.ReOn then DYKey.On = true; DYKey.ReOn = nil; elseif DYKey.ReOn then DYKey.ReOn = nil; end
65 elseif DYKey and DYKey.On then
66 if DYturn_Event then DYturn_Event(event, arg1, arg2, arg3); end
67 if event == "PLAYER_TARGET_CHANGED" then
68 DYVar.once = true;
69 elseif event == "PLAYER_ENTER_COMBAT" then
70 DYVar.combat = true;
71 elseif event == "PLAYER_LEAVE_COMBAT" then
72 DYVar.combat = nil;
73 if DYVar.attack then DYVar.once = true; end
74 elseif event == "PLAYER_REGEN_ENABLED" or event == "INSTANCE_BOOT_START" or event == "INSTANCE_BOOT_STOP" then
75 if not DYKey.Safe then DYVar.hate = nil; end
76 elseif event == "PLAYER_REGEN_DISABLED" then
77 DYVar.hate = true;
78 elseif event == "START_AUTOREPEAT_SPELL" then
79 DYVar.shot = nil;
80 elseif event == "STOP_AUTOREPEAT_SPELL" then
81 DYVar.shot = true;
82 elseif event == "PLAYER_CONTROL_LOST" then
83 DYVar.crazy = nil;
84 elseif event == "PLAYER_CONTROL_GAINED" then
85 if not DYVar.crazy then
86 TargetLastEnemy();
87 end
88 DYVar.crazy = true;
89 elseif event == "SPELLCAST_START" then
90 DYVar.spell = nil;
91 elseif event == "SPELLCAST_STOP" then
92 DYVar.spell = true;
93 if not DYVar.aiminit then
94 if DYVar.class and strfind(DYVar.class, "hunter") or strfind(DYVar.class, "rogue") then
95 pre_UseAction = UseAction;
96 UseAction = DefendYourself_checkUse;
97 end
98 DYVar.aiminit = true;
99 end
100 if not DYVar.combat and not DYVar.once then DYVar.once = true; end
101 elseif event == "UI_ERROR_MESSAGE" then
102 if (arg1 == ERR_NO_ATTACK_TARGET or arg1 == ERR_INVALID_ATTACK_TARGET) then
103 DYVar.target = nil;
104 DYVar.once = nil;
105 elseif (arg1 == ERR_WRONG_DIRECTION_FOR_ATTACK or arg1 == ERR_BADATTACKFACING) then
106 DYVar.once = nil;
107 elseif (arg1 == SPELL_FAILED_TOO_CLOSE) then
108 DYVar.use = true;
109 DYVar.shot = true;
110 end
111 elseif event == "CHAT_MSG_COMBAT_PARTY_HITS" or event == "CHAT_MSG_COMBAT_PARTY_MISSES" then
112 if DefendYourself_Panic and DefendYourself_Panic(0) then return; end
113 if DYKey.Assist then
114 local pname;
115 for i = 1, GetNumPartyMembers() do
116 if (strfind(arg1, UnitName("party"..i))) then
117 pname = i;
118 break;
119 end
120 end
121 if pname and not UnitExists("target") and DYVar.buff then
122 TargetUnit("party"..pname.."target");
123 end
124 end
125 elseif event == "CHAT_MSG_COMBAT_CREATURE_VS_PARTY_HITS" or event == "CHAT_MSG_COMBAT_CREATURE_VS_PARTY_MISSES" then
126 if DefendYourself_Panic and DefendYourself_Panic(0) then return; end
127 if DYKey.Assist then
128 local index = strfind(arg1, "hits");
129 if index and not UnitExists("target") and DYVar.buff then
130 local command = strsub(arg1, 1, index-2);
131 TargetByName(command);
132 if (UnitIsDead("target")) then
133 TargetNearestEnemy();
134 end
135 end
136 end
137 elseif event == "CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS" and arg1 == "You gain Self Invulnerability." then
138 DYVar.invul = nil;
139 elseif event == "CHAT_MSG_SPELL_AURA_GONE_SELF" and arg1 == "Self Invulnerability fades from you." then
140 DYVar.invul = true;
141 end
142 DefendYourself_Check();
143 DefendYourself_Trip();
144 end
145 end
146  
147 function DefendYourself_checkUse(arg1, arg2, arg3)
148 if (GetActionText(arg1)) then
149 local a, b, c = GetMacroInfo(GetMacroIndexByName(GetActionText(arg1)));
150 if c and (strfind(strlower(c), "aimed shot")) then
151 DYVar.use = nil;
152 elseif c and ((strfind(strlower(c), strlower(DefendYourself_noattack[1])) or strfind(strlower(c), strlower(DefendYourself_noattack[2])) or strfind(strlower(c), strlower(DefendYourself_noattack[13])))) then
153 DYVar.use = nil;
154 end
155 end
156 local tex = GetActionTexture(arg1);
157 if tex == "Interface\\Icons\\INV_Spear_07" or tex == "Interface\\Icons\\Ability_Gouge" or tex == "Interface\\Icons\\Ability_Sap" or tex == "Interface\\Icons\\Spell_Shadow_MindSteal" then
158 DYVar.use = nil;
159 end
160 if not DYVar.use then
161 DYVar.attack = nil;
162 DYVar.once = nil;
163 DYVar.usetimer = 3
164 end
165 pre_UseAction(arg1,arg2,arg3);
166 end
167  
168 function DefendYourself_OnUpdate(elapsed)
169 if not DYKey or not DYKey.On then DYStuff:Hide(); DefendYourselfFrame:EnableMouse(0); DefendYourselfFrame:SetBackdropColor(0,0,0,0); DefendYourselfFrame:SetBackdropBorderColor(0,0,0,0); return end
170 if DYKey.On then
171 if DYturn_Update then DYturn_Update(elapsed); end
172 if DefendYourself_Panic and DefendYourself_Panic(elapsed) then return; end
173 if DYVar.usetimer > 1 then DYVar.usetimer = DYVar.usetimer - elapsed; return; elseif DYVar.usetimer > 0 and not DYVar.use then DYVar.use = true; DYVar.usetimer = 0 return; end
174 DY_MoneyToggle();
175 DefendYourself_buff();
176 if DYKey.Debuff then DefendYourself_debuff(); else DYVar.debuff = true; end
177 DefendYourself_DK();
178 DY_MoneyToggle();
179 DefendYourself_Check();
180 if DYKey.Safe then DefendYourself_GetBloody(); end
181 DefendYourself_Trip();
182 DefendYourself_Attack();
183 DefendYourself_Stuff();
184 end
185 end
186  
187 function DefendYourself_Check()
188 if UnitExists("target") then DYVar.target = true; else DYVar.target = nil; end
189 if UnitIsDead("target") then DYVar.dead = nil; else DYVar.dead = true; end
190 if UnitCanAttack("player", "target") then DYVar.friend = true; else DYVar.friend = nil; end
191 if DYKey.Yellow then DefendYourself_Yellow(); else DYVar.yellow = true; end
192 if DYKey.Faction then DefendYourself_Faction(); else DYVar.faction = true; end
193 end
194  
195 function DefendYourself_Yellow()
196 if UnitIsEnemy("target", "player") then
197 DYVar.yellow = true;
198 elseif not UnitIsFriend("target", "player") and UnitExists("target") then
199 DYVar.yellow = nil;
200 else
201 DYVar.yellow = true;
202 end
203 end
204  
205 function DefendYourself_Stuff()
206 if DYKey.Debug then
207 DYStuff:Show();
208 DefendYourselfFrame:EnableMouse(1);
209 DefendYourselfFrame:SetBackdropColor(0,0,0,0.5);
210 DefendYourselfFrame:SetBackdropBorderColor(1,1,1,1);
211 DYStuff:SetText("Attacking:"..dycol(DYVar.attack).."\nNeed to attack:"..dycol(DYVar.once).."\nIn Combat:"..dycol(DYVar.combat).."\nOn Hate List:"..dycol(DYVar.hate)
212 .."\nNot Shooting:"..dycol(DYVar.shot).."\nNot Crazy:"..dycol(DYVar.crazy).."\nNot Casting:"..dycol(DYVar.cast).."\nHave a Target?:"..dycol(DYVar.target)
213 .."\nIt's not Dead?:"..dycol(DYVar.dead).."\nNot a Friend?:"..dycol(DYVar.friend).."\nNot Unhostile/Yellow?:"..dycol(DYVar.yellow).."\nOn a Mount?:"..dycol(DYVar.mount)
214 .."\nNo special Buffs?:"..dycol(DYVar.buff).."\nNo Debuffs on it?:"..dycol(DYVar.debuff).."\nNot using a certain skill?:"..dycol(DYVar.use));
215 else
216 DYStuff:Hide();
217 DefendYourselfFrame:EnableMouse(0);
218 DefendYourselfFrame:SetBackdropColor(0,0,0,0);
219 DefendYourselfFrame:SetBackdropBorderColor(0,0,0,0);
220 end
221 end
222  
223 function DefendYourself_Faction()
224 if UnitIsPlayer("target") and UnitFactionGroup("target") ~= UnitFactionGroup("player") then
225 if UnitIsPVP("player") and UnitIsPVP("target") then
226 DYVar.faction = true;
227 else
228 DYVar.faction = nil;
229 end
230 else
231 DYVar.faction = true;
232 end
233 end
234  
235 function DefendYourself_Trip()
236 if DYVar.hate and DYVar.target then
237 if DYVar.shot and DYVar.crazy and DYVar.dead and DYVar.friend and DYVar.yellow and DYVar.buff and DYVar.debuff and DYVar.dk and not DYVar.mount and DYVar.invul and DYVar.use then
238 DYVar.attack = true;
239 else
240 DYVar.attack = nil;
241 end
242 else
243 DYVar.attack = nil;
244 end
245 end
246  
247 --Handles all the lovely person-related saves. Yeah, saved by player name and server. T.T thx rowne!
248 function DefendYourself_UnitSave(x)
249 if (DYVar.init) then
250 local info = UnitName("player").." of "..GetCVar("realmName");
251 --[[ if (x == 1) then
252 info = Fetch_PlayerInfo;
253 end]]
254 local _, tempclassname = UnitClass("player");
255 DYVar.class = strlower(tempclassname);
256 if not DefendYourselfKey or not DefendYourselfKey.Version then
257 DefendYourselfKey = {};
258 DefendYourselfKey.Version = DEFEND_CONFIG_VERSION;
259 elseif DefendYourselfKey.Version ~= DEFEND_CONFIG_VERSION then
260 DefendYourselfKey.Version = DEFEND_CONFIG_VERSION;
261 end
262 if DefendYourselfKey.default then
263 info = "Default Class";
264 end
265 if (not DefendYourselfKey[info]) then
266 DefendYourselfKey[info] = {
267 ["On"] = true,
268 ["ReOn"] = nil,
269 ["Yellow"] = true,
270 ["Faction"] = true,
271 ["Debuff"] = true,
272 ["HP"] = nil,
273 ["Safe"] = nil,
274 ["Assist"] = true,
275 ["Civilian"] = true,
276 ["Debug"] = nil,
277 ["PanicTimer"] = 30,
278 ["PanicTime"] = 0,
279 ["Bar"] = 1,
280 ["blvl"] = 1
281 };
282 end
283 DYKey = DefendYourselfKey[info];
284 -- DefendYourself_Fetch_Frame:Hide();
285 -- DefendYourself_Print("Defend Yourself! v."..DEFEND_CONFIG_VERSION.." is Loaded and "..dycol(DYKey.On));
286 end
287 end
288  
289 function DefendYourself_Print(msg,r,g,b,frame,id)
290 if ( Print ) then
291 Print(msg, r, g, b, frame, id);
292 return;
293 end
294  
295 if (not r) then r = 1.0; end
296 if (not g) then g = 1.0; end
297 if (not b) then b = 0.0; end
298 if ( frame ) then
299 frame:AddMessage(msg,r,g,b,id);
300 else
301 if ( DEFAULT_CHAT_FRAME ) then
302 DEFAULT_CHAT_FRAME:AddMessage(msg, r, g, b,id);
303 end
304 end
305 end
306  
307 function DefendYourself_Toggle(tog, str)
308 if tog then
309 DefendYourself_Print(str.." |CFFFF0000Off|r");
310 return nil;
311 else
312 DefendYourself_Print(str.." |CFF00FF00On|r");
313 return true;
314 end
315 end
316  
317 function DefendYourself_Main_ChatCommandHandler(msg)
318 local msg = TextParse(msg);
319 msg[1] = strlower(msg[1])
320 if strfind(msg[1], "toggle") then
321 DYKey.On = DefendYourself_Toggle(DYKey.On, "DefendYourself! is");
322 elseif strfind(msg[1], "defaultprofile") then
323 DefendYourselfKey.default = DefendYourself_Toggle(DefendYourselfKey.default, "Using an overall profile is");
324 elseif strfind(msg[1], "yellow") then
325 DYKey.Yellow = DefendYourself_Toggle(DYKey.Yellow, "Ignoring Yellow Creatures is");
326 elseif strfind(msg[1], "faction") then
327 DYKey.Faction = DefendYourself_Toggle(DYKey.Faction, "Ignoring Faction Members is");
328 elseif strfind(msg[1], "debuff") then
329 DYKey.Debuff = DefendYourself_Toggle(DYKey.Debuff, "Ignoring debuffed creatures is");
330 elseif strfind(msg[1], "tlhp") then
331 DefendYourself_tlhp();
332 DefendYourself_Print("Aquiring target with lowest hp...",1,1,1);
333 elseif strfind(msg[1], "blood") then
334 DYKey.Safe = DefendYourself_Toggle(DYKey.Safe, "Bloodlust is");
335 DYVar.hate = nil;
336 elseif strfind(msg[1], "blvl") then
337 local x = tonumber(msg[2])
338 if x and x >= 0 and x <= 3 then DYKey.blvl = x; else DefendYourself_Print("What level is that?"); end
339 if x == 0 then
340 DefendYourself_Print("|CFFFFFFFFCurrent level is 0. As good as having the toggle off. Snore!|r");
341 elseif x == 1 then
342 DefendYourself_Print("|CFFFFFF00Current level is 1. Standard. You'll autoattack stuff you target, only if it meets the right criteria. Kinda bloody.|r");
343 elseif x == 2 then
344 DefendYourself_Print("|CFFFF8800Current level is 2. Yeep. You'll find and attack anything that comes across your path, but only if it meets your high standards. Only dining on virgin blood tonight, sir?|r");
345 elseif x == 3 then
346 DefendYourself_Print("|CFFFF0000OH CRAP CURRENT LEVEL IS 3!! RIP AND TEAR AND RIP AND TEAR YOUR GUTS! YOU ARE HUGE! THAT MEANS YOU HAVE HUGE GUTS! HERE IT COMES! BLOODY RAGE!!|r (Sanity: You'll target anything in your range if you have no target, and you'll beat on it indiscriminantly!! careful of faction and DK's!)",1,1,1);
347 end
348 elseif strfind(msg[1], "assist") then
349 DYKey.Assist = DefendYourself_Toggle(DYKey.Assist, "Smart Assist is");
350 elseif strfind(msg[1], "debug") then
351 DYKey.Debug = DefendYourself_Toggle(DYKey.Debug, "Debug options are");
352 elseif strfind(msg[1], "dk") then
353 DYKey.Civilian = DefendYourself_Toggle(DYKey.Civilian, "Dishonorable Kill Prevention is");
354 elseif strfind(msg[1], "help") then
355 DefendYourself_Help();
356 elseif strfind(msg[1], "menu") and DYmenu then
357 DYmenu:Show();
358 elseif strfind(msg[1], "button") then
359 if DefendYourselfPanicButtonClick then
360 if msg[2] == "off" then DYKey.PanicState = 5 else DefendYourselfPanicButtonClick(); end
361 end
362 elseif strfind(msg[1], "bar") then
363 if DefendYourselfBar then
364 if msg[2] == "off" then DYKey.Bar = nil; elseif not DYKey.Bar then DYKey.Bar = 1; elseif DYKey.Bar == 1 then DYKey.Bar = 2; elseif DYKey.Bar == 2 then DYKey.Bar = nil; end
365 end
366 elseif strfind(msg[1], "defaultpanic") then
367 DYKey.PanicTimer = tonumber(msg[2]);
368 elseif strfind(msg[1], "panic") then
369 if DefendYourself_StartPanic then DefendYourself_StartPanic(tonumber(msg[2])); end
370 elseif strfind(msg[1], "turn") then
371 if DefendYourself_Turn then DYKey.Turn = DefendYourself_Toggle(DYKey.Turn, "Turn functionability is"); end
372 elseif strfind(msg[1], "on") then
373 DefendYourself_Print("DefendYourself! is on"); DYKey.On = true; DYKey.ReOn = nil;
374 elseif strfind(msg[1], "off") then
375 local output = "DefendYourself! is off"
376 if msg[2] and strfind(msg[2], "s") then
377 output = output.." and will be restarted on your next reload";
378 DYKey.ReOn = true;
379 end
380 DefendYourself_Print(output);
381 DYKey.On = nil;
382 else
383 if DYmenu then DYmenu:Show(); else
384 DefendYourself_Print(DEFEND_CHAT_COMMAND_USAGE,1,1,0);
385 DefendYourself_Help();
386 end
387 end
388 msg = nil;
389 end
390  
391 function DefendYourself_Help()
392 DefendYourself_Print("Defend Yourself! v."..DEFEND_CONFIG_VERSION.." Parameters and their states");
393 DefendYourself_Print("Toggle is:"..dycol(DYKey.On));
394 DefendYourself_Print("Yellow is:"..dycol(DYKey.Yellow));
395 DefendYourself_Print("Faction is:"..dycol(DYKey.Faction));
396 DefendYourself_Print("Debuff is:"..dycol(DYKey.Debuff));
397 DefendYourself_Print("Bloodlust is:"..dycol(DYKey.Safe));
398 DefendYourself_Print("DK Prevention is:"..dycol(DYKey.Civilian));
399 DefendYourself_Print("Assist is:"..dycol(DYKey.Assist));
400 DefendYourself_Print("Using Default profiles is:"..dycol(DefendYourselfKey.default));
401 DefendYourself_Print("Use /dy help to see this, /dy on turns it on, /dy off turns it off, and /dy toggle turns it between the two. /dy menu handles the menu! /dy defaultprofile toggles using an overall profile or a per-character-per-server profile.");
402 end
403  
404 function dycol(tog)
405 if tog then
406 return "|CFF00FF00Yes|r";
407 else
408 return "|CFFFF0000No|r";
409 end
410 end
411  
412 function TextParse(InputString)
413 --[[ By FERNANDO!
414 This function should take a string and return a table with each word from the string in
415 each entry. IE, "Linoleum is teh awesome" returns {"Linoleum", "is", "teh", "awesome"}
416 Some good should come of this, I've been avoiding writing a text parser for a while, and
417 I need one I understand completely. ^_^
418  
419 If you want to gank this function and use it for whatever, feel free. Just give me props
420 somewhere. This function, as far as I can tell, is fairly foolproof. It's hard to get it
421 to screw up. It's also completely self-contained. Just cut and paste.]]
422 local Text = InputString;
423 local TextLength = 1;
424 local OutputTable = {};
425 local OTIndex = 1;
426 local StartAt = 1;
427 local StopAt = 1;
428 local TextStart = 1;
429 local TextStop = 1;
430 local TextRemaining = 1;
431 local NextSpace = 1;
432 local Chunk = "";
433 local Iterations = 1;
434 local EarlyError = false;
435  
436 if ((Text ~= nil) and (Text ~= "")) then
437 -- ... Yeah. I'm not even going to begin without checking to make sure Im not getting
438 -- invalid data. The big ol crashes I got with my color functions taught me that. ^_^
439  
440 -- First, it's time to strip out any extra spaces, ie any more than ONE space at a time.
441 while (string.find(Text, " ") ~= nil) do
442 Text = string.gsub(Text, " ", " ");
443 end
444  
445 -- Now, what if text consisted of only spaces, for some ungodly reason? Well...
446 if (string.len(Text) <= 1) then
447 EarlyError = true;
448 end
449  
450 -- Now, if there is a leading or trailing space, we nix them.
451 if EarlyError ~= true then
452 TextStart = 1;
453 TextStop = string.len(Text);
454  
455 if (string.sub(Text, TextStart, TextStart) == " ") then
456 TextStart = TextStart+1;
457 end
458  
459 if (string.sub(Text, TextStop, TextStop) == " ") then
460 TextStop = TextStop-1;
461 end
462  
463 Text = string.sub(Text, TextStart, TextStop);
464 end
465  
466 -- Finally, on to breaking up the goddamn string.
467  
468 OTIndex = 1;
469 TextRemaining = string.len(Text);
470  
471 while (StartAt <= TextRemaining) and (EarlyError ~= true) do
472  
473 -- NextSpace is the index of the next space in the string...
474 NextSpace = string.find(Text, " ",StartAt);
475 -- if there isn't another space, then StopAt is the length of the rest of the
476 -- string, otherwise it's just before the next space...
477 if (NextSpace ~= nil) then
478 StopAt = (NextSpace - 1);
479 else
480 StopAt = string.len(Text);
481 LetsEnd = true;
482 end
483  
484 Chunk = string.sub(Text, StartAt, StopAt);
485 OutputTable[OTIndex] = Chunk;
486 OTIndex = OTIndex + 1;
487  
488 StartAt = StopAt + 2;
489  
490 end
491 else
492 OutputTable[1] = "Error: Bad value passed to TextParse!";
493 end
494  
495 if (EarlyError ~= true) then
496 return OutputTable;
497 else
498 return {"Error: Bad value passed to TextParse!"};
499 end
500 end
501  
502  
503 local lOriginal_GameTooltip_ClearMoney;
504 function DY_MoneyToggle()
505 if( lOriginal_GameTooltip_ClearMoney ) then
506 GameTooltip_ClearMoney = lOriginal_GameTooltip_ClearMoney;
507 lOriginal_GameTooltip_ClearMoney = nil;
508 else
509 lOriginal_GameTooltip_ClearMoney = GameTooltip_ClearMoney;
510 GameTooltip_ClearMoney = DY_GameTooltip_ClearMoney;
511 end
512 end
513  
514 function DY_GameTooltip_ClearMoney()
515 end
516  
517 --[[This is similar to the above, but it checks your current buffs.
518 (List:DefendYourself_selfbuff)
519 returns true if it finds a buff that will get removed if you attack something(like stealth)
520 For reference, this one is run all the time, the previous one only runs if you have
521 debuff support toggled on.]]
522 function DefendYourself_buff()
523 local pow = 0;
524 DYVar.mount = nil;
525 DefendYourselfTip:ClearLines();
526 for i = 1, getn(DefendYourself_selfbuff), 1 do
527 if pow == 1 then break; end
528 local j = 1;
529 while UnitBuff("player", j) do
530 DefendYourselfTip:SetUnitBuff("player", j);
531 local msg = DefendYourselfTipTextLeft1:GetText();
532 local texture = UnitBuff("player", j);
533 if (string.find(texture,"Spell_Nature_Swiftness") or -- Summon Felsteed, Summon Warhorse
534 string.find(texture,"Ability_Mount") or string.find(texture,"INV_Misc_Foot_Kodo")) then
535 DYVar.mount = true;
536 end
537 if (msg == DefendYourself_selfbuff[i]) then
538 pow = 1;
539 break;
540 end
541 j = j + 1;
542 end
543 end
544 if pow == 0 then
545 if (not DYVar.buff) then
546 DYVar.buff = true;
547 DYVar.once = true;
548 end
549 elseif pow == 1 then
550 if DYVar.buff then
551 DYVar.buff = nil;
552 DYVar.once = nil;
553 end
554 end
555 end
556  
557 function DefendYourself_debuff()
558 local pow = 0;
559 DefendYourselfTip:ClearLines();
560 for i = 1, getn(DefendYourself_noattack), 1 do
561 if pow == 1 then break; end
562 local j = 1;
563 while UnitDebuff("target", j) do
564 DefendYourselfTip:SetUnitDebuff("target", j);
565 local msg = DefendYourselfTipTextLeft1:GetText();
566 if (msg == DefendYourself_noattack[i]) then
567 pow = 1;
568 break;
569 end
570 j = j + 1;
571 end
572 end
573 if pow == 0 then
574 if (not DYVar.debuff) then
575 DYVar.debuff = true;
576 DYVar.once = true;
577 DYVar.use = true;
578 end
579 elseif pow == 1 then
580 if DYVar.debuff then
581 DYVar.debuff = nil;
582 DYVar.once = nil;
583 end
584 end
585 end
586  
587 function DefendYourself_DK()
588 DefendYourselfTip:ClearLines();
589 DefendYourselfTip:SetUnit("target");
590 DYVar.dk = true;
591 for i = 1, 6 do
592 local msg = tostring(getglobal("DefendYourselfTipTextLeft"..i):GetText());
593 if strfind(msg, "Civilian") then
594 DYVar.dk = nil;
595 break;
596 end
597 end
598 end
599  
600 local escapetlhp = nil;
601 function DefendYourself_tlhp()
602 if escapetlhp and escapetlhp > GetTime() then return; end
603 escapetlhp = GetTime()+5;
604 local maxHP, curHP, retry;
605 maxHP = 101;
606 retry = 0;
607 if UnitExists("target") then maxHP = UnitHealth("target"); end
608 TargetNearestEnemy();
609 curHP = UnitHealth("target");
610 while (curHP ~= maxHP and UnitExists("target") and retry <= 10) do
611 if (curHP < maxHP) then
612 maxHP = curHP;
613 retry = 0;
614 else
615 retry = retry + 1;
616 end
617 TargetNearestEnemy();
618 if UnitExists("target") then curHP = UnitHealth("target"); end
619 end
620 DY_MoneyToggle();
621 DefendYourself_debuff();
622 DY_MoneyToggle();
623 DefendYourself_Check();
624 DefendYourself_Trip();
625 if not DYVar.attack or (UnitIsTapped("target") and not UnitIsTappedByPlayer("target")) then ClearTarget(); end
626 escapetlhp = nil;
627 end
628  
629 function DefendYourself_Attack()
630 if DYKey.On then
631 if DYVar.attack then
632 DYBattle();
633 else
634 DYEscape();
635 end
636 end
637 end
638  
639 function DYBattle()
640 if DYVar.once then
641 if DYVar.combat then
642 DYVar.once = nil;
643 else
644 AttackTarget();
645 DYVar.once = nil;
646 end
647 end
648 end
649  
650 function DYEscape()
651 if not DYVar.crazy and not UnitOnTaxi("player") then return; end
652 if DYVar.combat and (not DYVar.buff or not DYVar.debuff) then AttackTarget(); DYVar.once = nil; return; end
653 end
654  
655 function DefendYourself_GetBloody()
656 --I apologize in advance. I couldn't help myself. lol!
657 --(rage3 level indicator stolen from the doom comic. HERE COMES THE NIGHT TRAIN!)
658 if not DYKey.blvl then DYKey.blvl = 1; end
659 if DYKey.blvl == 0 then
660 return;
661 elseif DYKey.blvl == 1 then
662 DYVar.hate = true;
663 elseif DYKey.blvl == 2 then
664 DYVar.hate = true;
665 if not UnitExists("target") then TargetNearestEnemy(); end
666 elseif DYKey.blvl == 3 then
667 DYVar.hate = true;
668 DYVar.yellow = true;
669 DYVar.debuff = true;
670 DYVar.faction = true;
671 if not UnitExists("target") then TargetNearestEnemy(); end
672 end
673 end