Code:
function COnLoad()
TStop();
hooks = {} --Make a table to store the old functions in.
for i=1, 7 do --For each chat frame.
f = getglobal("ChatFrame"..i) --Get pointer to the ChatFrame.
hooks[f] = f.AddMessage --Add this frame's AddMessage function to the hooks table.
f.AddMessage = AlertScreensFilter --Set frame's AddMessage function to your AddMessage.
end
end --BOnLoad
local frmTick = CreateFrame("FRAME","HZ_Frame", UIParent);
frmTick:SetWidth(200);
frmTick:SetHeight(200);
frmTick:SetPoint("BOTTOMRIGHT",UIParent, "BOTTOMRIGHT",-50,100);
frmTick:SetBackdrop({
bgFile="Interface\DialogFrame\UI-DialogBox-Background",
edgeFile="Interface\\Tooltips\\UI-Tooltip-Border",
tile=1, tileSize=10, edgeSize=10,
insets={left=3, right=3, top=3, bottom=3}
});
frmTick:SetBackdropColor(255,255,255,100);
----------chat frame hook for commands
function AlertScreensFilter(frame, text, red, blue, green, id) --Function that is fired before the default AddMessage.
if string.find(text,"whispers",1) ~= nil then
start = string.find(text,"yer:") + 4 --Finding the player's name who whispered
endloc = string.find(text,":",start+3) - 1 --^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
replyName = strsub(text, start,endloc)
if string.find(text,"follow") ~= nil then
FollowUnit(replyName);
print("Following " .. replyName);
elseif string.find(text,"stop") ~= nil then
MoveForwardStart();
MoveForwardStop();
MoveForwardStop();
print("Stopping...");
end
end
return hooks[f](frame, text, red, blue, green, id) --Let the old AddMessage function handle the rest.
end
-----------End hook---------------------------------
local fsCasting = frmTick:CreateFontString("$parentText","ARTWORK","GameFontNormal");
fsCasting:SetParent(frmTick);
fsCasting:SetPoint("TOPLEFT", frmTick,"TOPLEFT", 10, -5);
local fsHP = frmTick:CreateFontString("$parentText","ARTWORK","GameFontNormal");
fsHP:SetParent(frmTick);
fsHP:SetPoint("TOPLEFT", frmTick,"TOPLEFT", 10, -18);
fsHP:SetText("Mana: " .. UnitMana("player") .. "/" .. UnitManaMax("player"));
local fsTarget = frmTick:CreateFontString("$parentText","ARTWORK","GameFontNormal");
fsTarget:SetParent(frmTick);
fsTarget:SetPoint("TOPLEFT", frmTick,"TOPLEFT", 10, -31);
fsTarget:SetText("Target:");
local tTarget = UnitName("target");
if tTarget ~= nil then
fsTarget:SetText("Target: " .. tTarget);
end
local fsTargetHP = frmTick:CreateFontString("$parentText","ARTWORK","GameFontNormal");
fsTargetHP:SetParent(frmTick);
fsTargetHP:SetPoint("TOPLEFT", frmTick,"TOPLEFT", 10, -44);
fsTargetHP:SetText("Target HP:");
if tTarget ~= nil then
local tTargetHP = UnitHealth("target") .. "/" .. UnitHealthMax("target")
fsTargetHP:SetText("Target HP: " .. tTargetHP);
end
local fsTargetState = frmTick:CreateFontString("$parentText","ARTWORK","GameFontNormal");
fsTargetState:SetParent(frmTick);
fsTargetState:SetPoint("TOPLEFT", frmTick,"TOPLEFT", 10, -58);
fsTargetState:SetText("Target State:");
if tTarget ~= nil then
local TargetState = GetState()
fsTargetState:SetText("Target State: " .. TargetState);
end
local totalElapsed = 0.0;
local TargetState = 0
local NumPartyMembers = 0
local PartyCount = 1
function IsCasting(player)
local IsCasting = ""
spell, rank, displayName, icon, startTime, endTime, isTradeSkill, castID, interrupt = UnitCastingInfo(player)
if spell ~= nil then
IsCasting = "TRUE"
else
IsCasting = "FALSE"
end
return IsCasting
end
function NeedHeal(unit)
local NeedHeals = 0
if UnitHealth(unit) / UnitHealthMax(unit) < .55 then
NeedHeals = 1
else
NeedHeals = 0
end
if UnitHealth(unit) == 0 then
NeedHeals = 2
end
return NeedHeals
end
function GetState()
State = 0
if UnitName("target") ~= nil then
if NeedHeal("target") == 1 then
State = 1
elseif NeedHeal("target") == 0 then
State = 0;
else
State = 2
end
end
return State
end
local function Tick(self, elapsed)
NumPartyMembers = GetNumPartyMembers()
totalElapsed = totalElapsed + elapsed;
if totalElapsed > .5 then
--Update frame information-------------------------------
fsCasting:SetText("Casting: " .. IsCasting("player"));
fsHP:SetText("Mana: " .. UnitMana("player") .. "/" .. UnitManaMax("player"));
tTarget = UnitName("target");
if tTarget ~= nil then
fsTarget:SetText("Target: " .. tTarget);
local tTargetHP = UnitHealth("target") .. "/" .. UnitHealthMax("target")
fsTargetHP:SetText("Target HP: " .. tTargetHP);
end
--End Update---------------------------------------------
if IsCasting("player") == "FALSE" then
if NumPartyMembers > 0 then
if PartyCount <= NumPartyMembers then
if PartyCount == 1 then
RunMacro("p1");
elseif PartyCount == 2 then
RunMacro("p2");
elseif PartyCount == 3 then
RunMacro("p3");
elseif PartyCount == 4 then
RunMacro("p4");
end
PartyCount = PartyCount + 1
elseif PartyCount >= NumPartyMembers then
PartyCount = 1
RunMacro("self");
if UnitAffectingCombat("player") == nil then --not in combat
if UnitMana("player") / UnitManaMax("player") < .40 then
name, rank, icon, count, debuffType, duration, expirationTime, source, isStealable = UnitBuff("player", "Drink");
if name == nil then
RunMacro("EatDrink");
else
end
end
end
end
end
--Get Target state. 0-Healthy, 1-Needs Heal, 2-Dead
TargetState = GetState()
if TargetState == 1 and IsCasting("player") == "FALSE" then
fsTargetState:SetText("Target State: Needs Heal");
CastSpellByName("Healing Wave");
elseif TargetState == 0 then
fsTargetState:SetText("Target State: Healthy");
elseif TargetState == 2 then
fsTargetState:SetText("Target State: Dead");
end
--Target State---------------------------------------------
totalElapsed = 0.0
end
end
end
frmTick:SetScript("OnUpdate", Tick);
function TStart()
totalElapsed = 0.0
frmTick:Show();
end
function TStop()
frmTick:Hide();
end
SLASH_HEALZOR1, SLASH_HEALZOR2 = '/hz', '/healzor';
function SlashCmdList.HEALZOR(msg, editbox)
if msg.len(msg) > 0 then
if msg == "enable" then
TStart();
print("Healzor is now active.");
elseif msg == "disable" then
TStop();
print("Healzor is no longer active.");
end
end
end
Healzor.toc