Here's an addon I wrote for something else, but I've adapted it to output the name of an npc from an ID..
Code:
local QUEST_TIMEOUT = 0.3
local function ScrapeQTip(self)
local tipName = self:GetName()
local name, description = _G[tipName .. 'TextLeft1']:GetText(), _G[tipName ..'TextLeft2']:GetText()
if name then
print(format('|cffffff00|Hunit:Creature-0-0-0-0-%d-0|h[%s]|h|r (%d) %s', self.npcID, name, self.npcID, description or ''))
end
self:SetScript('OnTooltipSetUnit', nil)
self.npcID = nil
end
local QTips = {}
local function GetQTip()
local now = GetTime()
for i, tip in ipairs(QTips) do
if not tip.npcID or now - tip.lastUpdate > QUEST_TIMEOUT + 0.2 then
tip.lastUpdate = now
return tip
end
end
local tip = CreateFrame('GameTooltip', 'SemlarsQTip' .. (#QTips + 1), WorldFrame, 'GameTooltipTemplate')
tip:Show()
tip:SetHyperlink('unit:')
tip.lastUpdate = now
tinsert(QTips, tip)
return tip
end
function GetNPCInfo(npcID)
local tip = GetQTip()
tip:SetOwner(WorldFrame, 'ANCHOR_NONE')
tip.npcID = npcID or 0
tip:SetScript('OnTooltipSetUnit', ScrapeQTip)
tip:SetHyperlink('unit:Creature-0-0-0-0-' .. npcID .. '-0')
C_Timer.After(QUEST_TIMEOUT, function() -- Run a second pass for uncached units or the event will never fire
if tip.npcID == npcID then
tip:SetHyperlink('unit:Creature-0-0-0-0-' .. npcID .. '-0')
end
end)
end
Usage is "/run GetNPCInfo(npcID)", and you'll have to wait for a response from the server if the unit isn't cached.
It's capable of scanning multiple IDs at once.
Paste it into http://addon.bool.no if you need help turning it into an addon, change the interface number to 60000 in the toc options.