As some People have asked for the Addon I coded to print my hk/h, ill post the Code here now.
How to use:
/hk - see them for yourself
/hk bg - post them in bg chat.
/reload will reset the data
How to install:
Create Folder in the Addons Folder called "HonorableKillsTracker" and two files called "HonorableKillsTracker.lua" and the other "HonorableKillsTracker.toc"
Open files in your preffered texteditor and paste in the code:
HonorableKillsTracker.lua:
Code:
-- Define addon namespace and initialize addon frame
local ADDON_NAME = "HonorableKillsTracker"
local frame = CreateFrame("Frame")
-- Data structure to store honorable kills values with timestamps
local data = {}
local function IsPlayerInBattleground()
local zoneName = GetRealZoneText()
return zoneName == "Arathi Basin" or
zoneName == "Warsong Gulch" or
zoneName == "Eye of the Storm" or
zoneName == "Strand of the Ancients" or
zoneName == "Alterac Valley" or
zoneName == "Wintergrasp"
end
-- Function to update data with current honorable kills value and timestamp
local function UpdateData()
if IsPlayerInBattleground() then
local timestamp = date("%Y-%m-%d %H:%M:%S")
local hk = select(1, GetPVPLifetimeStats())
table.insert(data, {timestamp = timestamp, hk = hk})
else
data = {}
end
end
-- Event handler for updating data at regular intervals
frame:SetScript("OnUpdate", function(_, elapsed)
-- Update data every minute
local interval = 30
frame.timer = (frame.timer or 0) + elapsed
if frame.timer >= interval then
UpdateData()
frame.timer = 0
end
end)
-- Function to convert datetime string to Unix timestamp
local function strtotime(datetime)
local pattern = "(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)"
local year, month, day, hour, min, sec = datetime:match(pattern)
return (year * 31536000) + (month * 2592000) + (day * 86400) + (hour * 3600) + (min * 60) + sec
end
local function FindClosestEntry(entries, targetTimestamp)
local closestEntry = nil
local closestDifference = math.huge
for _, entry in ipairs(entries) do
local entryTimestamp = strtotime(entry.timestamp)
local timeDifference = math.abs(entryTimestamp - targetTimestamp)
if timeDifference < closestDifference then
closestEntry = entry
closestDifference = timeDifference
end
end
return closestEntry
end
local function CalculateHourlyRate(entries, startTimestamp, endTimestamp)
local hkSum = 0
local count = 0
for _, entry in ipairs(entries) do
print(entry)
local entryTimestamp = strtotime(entry.timestamp)
if entryTimestamp >= startTimestamp and entryTimestamp <= endTimestamp then
hkSum = hkSum + entry.hk
count = count + 1
end
end
local timeDifference = (endTimestamp - startTimestamp) / 3600
local hourlyRate = (hkSum / count) * (3600 / timeDifference)
return hourlyRate
end
local function PrintHourlyRate(entries, timeFrame, t, channel)
local currentTime = date("%Y-%m-%d %H:%M:%S") -- Get current timestamp
local endTimestamp = strtotime(date("%Y-%m-%d %H:%M:%S")) -t*3600 -- Current time in seconds since epoch
local startTimestamp = endTimestamp - timeFrame -t*3600 -- Start time for the specified time frame
local entriesInTimeFrame = {}
for _, entry in ipairs(entries) do
local entryTimestamp = strtotime(entry.timestamp) -- Convert entry timestamp to seconds
if entryTimestamp >= startTimestamp and entryTimestamp <= endTimestamp then
table.insert(entriesInTimeFrame, entry)
end
end
if #entriesInTimeFrame > 0 then
local closestEntryStart = FindClosestEntry(entriesInTimeFrame, startTimestamp)
local closestEntryEnd = FindClosestEntry(entriesInTimeFrame, endTimestamp)
local hkStart = closestEntryStart.hk
local hkEnd = closestEntryEnd.hk
local timeDifferenceHours = (strtotime(closestEntryEnd.timestamp) - strtotime(closestEntryStart.timestamp)) / 3600 -- Time difference in hours
local hourlyRate = (hkEnd - hkStart) / timeDifferenceHours
hourlyRate = math.floor(hourlyRate*100)/100
if channel == "BATTLEGROUND" then
local message = ""
if t == 1 then
message = "Hourly Honorable Kill Rate 1 hour ago: " .. hourlyRate
elseif t == 2 then
message = "Hourly Honorable Kill Rate 2 hours ago: " .. hourlyRate
else
message = "Hourly Honorable Kill Rate (Last " .. (timeFrame / 60) .. " Minutes): " .. hourlyRate
end
SendChatMessage(message, channel, nil, nil)
else
if t == 1 then
print("Hourly Honorable Kill Rate 1 hour ago: " .. hourlyRate)
elseif t==2 then
print("Hourly Honorable Kill Rate 2 hours ago: " .. hourlyRate)
else
print("Hourly Honorable Kill Rate (Last " .. (timeFrame / 60) .. " Minutes): " .. hourlyRate)
end
end
else
if channel == "BATTLEGROUND" then
local message = ""
if t == 1 then
message = "No data available for 1 hour ago."
elseif t == 2 then
message = "No data available for 2 hours ago."
else
message = "No data available for the last " .. (timeFrame / 60) .. " minutes."
end
SendChatMessage(message, channel, nil, nil)
else
if t == 1 then
print("No data available for 1 hour ago.")
elseif t==2 then
print("No data available for 2 hours ago.")
else
print("No data available for the last " .. (timeFrame / 60) .. " minutes.")
end
end
end
end
local function PrintData(channel)
if IsPlayerInBattleground() then
PrintHourlyRate(data, 600, 0, channel) -- Last 10 minutes
PrintHourlyRate(data, 1800, 0, channel) -- Last 30 minutes
PrintHourlyRate(data, 3600, 0, channel) -- Last 60 minutes
PrintHourlyRate(data, 3600, 1, channel) -- 60 to 120 minutes ago
PrintHourlyRate(data, 3600, 2, channel) -- 120 to 180 minutes ago
else
print("You are currently not in a battleground.nThe Data will be recorded once you join a battleground.")
end
end
-- Slash command handler to print the data
SLASH_HONORABLEKILLSTRACKER1 = "/hk"
SlashCmdList["HONORABLEKILLSTRACKER"] = function(arg)
if arg == "bg" then
PrintData("BATTLEGROUND") -- Print data in battleground chat
else
PrintData(0) -- Print data in default chat
end
end
HonorableKillsTracker.toc
Code:
## Title: HonorableKillsTracker
## Version: 1.0
## Author: Faintfury-Onyxia
## Interface: 30300
HonorableKillsTracker.lua