View Single Post
01-11-24, 03:24 PM   #19
Carriola
A Murloc Raider
Join Date: Jan 2024
Posts: 4
Originally Posted by Xrystal View Post
This works in 10.2.5 so hopefully it will work for you

How this example addon works is when you first log in / reload the ui you can open the tradeskill of your choice and it will automatically grab the skill link and send it via addonmessage to the chatframe. The addon then stops checking for the tradeskill frame being opened and closes the window. It then sees there is an addon message and grabs the link sent earlier and puts it into the fontstring set up for it.
Clicking on that link will then bring up the trade skill window ( showing the name of the link sender - in my case me ).

Looking at the tradeskill frame there is no option for WHISPERing the tradeskill link automatically as an addon message with a special prefix. So I had to use this roundabout route to get the tradeskill link and send it manually via addonmessage with the prefix.

It adds a clickable profession link to a font string so does what you are asking, you might just have to do some additional work, to make it work in your addon.

If my example doesn't work for you in 10.2.0 or 10.2.5 then mayhap something is not working right at your end and could explain the problems you are having. And as Fizzle says, we cannot help with addons not designed to work on official servers.

Lua Code:
  1. local addonName,db = ...
  2.  
  3. -- Simple Frame to display the link(s) and control how that link works when you click it
  4. local cf = CreateFrame("Frame","TestFrame",UIParent)
  5. cf:SetSize(600,100)
  6. cf:SetPoint("CENTER",0,0)
  7. cf:SetHyperlinksEnabled(true)
  8. cf:SetScript("OnHyperlinkClick", ChatFrame_OnHyperlinkShow)
  9.  
  10. -- Font string that holds the text
  11. -- I am just using one, but you could have a list of strings set up
  12. cf.fs = cf:CreateFontString(nil,"OVERLAY","GameFontNormal")
  13. cf.fs:SetAllPoints()
  14.  
  15. local function OnEvent(self,event,...)    
  16.     local args = { ... }
  17.    
  18.     -- Register addon message prefix when the addon is loaded
  19.     if event == "ADDON_LOADED" and args[1] == addonName then
  20.         local successfulRequest = C_ChatInfo.RegisterAddonMessagePrefix("XTA-AMP")
  21.         if successfulRequest then db.addonMessagePrefix = "XTA-AMP" end
  22.        
  23.     -- This is used to get the trade skill link when they open the tradeskill frame
  24.     -- If you have another way to send the addon message the link then use that
  25.     elseif event =="TRADE_SKILL_SHOW" then
  26.         self:RegisterEvent("TRADE_SKILL_LIST_UPDATE")
  27.        
  28.     elseif event == "TRADE_SKILL_LIST_UPDATE" then
  29.         local link = C_TradeSkillUI.GetTradeSkillListLink()
  30.         local success = C_ChatInfo.SendAddonMessage(db.addonMessagePrefix, link,  "WHISPER", UnitName("player"))
  31.        
  32.         -- Make sure we close the tradeskill frame and unregister events so that it doesn't trigger until the next reload
  33.         C_TradeSkillUI.CloseTradeSkill()
  34.         self:UnregisterEvent("TRADE_SKILL_LIST_UPDATE")
  35.         self:UnregisterEvent("TRADE_SKILL_SHOW")
  36.        
  37.     -- Monitor Addon messages in the chat frame
  38.     elseif event == "CHAT_MSG_ADDON" then
  39.         -- args 1 is the prefix
  40.         -- args 2 is the message
  41.         if args[1] == db.addonMessagePrefix then
  42.             -- set the profession link to the fontstring requiring it
  43.             -- remember I am using a single fontstring, if you are using multiple, make sure you are updating the correct one
  44.             cf.fs:SetText(args[2] or "")
  45.         end
  46.            
  47.     end
  48.    
  49. end
  50.  
  51. local f = CreateFrame("Frame")
  52. f:RegisterEvent("ADDON_LOADED")
  53. f:RegisterEvent("PLAYER_LOGIN")
  54. f:RegisterEvent("TRADE_SKILL_SHOW")
  55. f:RegisterEvent("CHAT_MSG_ADDON")
  56. f:SetScript("OnEvent",OnEvent)

Wow thanks Xrystal!! this solution works but I don't know why (I'm a beginner addon developer :P)! You are very kind! Thanks a lot Fizzlemizz too for time and advice!
Good community
  Reply With Quote