Thread Tools Display Modes
03-27-15, 09:07 PM   #1
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Checking if item is usable

This is driving me crazy. How can I check if an item actually is usable?
IsUsableItem() is not what I'm looking for. This is what I use in my OnTooltipSetItem script:
Lua Code:
  1. ...
  2. elseif  MerchantFrame:IsVisible()        then CLICK_STRING = G.CLICK.SELL;
  3. elseif  IsEquippedItem(self:GetItem())   then CLICK_STRING = G.CLICK.REPLACE;
  4. elseif  IsEquippableItem(self:GetItem()) then CLICK_STRING = G.CLICK.EQUIP;
  5. elseif  IsUsableItem(self:GetItem())     then CLICK_STRING = G.CLICK.USE;
  6. ...
CLICK_STRING is added to the tooltip depending on the outcome of this check.
However, the last line adds to pretty much any item that isn't currently locked out.
This means even grey, non-usable items will get the "Use" string added to it.

How can I check explicitly for items that have a Use effect?

Edit: For anyone else asking this question, the answer is here:
Originally Posted by SDPhantom View Post
I remember using GetItemSpell() to poke around and see what spells different items triggered. As far as I remember, it only returns spell name and rank if there is one attached to said item.
__________________

Last edited by MunkDev : 03-28-15 at 02:52 PM.
  Reply With Quote
03-27-15, 10:06 PM   #2
Barjack
A Black Drake
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 89
From what I've seen, any addon that tries to detect the presence of a "Use:" effect is forced to do so via tooltip scanning. Obviously this is a very bad solution, but I don't know if there is any other. Maybe some new technique was added that I'm unaware of, though.

On the plus side it should be relatively easy to cache a true/false value for each item ID once you've done a successful scan, if it's something you need to check often.
  Reply With Quote
03-27-15, 10:20 PM   #3
jeruku
A Cobalt Mageweaver
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 223
First I would like to point out that IsConsumableItem() and IsUsableItem() both do not function the way you think. Second, you should upvalue self:GetItem() if it is used more than a few times.

These are two approaches you could take. If you are already dealing with the tooltip you could just scan it for USE_COLON or make a table of usable ItemTypes. The latter would also allow you to define each category yourself.

Lua Code:
  1. --...
  2. local _, _, _, _, _, itemType, itemSubType= GetItemInfo(self:GetItem())
  3. CLICK_STRING = aTable[itemType][itemSubType]
  4. --...
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison

Last edited by jeruku : 03-27-15 at 10:21 PM. Reason: spaces...
  Reply With Quote
03-27-15, 11:33 PM   #4
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
I don't think they function like you think I think they function. lol. I know how they work. The reason I even included that function call is because I didn't want posts from people who search the API listing and post the first function they find that seems to do the trick.

I was asking if there's actually any reliable way to determine whether an item is usable. It seems there isn't. Scanning the tooltip would only apply for the USE_COLON, but not for items that lack any tooltip use indication, which happens sometimes.
__________________
  Reply With Quote
03-27-15, 11:53 PM   #5
Barjack
A Black Drake
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 89
Originally Posted by MunkDev View Post
I don't think they function like you think I think they function. lol. I know how they work. The reason I even included that function call is because I didn't want posts from people who search the API listing and post the first function they find that seems to do the trick.

I was asking if there's actually any reliable way to determine whether an item is usable. It seems there isn't. Scanning the tooltip would only apply for the USE_COLON, but not for items that lack any tooltip use indication, which happens sometimes.
Are there many items that are usable but don't have a Use: in their tooltip? I was surprised that the SELFIE cameras seemingly don't, but they may be the only exception that I remember seeing. There are also items with "This Item Begins a Quest" which might be considered "usable" depending on what you want the addon to do.

But you're right as far as I know: there is no reliable way in the API to know whether using an item (i.e. by UseItemByName, UseInventoryItem, etc.) will actually do something or not. With tooltip scanning you're only really guessing (though pretty accurately, I would say).
  Reply With Quote
03-28-15, 03:15 AM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
I remember using GetItemSpell() to poke around and see what spells different items triggered. As far as I remember, it only returns spell name and rank if there is one attached to said item.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
03-28-15, 08:36 AM   #7
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Originally Posted by SDPhantom View Post
I remember using GetItemSpell() to poke around and see what spells different items triggered. As far as I remember, it only returns spell name and rank if there is one attached to said item.
This worked surprisingly well, if not exactly as I want it to. I checked on several characters and the tooltip line now only shows on items that are in fact usable, even on things that have no apparent spell or use effect attached. Thanks
__________________

Last edited by MunkDev : 03-28-15 at 10:18 AM.
  Reply With Quote
03-28-15, 10:30 AM   #8
jeruku
A Cobalt Mageweaver
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 223
SDPhantom happened to have the best solution. I added the information to the wiki GetItemSpell as I am surely not the only one who ignores undocumented functions.

I apologize if I offended in anyway or caused any confusion. Just trying to mention that IsUsableItem is used to determine whether or not an item is in your bags or in your bank while the bank UI is shown. (If I recall my history lessons correctly anyway.)
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison
  Reply With Quote
03-28-15, 02:34 PM   #9
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
IsUsableItem() ought to be renamed, because its name is very misleading.
Maybe I should have been clearer. The reason I previously had that in my code was because I didn't want to add that tooltip to inaccessible items. It was not because I thought it would only apply to usable items.

I failed to follow the basic principle of showing all code. I wanted to determine if items were usable because I wanted to offer the ability to bind them to a DIY extra button.

I found that GetItemSpell() works even with items that do not have USE_COLON in the tooltip, but it will not trigger for items that have no direct use.
__________________
  Reply With Quote
03-29-15, 12:11 PM   #10
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
Can you give an example of an item with no "direct use"?
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
03-29-15, 12:35 PM   #11
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by SDPhantom View Post
Can you give an example of an item with no "direct use"?
The selfie camera has no "Use" listed in the tooltip, presumably an oversight.
  Reply With Quote
03-29-15, 02:16 PM   #12
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
There are a lot of items that don't have it but will still get results from GetItemSpell().
I can't mention any specific item right now, but usually it's the type of item where you can choose whether to click it from your bags or through a cogwheel interaction in 3D space. The fact remains though, it is only triggered for items that can actually be used by clicking them.

Edit: To avoid any confusion here, I meant it won't trigger for junk items or reagents that you cant split or combine. It will only trigger for items where something actually happens if you right click. Sometimes, an item does not have a green USE_COLON tooltip, but will still get results from GetItemSpell(), because, contrary to the tooltip, something actually happens when you use said item.
__________________

Last edited by MunkDev : 03-30-15 at 08:04 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Checking if item is usable


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