I use UnitName("npc") to get the name of the trading target for my addon.
Lua Code:
local f = CreateFrame("frame")
function f.TRADE_SHOW()
local name, realm = UnitName("npc")
print(name..(realm and "-"..realm or "").." has opened a trade with me.")
end
f:RegisterEvent("TRADE_SHOW")
f:SetScript("OnEvent", function(self, event, ...) self[event](...) end)
I got this from
http://wowprogramming.com/docs/api_types#unitID before it was deleted.
Edit: It's been quite a while since I found/used that, so I had a look in Blizzard's TradeFrame.lua, they use it to set the other player's name in the window:
Lua Code:
function TradeFrame_Update()
SetPortraitTexture(TradeFramePlayerPortrait, "player");
SetPortraitTexture(TradeFrameRecipientPortrait, "NPC");
TradeFramePlayerNameText:SetText(GetUnitName("player"));
TradeFrameRecipientNameText:SetText(GetUnitName("NPC"));
for i=1, MAX_TRADE_ITEMS, 1 do
TradeFrame_UpdateTargetItem(i);
TradeFrame_UpdatePlayerItem(i);
end
TradeHighlightRecipient:Hide();
TradeHighlightPlayer:Hide();
TradeHighlightPlayerEnchant:Hide();
TradeHighlightRecipientEnchant:Hide();
end
UnitName is defined in the C portion of WoW's code, but GetUnitName is in UnitFrame.lua:
Lua Code:
function GetUnitName(unit, showServerName)
local name, server = UnitName(unit);
local relationship = UnitRealmRelationship(unit);
if ( server and server ~= "" ) then
if ( showServerName ) then
return name.."-"..server;
else
if (relationship == LE_REALM_RELATION_VIRTUAL) then
return name;
else
return name..FOREIGN_SERVER_LABEL;
end
end
else
return name;
end
end