From 7b2aa292041452a545b6317b3f08f77a701c61d4 Mon Sep 17 00:00:00 2001 From: F16Gaming Date: Tue, 1 Nov 2011 19:45:44 +0100 Subject: [PATCH] Fixes and additions. FIXED: KillTrack.PrintKills now prints NPC name instead of ID if player has a target. ADDED: Sort method to sort mob database by kills (descending or ascending). --- KillTrack.lua | 3 +++ Tools.lua | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/KillTrack.lua b/KillTrack.lua index 5b564bc..9949cd6 100644 --- a/KillTrack.lua +++ b/KillTrack.lua @@ -125,6 +125,9 @@ function KT:PrintKills(identifier) if found then self:Msg(("You have killed %q %d times in total, %d times on this character"):format(name, gKills, cKills)) else + if UnitExists("target") and not UnitIsPlayer("target") then + identifier = UnitName("target") + end self:Msg(("Unable to find %q in mob database."):format(tostring(identifier))) end end diff --git a/Tools.lua b/Tools.lua index d5deaf7..f82bfcb 100644 --- a/Tools.lua +++ b/Tools.lua @@ -19,7 +19,7 @@ KillTrack_Tools = {} -local KTT = KillTrack_StringTools +local KTT = KillTrack_Tools ------------------ -- STRING TOOLS -- @@ -48,6 +48,43 @@ function KTT:InTable(tbl, val) return false end +function KTT:TableCopy(tbl, cache) + if type(tbl) ~= "table" then return tbl end + cache = cache or {} + if cache[tbl] then return cache[tbl] end + local copy = {} + cache[tbl] = copy + for k, v in pairs(tbl) do + copy[self:TableCopy(k, cache)] = self:TableCopy(v, cache) + end + return copy +end + +KTT.SortMode = { + Descending = 0, + Ascending = 1 +} + +function KTT:GetSortedMobTable(tbl, mode) + local t = {} + for k,v in pairs(tbl) do + local entry = {Id = k, Name = v.Name, Kills = v.Kills} + table.insert(t, entry) + end + if not mode or (mode < 0 or mode > 1) then + mode = self.SortMode.Descending + end + local function compare(a, b) + if mode == self.SortMode.Descending then + return a.Kills > b.Kills + else + return a.Kills < b.Kills + end + end + table.sort(t, compare) + return t +end + ----------------- -- OTHER TOOLS -- ----------------- -- 1.7.9.5