Thread Tools Display Modes
01-04-16, 09:14 PM   #1
Nandchan
A Murloc Raider
Join Date: May 2013
Posts: 6
Detecting when a player manually sells or destroys an item?

As the title implies, I'm trying to detect if a player has manually sold or destroyed an item.

There don't really seem to be any events that are indicative of this happening, at least none I can tell.

I did a trace of selling an item and it looks something like this:

ITEM_LOCK_CHANGED (bagID = 0, slot = 2)
ITEM_LOCKED (bagID = 0, slot = 2)
BAG_UPDATE (containerID = 0)
PLAYER_MONEY
MERCHANT_UPDATE
BAG_UPDATE_DELAYED

which doesn't exactly seem very useful.

I could perhaps listen for MERCHANT_UPDATE and check the merchant's buy-back tab (how?) to see if an item was added to the list, but I'm not sure how much of a reliable/smart idea that is - and plus it doesn't work for deleting items at all.

For deleting an item, it looks like this:

DELETE_ITEM_CONFIRM (Item name = Blacksmith Hammer, 1, 0, 0)
ITEM_LOCK_CHANGED (bagID = 0, slot = 4)
ITEM_UNLOCKED (bagID = 0, slot = 4)
BAG_UPDATE (container ID = 0)
BAG_UPDATE_DELAYED

I could try remembering the item names off any DELETE_ITEM_CONFIRM prompts, followed by looking at BAG_UPDATE to see if that item was actually removed - but it also seems rather brittle and inelegant.

Does anybody have any ideas as for how I could do this in a clean and elegant way?
  Reply With Quote
01-12-16, 06:06 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well, for deleting, that event sequence looks pretty straightforward:

1. When you see DELETE_ITEM_CONFIRM, store the name in a temporary variable.
2. When you see ITEM_LOCK_CHANGED, get info about the item in the indicated bag/slot. If the name matches what you saw in #1, you now have the item ID, full item link, or whatever other info you want to keep about the item being deleted.

You could probably add a #3 where you verify that the item was successfully deleted when you see ITEM_UNLOCKED or BAG_UPDATE, but it's probably not necessary.

For selling items, you could hook UseContainerItem; something like:

Code:
hooksecurefunc("UseContainerItem", function(bag, slot)
    -- if the merchant frame is shown, and not to the buyback panel,
    -- then you are selling the indicated item
end)
and then proceed with watching bag events to see when the item successfully leaves your bags.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
01-12-16, 02:36 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,325
Originally Posted by Phanx View Post
For selling items, you could hook UseContainerItem; something like:

Code:
hooksecurefunc("UseContainerItem", function(bag, slot)
    -- if the merchant frame is shown, and not to the buyback panel,
    -- then you are selling the indicated item
end)
You might want to hook PickupMerchantItem() as well since that sells any item that's being held by mouse cursor.
__________________
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

WoWInterface » Developer Discussions » General Authoring Discussion » Detecting when a player manually sells or destroys an item?


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