Thread Tools Display Modes
06-19-09, 02:35 PM   #1
Tuhljin
A Flamescale Wyrmkin
 
Tuhljin's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2008
Posts: 106
Tracking item use

What is the easiest way for an addon to notice that an item has been used, and which item it is? I'm attempting to track whether the player has ever consumed a given food/drink item before. In order to do so, since Blizzard removed the much easier way I'd been doing it prior to 3.1 and has been unresponsive when asked about it (e.g. see here), the addon needs to know when the player consumes something and what that something was. I've looked over the events that seemed relevant and they just aren't very helpful. Nothing seems to give you reference to which item is involved, and more importantly, they don't tell you if the player actually used the item rather than losing it in some other way (e.g. dropping it or trading it away).

It seemed like I'd have to keep track of all the relevant items in the bags, checking at startup and then using BAG_UPDATE to see if an item (including partial stacks) are lost... but again, you don't know for sure that the player actually consumed the item.

Any ideas?
  Reply With Quote
06-20-09, 07:07 AM   #2
dirtygurl
A Murloc Raider
 
dirtygurl's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2009
Posts: 4
concerning food/drink usage, you could check the buff (UNIT_AURA) instead of checking the item stacks BUT you are right, i haven't found anything on how to get the actual item used.

do you mind posting you old code? i dunno, it might be relevant or helpful in tracking down something.
  Reply With Quote
06-20-09, 07:59 AM   #3
jaliborc
A Chromatic Dragonspawn
 
jaliborc's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 196
Simple: use hooksecurefunc to hook UseContainerItem. Done!
  Reply With Quote
06-20-09, 10:47 AM   #4
Nafe
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 17
Originally Posted by jaliborc View Post
Simple: use hooksecurefunc to hook UseContainerItem. Done!
UseContainerItem is used in more cases than just using an item. It also (if I remember correctly) sells items to merchants, places them in mail messages, and adds them to/removes them from the bank, amongst other things.
A list of things can seemingly be found at WoWwiki:
http://www.wowwiki.com/API_UseContai...otection_Notes

Originally Posted by Tuhljin View Post
but again, you don't know for sure that the player actually consumed the item.
I guess in order to successfully use hooking UseContainerItem for your purpose, you will need checks to see if any of those windows are open.


Just a general (and probably stupid question): did you check to see if using an item triggers any event other than BAG_UPDATE, using an addon such as DevTools?
  Reply With Quote
06-20-09, 07:36 PM   #5
Tuhljin
A Flamescale Wyrmkin
 
Tuhljin's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2008
Posts: 106
Thanks for all the input. Unfortunately, I still haven't found something reliable to use for this.

Not only does a hook for UseContainerItem trigger when doing such things as selling items, it can also trigger when the player attempts to use something but fails to do so. (It also doesn't trigger when the player uses the item by way of the action bar or script commands; I could perhaps find other things to hook or events to watch for for those cases, but the same limitations apply.)

Because the consumable items I need to check aren't always, say, food/drink that give health/mana (and even if they were, the aura name often doesn't help identify the item used), events like UNIT_AURA and those for the combat log don't always work and both they and other events I found using DevTools (like UNIT_SPELLCAST_SUCCEEDED) don't give enough data in the args they give.

As for the old code I used for this, it wouldn't be helpful because it never did any actual tracking. Blizzard did the tracking for me, and I would just use GetAchievementCriteriaInfo to see what had and hadn't been consumed.


Edit: Now I'm thinking about using a combination of watching bag contents with BAG_UPDATE and watching for CRITERIA_UPDATE to watch for an increase in the number of food/drink consumed in the achievement.. Hopefully I can get something worked out there, though the limitation is that CRITERIA_UPDATE won't fire if you've already consumed a given item (so that food you ate months ago will remain marked as unconsumed even if you eat it again today).

I really wish Blizzard would give me back the old GetAchievementCriteriaInfo functionality. I still don't know why they tampered with it. >:P

Last edited by Tuhljin : 06-20-09 at 07:49 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Tracking item use


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