Thread Tools Display Modes
06-23-24, 08:49 AM   #1
GerlockADUS
A Murloc Raider
 
GerlockADUS's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2024
Posts: 6
Trigger toys with click

I am having trouble getting my addon to trigger the toy functionality with button clicks. I have tried UseToy, but that is restricted to the Blizzard UI. I am currently trying "macrotext", but that is not working and I read that is getting removed in 11.0.

What am I doing wrong here? Is it possible? Is there any other way to accomplish this, or is my addon effectively dead on arrival because of the removal of macrotext?

Any help is greatly appreciated.

Here is my current code for the toy button:

Code:
local function CreateToyButton(itemID, parent, index)
    local _, toyName, toyTexture = C_ToyBox.GetToyInfo(itemID)
    local button = CreateFrame("Button", "HearthToyButton"..index, parent, "SecureActionButtonTemplate")
    button:SetSize(TOY_BUTTON_SIZE, TOY_BUTTON_SIZE)
    button:SetNormalTexture(toyTexture or "Interface\\Icons\\INV_Misc_QuestionMark")
    button.itemID = itemID
    
    button:SetScript("OnEnter", function(self)
        GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
        GameTooltip:SetToyByItemID(itemID)
        GameTooltip:Show()
        DebugPrint("Setting macrotext for " .. toyName .. ": /use item:" .. itemID)
    end)
    
    button:SetScript("OnLeave", function(self)
        GameTooltip:Hide()
    end)
    
    button:SetScript("OnClick", function(self)
        print("Clicked toy: " .. toyName .. " " .. itemID)
        print("Macrotext: " .. self:GetAttribute("macrotext1"))
    end)
    
    -- Set macrotext for using the toy
    button:SetAttribute("type", "macro")
    button:SetAttribute("macrotext1", "/use item:" .. itemID)
    button:SetMouseClickEnabled(true)
    button:RegisterForClicks("AnyUp", "AnyDown")
    
    return button
end
  Reply With Quote
06-23-24, 09:30 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,975
Looking at this page there is a UseToy function

https://warcraft.wiki.gg/wiki/API_UseToy

You could then use this example to create a button that uses the secure environment to use the toy on click

https://warcraft.wiki.gg/wiki/Secure...rClickTemplate


I'm still learning the limits and how tos of the secure environment myself but hopefully the example will help you figure out what you need to do for your project.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
06-23-24, 11:07 AM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,931
Instead of using the macro type (see the "toy" type information SecureActionButtonTemplate)

Lua Code:
  1. local f = CreateFrame("Button", "ClickAToyButton", UIParent, "UIPanelButtonTemplate, SecureActionButtonTemplate")
  2. f:SetSize(90, 40)
  3. f:SetPoint("CENTER", UIParent, "CENTER", 100, 0)
  4. f:SetText("Click Me!")
  5. f:RegisterForClicks("AnyUp")
  6. f:SetAttribute("type", "toy")
  7. f:SetAttribute("*toy1", 108634) -- Crashin' Thrashin' Mortar Controller

The macrotext removal is not to stop "basic" things but a giant sledgehammer to stop what they see as some malicious things that have crept into the game over time (although it's still "under discussion" apparently).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 06-23-24 at 01:33 PM.
  Reply With Quote
06-23-24, 12:46 PM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,975
Ah, I was hoping there would be a toy equivalent for the attribute setting.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
06-23-24, 02:26 PM   #5
GerlockADUS
A Murloc Raider
 
GerlockADUS's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2024
Posts: 6
I really appreciate the responses, as this is getting super frustrating. I've spent way to much time trying to get this to work.

Unfortunately, the code you provided is not activating the toy. I don't know what else to do.
  Reply With Quote
06-23-24, 02:49 PM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,931
Originally Posted by GerlockADUS View Post
I really appreciate the responses, as this is getting super frustrating. I've spent way to much time trying to get this to work.

Unfortunately, the code you provided is not activating the toy. I don't know what else to do.
As per the forum reply:

You’re probably wanting to use the spell that is cast when you click the toy, not the toy itself (different button attributes for toys, items, spells etc.).
Toy 54452
https://www.wowhead.com/wotlk/item=5...thereal-portal
should cast
spell 75136
https://www.wowhead.com/spell=75136/ethereal-portal
Lua Code:
  1. local toyButton
  2.  
  3. local function CreateToyButton()
  4.     local _, toyName, toyTexture = C_ToyBox.GetToyInfo(75136)  -- Example: Ethereal Portal
  5.    
  6.     toyButton = CreateFrame("Button", "HearthToyButton", UIParent, "SecureActionButtonTemplate")
  7.     toyButton:SetSize(41, 41)
  8.     toyButton:SetNormalTexture(toyTexture or "Interface\\Icons\\INV_Misc_QuestionMark")
  9.     toyButton:SetPoint("CENTER", UIParent, "CENTER")
  10.    
  11.     toyButton:SetScript("OnEnter", function(self)
  12.         GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  13.         GameTooltip:SetSpellByID(75136)  -- Update with the correct toy item ID
  14.         GameTooltip:Show()
  15.     end)
  16.    
  17.     toyButton:SetScript("OnLeave", function(self)
  18.         GameTooltip:Hide()
  19.     end)
  20.     toyButton:SetAttribute("type", "spell")
  21.     toyButton:SetAttribute("*spell1", 75136)
  22. end
  23.  
  24. local eventFrame = CreateFrame("Frame")
  25. eventFrame:RegisterEvent("PLAYER_LOGIN")
  26. eventFrame:SetScript("OnEvent", function(self, event, arg1)
  27.     if event == "PLAYER_LOGIN" then
  28.         CreateToyButton()
  29.     end
  30. end)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
06-23-24, 03:22 PM   #7
GerlockADUS
A Murloc Raider
 
GerlockADUS's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2024
Posts: 6
You're awesome for offering the suggestion. I thought it might be the answer, but unfortunately it is not working. I plan on developing this further if I can ever get this basic functionality to work. Maybe it's impossible.


I kept the item number in place to handle the texture and GameTooltip, but I changed the number in the button attribute section for the spell. (I also tried changing all references to the item number, but that didn't work either.).

Here is what I have:

Code:
local toyButton

local function CreateToyButton()
    local _, toyName, toyTexture = C_ToyBox.GetToyInfo(54452)  -- Example: Ethereal Portal
    
    toyButton = CreateFrame("Button", "HearthToyButton", UIParent, "SecureActionButtonTemplate")
    toyButton:SetSize(41, 41)
    toyButton:SetNormalTexture(toyTexture or "Interface\\Icons\\INV_Misc_QuestionMark")
    toyButton:SetPoint("CENTER", UIParent, "CENTER")
    
    toyButton:SetScript("OnEnter", function(self)
        GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
        GameTooltip:SetToyByItemID(54452)  -- Update with the correct toy item ID
        GameTooltip:Show()
    end)
    
    toyButton:SetScript("OnLeave", function(self)
        GameTooltip:Hide()
    end)
    
    toyButton:RegisterForClicks("AnyUp")
    toyButton:SetAttribute("type", "spell")
    toyButton:SetAttribute("*spell1", 75136)
end

local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("PLAYER_LOGIN")
eventFrame:SetScript("OnEvent", function(self, event, arg1)
    if event == "PLAYER_LOGIN" then
        CreateToyButton()
    end
end)

Last edited by GerlockADUS : 06-23-24 at 03:29 PM.
  Reply With Quote
06-23-24, 03:28 PM   #8
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,931
I don't have the portal, are you sure your character does/can use?

The Dalaran Hearthstone is considered a toy.
Code:
toyButton:SetAttribute("type", "toy")
toyButton:SetAttribute("*toy1", 140192)
Maybe get idTip to check the toy ID in the Toybox.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 06-23-24 at 03:33 PM.
  Reply With Quote
06-23-24, 03:42 PM   #9
GerlockADUS
A Murloc Raider
 
GerlockADUS's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2024
Posts: 6
I can use the Ethereal Portal from the Toy Box or from my action bar. If I plug in the numbers for the Dalaran Hearthstone, it doesn't work either. My plan is to make a button that will show/hide a frame with all of the hearthstone toys that the character has collected, so you can use different ones, so it doesn't have to be Ethereal Portal.

Did you try and have success with the Dalaran Hearthstone?
  Reply With Quote
06-23-24, 03:50 PM   #10
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,931
Originally Posted by GerlockADUS View Post
I can use the Ethereal Portal from the Toy Box or from my action bar. If I plug in the numbers for the Dalaran Hearthstone, it doesn't work either. My plan is to make a button that will show/hide a frame with all of the hearthstone toys that the character has collected, so you can use different ones, so it doesn't have to be Ethereal Portal.

Did you try and have success with the Dalaran Hearthstone?
This works for me:
Lua Code:
  1. local f = CreateFrame("Button", "ClickAToyButton", UIParent, "UIPanelButtonTemplate, SecureActionButtonTemplate")
  2. f:SetSize(90, 40)
  3. f:SetPoint("CENTER", UIParent, "CENTER", 100, 0)
  4. f:SetText("Click Me!")
  5. f:RegisterForClicks("AnyUp")
  6. f:SetScript("OnEnter", function(self)
  7.     GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  8.     GameTooltip:SetToyByItemID(140192)  -- Update with the correct toy item ID
  9.     GameTooltip:Show()
  10. end)
  11. f:SetScript("OnLeave", function(self)
  12.     GameTooltip:Hide()
  13. end)
  14. f:SetAttribute("type", "toy")
  15. f:SetAttribute("*toy1", 140192) -- Dalaran Hrarthstone
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 06-23-24 at 04:00 PM.
  Reply With Quote
06-23-24, 04:02 PM   #11
GerlockADUS
A Murloc Raider
 
GerlockADUS's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2024
Posts: 6
Interesting. I wonder why it's not working for me. It's the only addon that I have enabled.
Thank you for your help. I don't want to be a bother. I think I'm at a dead end, for now at least.
  Reply With Quote
06-23-24, 04:07 PM   #12
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,931
It' try exiting and renaming the Interface folder and let the game create a new one then create a single addon with new .toc and .lua file in it.
You can delete the new folder and rename the old one back.

This also works for me
Lua Code:
  1. local toyButton
  2.  
  3. local function CreateToyButton()
  4.     local _, toyName, toyTexture = C_ToyBox.GetToyInfo(140192)  -- Example: Ethereal Portal
  5.    
  6.     toyButton = CreateFrame("Button", "HearthToyButton", UIParent, "SecureActionButtonTemplate")
  7.     toyButton:SetSize(41, 41)
  8.     toyButton:SetNormalTexture(toyTexture or "Interface\\Icons\\INV_Misc_QuestionMark")
  9.     toyButton:SetPoint("CENTER", UIParent, "CENTER")
  10.    
  11.     toyButton:SetScript("OnEnter", function(self)
  12.         GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  13.         GameTooltip:SetToyByItemID(140192)  -- Update with the correct toy item ID
  14.         GameTooltip:Show()
  15.     end)
  16.    
  17.     toyButton:SetScript("OnLeave", function(self)
  18.         GameTooltip:Hide()
  19.     end)
  20.    
  21.     toyButton:RegisterForClicks("AnyUp")
  22.     toyButton:SetAttribute("type", "toy")
  23.     toyButton:SetAttribute("*toy1", 140192)
  24. end
  25.  
  26. local eventFrame = CreateFrame("Frame")
  27. eventFrame:RegisterEvent("PLAYER_LOGIN")
  28. eventFrame:SetScript("OnEvent", function(self, event, arg1)
  29.     if event == "PLAYER_LOGIN" then
  30.         CreateToyButton()
  31.     end
  32. end)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 06-23-24 at 04:09 PM.
  Reply With Quote
06-23-24, 04:18 PM   #13
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,931
You might also have the actionButtonUseyKeyDown CVar set (I keep forgetting that one).
Try replacing your RegisterForClicks with
Code:
toyButton:RegisterForClicks("AnyDown", "AnyUp")
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
06-23-24, 05:20 PM   #14
GerlockADUS
A Murloc Raider
 
GerlockADUS's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2024
Posts: 6
YYEEEEESSSSSS!!!!!! This was it! And I could have sworn that I tried that before!

THANK YOU!!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Trigger toys with click

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off