From 9523a49047c165069d994dfd73df01358ec83fa2 Mon Sep 17 00:00:00 2001 From: Adrian L Lange Date: Thu, 19 Dec 2024 03:37:49 +0100 Subject: [PATCH] Add method for getting NPC names by ID --- modules/misc.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/modules/misc.lua b/modules/misc.lua index 73bbb82..4d820b9 100644 --- a/modules/misc.lua +++ b/modules/misc.lua @@ -51,6 +51,28 @@ function addon:GetUnitID(unit) end end +--[[ namespace:GetNPCName(_npcID_) +Returns the name for the NPC by the given `npcID`. + +Warning: this depends on the cache, and might not yield results the first time. +--]] +do + local creatureNames = setmetatable({}, { + __index = function(self, npcID) + local data = C_TooltipInfo.GetHyperlink('unit:Creature-0-0-0-0-' .. npcID .. '-0') + local name = data and data.lines and data.lines[1] and data.lines[1].leftText + if name then + rawset(self, npcID, name) + return name + end + end + }) + + function addon:GetNPCName(npcID) + return creatureNames[npcID] + end +end + do local ITEM_LINK_FORMAT = '|Hitem:%d|h' --[[ namespace:GetItemLinkFromID(_itemID_)