WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Send a slash command to execute another addon (with itemlink) (https://www.wowinterface.com/forums/showthread.php?t=58717)

onesock 05-03-21 01:31 PM

Send a slash command to execute another addon (with itemlink)
 
Given I have a button in my code with an itemlink available to it, I want to be able to click the button and execute another addon's command that uses the link that would be "shift clicked" from the item via the standard wow UI.

I see how to add macrotext to a button frame like this (may not be 100% correct):

Lua Code:
  1. local frame = CreateFrame("Button", nil, region, "SecureActionButtonTemplate")
  2. frame:SetAllPoints(region)
  3. frame:SetAttribute("type","macro")
  4. frame:SetAttribute("macrotext", [[
  5. /cast [@player] Arcane Intellect(Rank 5)
  6. ]])
  7. frame:RegisterForClicks("AnyDown")

I can change the command to do a /command, but I cannot pass an itemlink. Is there something more intuitive/built in command for doing what I'm trying to do?

Thanks!

SDPhantom 05-03-21 06:04 PM

Commands are stored in the SlashCmdList table. You'll need the token the addon uses to register the command.
For example, you can open BigWigs' options window by calling this.
Code:

SlashCmdList.BigWigs()
To send arguments, just pass them as a single string to the function, similar to this.
Code:

SlashCmdList.TOKEN("args")


While you can also access commands using hash_SlashCmdList, slash commands are often localized, meaning your code probably won't work in other languages. SlashCmdList is more stable as tokens are not supposed to be localized.



If you insist on using macro buttons, you can inject links using concatenation or formatting. Note this is also susceptible to localization.
For example, this'll make you send the link for Hearthstone in /say.
Lua Code:
  1. local frame = CreateFrame("Button", nil, region, "SecureActionButtonTemplate")
  2. frame:SetAllPoints(region)
  3. frame:SetAttribute("type","macro")
  4. frame:SetAttribute("macrotext", "/say " .. select(2, GetItemInfo(6948)))
  5. frame:RegisterForClicks("AnyDown")

onesock 05-04-21 07:24 AM

Fantastic! I was hoping there was a better way than this macro-generating method I saw in WeakAuras code.

Thanks!


edit - worked like a charm. So glad I stumbled onto this site <3


All times are GMT -6. The time now is 06:24 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI