View Single Post
11-23-18, 01:25 AM   #8
outer1990
A Defias Bandit
Join Date: Nov 2018
Posts: 3
Originally Posted by Kanegasi View Post
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
thank you, it does let me know who opens trade with me which is useful to know when trading with 10+ people at once. thank you for this script... it has been added on. Still must target the person when accepting a trade to get there name in "Xname has traded you 2000g confirmed" Dont think it is possible.. but still a useful script! <3
  Reply With Quote