Fixed session kills not being sorted.
F16Gaming [09-02-12 - 14:37]
Fixed session kills not being sorted.
diff --git a/Broker.lua b/Broker.lua
index e9cc639..1004070 100644
--- a/Broker.lua
+++ b/Broker.lua
@@ -49,8 +49,8 @@ function obj.OnTooltipShow(tip)
tip:AddLine(" ")
tip:AddLine("Most kills this session:", 1, 1, 0)
local added = 0
- for k,v in pairs(KT.Session.Kills) do
- tip:AddDoubleLine(k, v)
+ for i,v in pairs(KT:GetSortedSessionKills()) do
+ tip:AddDoubleLine(v.Name, v.Kills)
added = added + 1
end
if added <= 0 then
diff --git a/KillTrack.lua b/KillTrack.lua
index 4fe1ce8..ecc19f0 100644
--- a/KillTrack.lua
+++ b/KillTrack.lua
@@ -205,17 +205,25 @@ function KT:AddSessionKill(name)
else
self.Session.Kills[name] = 1
end
- table.sort(self.Session.Kills, function(a, b) return a > b end)
+ self.Session.Count = self.Session.Count + 1
+end
+
+function KT:GetSortedSessionKills(max)
+ max = tonumber(max) or 3
+ local t = {}
+ for k,v in pairs(self.Session.Kills) do
+ t[#t + 1] = {Name = k, Kills = v}
+ end
+ table.sort(t, function(a, b) return a.Kills > b.Kills end)
-- Trim table to only contain 3 entries
local trimmed = {}
- local i = 0
- for k,v in pairs(self.Session.Kills) do
- trimmed[k] = v
- i = i + 1
- if i >= 3 then break end
+ local c = 0
+ for i,v in ipairs(t) do
+ trimmed[i] = v
+ c = c + 1
+ if c >= max then break end
end
- self.Session.Kills = trimmed
- self.Session.Count = self.Session.Count + 1
+ return trimmed
end
function KT:ResetSession()