View Single Post
11-22-18, 11:38 PM   #7
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
I use UnitName("npc") to get the name of the trading target for my addon.

Lua Code:
  1. local f = CreateFrame("frame")
  2. function f.TRADE_SHOW()
  3.     local name, realm = UnitName("npc")
  4.     print(name..(realm and "-"..realm or "").." has opened a trade with me.")
  5. end
  6. f:RegisterEvent("TRADE_SHOW")
  7. 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:
  1. function TradeFrame_Update()
  2.     SetPortraitTexture(TradeFramePlayerPortrait, "player");
  3.     SetPortraitTexture(TradeFrameRecipientPortrait, "NPC");
  4.     TradeFramePlayerNameText:SetText(GetUnitName("player"));
  5.     TradeFrameRecipientNameText:SetText(GetUnitName("NPC"));
  6.     for i=1, MAX_TRADE_ITEMS, 1 do
  7.         TradeFrame_UpdateTargetItem(i);
  8.         TradeFrame_UpdatePlayerItem(i);
  9.     end
  10.     TradeHighlightRecipient:Hide();
  11.     TradeHighlightPlayer:Hide();
  12.     TradeHighlightPlayerEnchant:Hide();
  13.     TradeHighlightRecipientEnchant:Hide();
  14. end

UnitName is defined in the C portion of WoW's code, but GetUnitName is in UnitFrame.lua:

Lua Code:
  1. function GetUnitName(unit, showServerName)
  2.     local name, server = UnitName(unit);
  3.     local relationship = UnitRealmRelationship(unit);
  4.     if ( server and server ~= "" ) then
  5.         if ( showServerName ) then
  6.             return name.."-"..server;
  7.         else
  8.             if (relationship == LE_REALM_RELATION_VIRTUAL) then
  9.                 return name;
  10.             else
  11.                 return name..FOREIGN_SERVER_LABEL;
  12.             end
  13.         end
  14.     else
  15.         return name;
  16.     end
  17. end

Last edited by Kanegasi : 11-22-18 at 11:47 PM. Reason: Blizzard code
  Reply With Quote