Skip to content

Commit

Permalink
Add method for getting NPC names by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
p3lim committed Dec 19, 2024
1 parent 9494e4f commit 9523a49
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions modules/misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Check warning on line 62 in modules/misc.lua

View workflow job for this annotation

GitHub Actions / lint

accessing undefined variable 'C_TooltipInfo'
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_)
Expand Down

0 comments on commit 9523a49

Please sign in to comment.