--------------------------------------------------------------THESE COLORS SET THE TOP MIDDLE AND BOTTOM ROW COLORS
local KBTWhiteColor = "|cFFFFFFFF";
local KBTBlueColor = "|cFF0070fF";
local KBTTopColor = "|cFFFFFF00";
local KBTMiddleColor = "|cFFFF0000";
local KBTBottomColor = "|cFF00FF00";
local PlayerName = UnitName("Player");
local KBT_WasInBG = false;
local KBT_IsInBG = false;
local KBT_LastBG = "";
function KBT_TestFn()
KBT_Current_KillingBlows = 10;
KBT_Current_HonorKills = 10;
KBT_Display_HK:SetText( KBTWhiteColor .. "(KB)\n" ..
KBTTopColor .. KBT_Current_KillingBlows .. "\n" ..
KBTMiddleColor .. KBT_Last_KillingBlows .."\n" ..
KBTBottomColor .. KBT_Total_KillingBlows + KBT_Current_KillingBlows)
KBT_Display_KB:SetText( KBTWhiteColor .. "(HK)\n" ..
KBTTopColor .. KBT_Current_HonorKills .. "\n" ..
KBTMiddleColor .. KBT_Last_HonorKills .."\n" ..
KBTBottomColor .. KBT_Total_HonorKills + KBT_Current_HonorKills)
end
local KBT_ListOfBattlegrounds = {
"Isle of Conquest",
"Alterac Valley",
"Arathi Basin",
"Eye of the Storm",
"Warsong Gulch",
"Strand of the Ancients",
"Twin Peaks",
"Battle for Gilneas"
}
KBT_Current_KillingBlows = 0;
KBT_Last_KillingBlows = 0;
KBT_Total_KillingBlows = 0;
KBT_Current_HonorKills = 0;
KBT_Last_HonorKills = 0;
KBT_Total_HonorKills = 0;
KBTracker_OnLoadFunction = CreateFrame("FRAME");
KBTracker_OnLoadFunction:SetScript("OnEvent", function() KBTracker_OnLoad(); end)
KBTracker_OnLoadFunction:RegisterEvent("VARIABLES_LOADED");
function KBTracker_OnLoad()
if KBTrackerDBPC == nil then KBTrackerDBPC = {} end
if KBTrackerDBPC["x"] == nil then KBTrackerDBPC["x"] = 0 end
if KBTrackerDBPC["y"] == nil then KBTrackerDBPC["y"] = 0 end
if KBTrackerDBPC["point"] == nil then KBTrackerDBPC["point"] = "Center" end
-- create the frame to hold the data
KBTracker_CreateMainFrame()
-- create a frame that updates every 5 seconds to update the data
KBTracker_CreateUpdateFrame()
-- setup slash commands
SLASH_KBT1 = "/kbt";
SLASH_KBT2 = "/hkt";
SLASH_KBT3 = "/kbtracker";
SlashCmdList["KBT"] = KBTracker_Command;
end
function KBTracker_CreateUpdateFrame()
KBT_UpdateTime = time()+10;
KBT_Update_Frame=CreateFrame("FRAME");
KBT_Update_Frame:SetScript("OnUpdate", function()
if time() >= KBT_UpdateTime then
KBT_UpdateTime = time()+10;
RequestBattlefieldScoreData()
KBTracker_ZoneChecker()
--print(time());
end;
end);
KBTracker_UpdateDataFrame = CreateFrame("FRAME");
KBTracker_UpdateDataFrame:SetScript("OnEvent", function() KBTracker_UpdateData(); end)
KBTracker_UpdateDataFrame:RegisterEvent("UPDATE_BATTLEFIELD_SCORE");
end
function KBTracker_ZoneChecker()
local Zone = GetRealZoneText();
local KBT_BGFound = false;
local KBT_NewBG = false;
--print(Zone)
for i=1,#KBT_ListOfBattlegrounds do
if Zone == KBT_ListOfBattlegrounds[i] then
--print(KBT_ListOfBattlegrounds[i]);
KBT_BGFound = true;
end
end
if KBT_WasInBG == true and KBT_BGFound == true and KBT_LastBG ~= Zone then
KBT_NewBG = true;
end
if KBT_WasInBG == false and KBT_BGFound == true then
KBT_NewBG = true;
end
if KBT_NewBG == true then
--print("|cff0070ffNew BG found")
KBT_Total_KillingBlows = KBT_Total_KillingBlows + KBT_Current_KillingBlows;
KBT_Total_HonorKills = KBT_Total_HonorKills + KBT_Current_HonorKills;
KBT_Last_KillingBlows = KBT_Current_KillingBlows;
KBT_Last_HonorKills = KBT_Current_HonorKills;
KBT_Current_KillingBlows = 0;
KBT_Current_HonorKills = 0;
KBT_LastBG = Zone;
end
KBT_WasInBG = KBT_BGFound;
end
function KBTracker_UpdateData()
local Max = GetNumBattlefieldScores();
if Max > 0 then
for i=1,Max do
local name, killingBlows, honorKills, _ = GetBattlefieldScore(i);
if name == PlayerName then
--print(name)
--print(killingBlows)
--print(honorKills)
--print(GetBattlefieldScore(i));
if killingBlows > KBT_Current_KillingBlows then
KBT_Current_KillingBlows = killingBlows;
end
if honorKills > KBT_Current_HonorKills then
KBT_Current_HonorKills = honorKills;
end
KBT_Display_HK:SetText( KBTWhiteColor .. "(KB)\n" ..
KBTTopColor .. KBT_Current_KillingBlows .. "\n" ..
KBTMiddleColor .. KBT_Last_KillingBlows .."\n" ..
KBTBottomColor .. KBT_Total_KillingBlows + KBT_Current_KillingBlows)
KBT_Display_KB:SetText( KBTWhiteColor .. "(HK)\n" ..
KBTTopColor .. KBT_Current_HonorKills .. "\n" ..
KBTMiddleColor .. KBT_Last_HonorKills .."\n" ..
KBTBottomColor .. KBT_Total_HonorKills + KBT_Current_HonorKills)
end
end
end
end
function KBTracker_CreateMainFrame()
local f = CreateFrame("Frame", nil, UIParent, BackdropTemplateMixin and "BackdropTemplate")
tile = false, -- true to repeat the background texture to fill the frame, false to scale it
-- size (width or height) of the square repeating background tiles (in pixels)
-- thickness of edge segments and square size of edge corners (in pixels)
-- distance from the edges of the frame to those of the background texture (in pixels)
-- create the frame
KBT_Display_Frame:SetWidth(135);
KBT_Display_Frame:SetHeight(65);
KBT_Display_Frame:SetPoint(KBTrackerDBPC["point"],KBTrackerDBPC["x"],KBTrackerDBPC["y"]);
KBT_Display_Frame:SetBackdrop(backdrop);
--KBT_Display_Frame:Hide()
-- This allows the frame to be moved
KBT_Display_Frame:SetMovable(true)
KBT_Display_Frame:EnableMouse(true)
KBT_Display_Frame:SetScript("OnMouseDown",function()
KBT_Display_Frame:StartMoving()
end)
KBT_Display_Frame:SetScript("OnMouseUp",function()
KBT_Display_Frame:StopMovingOrSizing()
local point, relativeTo, relativePoint, xOfs, yOfs = KBT_Display_Frame:GetPoint()
KBTrackerDBPC["point"] = point;
KBTrackerDBPC["x"] = xOfs;
KBTrackerDBPC["y"] = yOfs;
end)
-- create the font strings
KBT_Display_Types = KBT_Display_Frame:CreateFontString("KBT_Display_Types" ,"ARTWORK","GameFontNormal");
KBT_Display_Types:SetPoint("TopLeft", KBT_Display_Frame, "TopLeft", 5, -8)
KBT_Display_Types:SetText( KBTBlueColor .. "KBT \n" ..
KBTTopColor .. "This BG:\n" ..
KBTMiddleColor .. "Last BG:\n" ..
KBTBottomColor .. "Session:")
KBT_Display_Types:SetJustifyH("Right")
KBT_Display_HK = KBT_Display_Frame:CreateFontString("KBT_Display_HK" ,"ARTWORK","GameFontNormal");
KBT_Display_HK:SetPoint("TopLeft", KBT_Display_Frame, "TopLeft", 55, -8)
KBT_Display_HK:SetText( KBTWhiteColor .. "(KB)\n" ..
KBTTopColor .. KBT_Current_KillingBlows .. "\n" ..
KBTMiddleColor .. KBT_Last_KillingBlows .."\n" ..
KBTBottomColor .. KBT_Total_KillingBlows)
KBT_Display_HK:SetJustifyH("Center")
KBT_Display_KB = KBT_Display_Frame:CreateFontString("KBT_Display_KB" ,"ARTWORK","GameFontNormal");
KBT_Display_KB:SetPoint("TopLeft", KBT_Display_Frame, "TopLeft", 90, -8)
KBT_Display_KB:SetText( KBTWhiteColor .. "(HK)\n" ..
KBTTopColor .. KBT_Current_HonorKills .. "\n" ..
KBTMiddleColor .. KBT_Last_HonorKills .."\n" ..
KBTBottomColor .. KBT_Total_HonorKills)
KBT_Display_KB:SetJustifyH("Center")
end
function KBTracker_Command(cmd)
if cmd == "center" then
KBT_Display_Frame:ClearAllPoints();
KBT_Display_Frame:SetPoint("Center");
elseif cmd == "show" then
if KBT_Display_Frame:IsShown() then
KBT_Display_Frame:Hide();
else
KBT_Display_Frame:Show();
end
else
print(KBTBlueColor .. "Killing Blow Tracker")
print("Commands:")
print("show - Toggle the tracker frame")
print("center - Reset the position of the window")
end
end
local KBT_DataObj = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject("KB Tracker", {
text = "KBT",
type = "data source",
icon = "Interface\\Icons\\spell_deathknight_subversion",
OnClick = function(clickedframe, button)
if button == "LeftButton" then
if KBT_Display_Frame:IsShown() then
KBT_Display_Frame:Hide();
else
KBT_Display_Frame:Show();
end
elseif button == "RightButton" then
KBT_Display_Frame:ClearAllPoints();
KBT_Display_Frame:SetPoint("Center");
end
end,
})
if KBT_DataObj ~= nil then
function KBT_DataObj:OnTooltipShow()
self:AddLine(KBTBlueColor .. "Killing Blow Tracker\n\n" .. KBTWhiteColor .. "Left Click: Toggle Window\nRight Click: Recenter Window")
end
function KBT_DataObj:OnEnter()
GameTooltip:SetOwner(self, "ANCHOR_NONE")
GameTooltip:SetPoint("TOPLEFT", self, "BOTTOMLEFT")
GameTooltip:ClearLines()
KBT_DataObj.OnTooltipShow(GameTooltip)
GameTooltip:Show()
end
function KBT_DataObj:OnLeave()
GameTooltip:Hide()
end
end