WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Tracking item use (https://www.wowinterface.com/forums/showthread.php?t=24863)

Tuhljin 06-19-09 02:35 PM

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?

dirtygurl 06-20-09 07:07 AM

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.

jaliborc 06-20-09 07:59 AM

Simple: use hooksecurefunc to hook UseContainerItem. Done!

Nafe 06-20-09 10:47 AM

Quote:

Originally Posted by jaliborc (Post 143907)
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

Quote:

Originally Posted by Tuhljin (Post 143799)
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?

Tuhljin 06-20-09 07:36 PM

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


All times are GMT -6. The time now is 02:33 PM.

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