WoWInterface (
-   AddOn Help/Support (
-   -   Callback when item is clicked in bag (

paulinamachtmuh 09-01-19 04:28 AM

Callback when item is clicked in bag

can you guys help me. Im trying to create a small addon that will generate macros for me dependant on the weapon that ill be using. For that i want to be able to conveniently select the weapon by clicking on it in my bag. Any hints on what to hook in order to grab the Item Name that I clicked on in my bag?

SDPhantom 09-01-19 01:11 PM

You can hook ContainerFrameItemButton_OnClick() for normal clicks and ContainerFrameItemButton_OnModifiedClick() for modified ones (Example: Shift-Click). To get the bag and slot numbers from these, you need to do something like this.
Lua Code:
  1. hooksecurefunc("ContainerFrameItemButton_OnClick",function(self,button)
  2.     local bag,slot=self:GetParent():GetID(),self:GetID();
  3. --  Do stuff here
  4. end);

Note: Both left and right mouse buttons are already in use by the game. Left lets you move the item while right will equip the weapon you want to click. If you register extra buttons to be recognized as clicks, these functions will pick up the extra buttons as right-clicks. There are better ways of detecting a weapon swap if that's your goal instead. Also keep in mind, macros cannot be edited while in combat, though weapon swapping cannot happen during combat either.

Another option is to use the [equipped] macro conditional. See Macro Conditionals.

paulinamachtmuh 09-01-19 03:07 PM

thank you very much, working perfectly fine. One more question. Do you know a way to actually display the icon of the item within my gui? I couldnt find any predefined element that would let me do it.

SDPhantom 09-02-19 07:42 AM

You can grab the icon from GetContainerItemInfo() and just create a texture object to display it. If you really want to be fancy, you could create a button using the ItemButtonTemplate or ActionButtonTemplate. Whichever suits your needs.

All times are GMT -6. The time now is 07:34 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI