Reply
Thread Tools Display Modes
Unread 04-08-14, 10:35 AM   #1
Haegr
A Murloc Raider
Join Date: Apr 2014
Posts: 4
API Reference for looted item

I'm new to the API, brand new - this is the first addon I've ever bothered to try to create.

I'm crawling through the API but I can't find what I need so I figured I'd ask here.

First what I am trying to write; an addon that tells me what I have prospected / disenchanted. So I need to find the item I have just prospected / disenchanted as well as the addons that I have just looted from what I just prospected / disenchanted.

Any help / a point in the right direction would be fantastic.

Thanks.
Haegr is offline   Reply With Quote
Unread 04-08-14, 02:59 PM   #2
Duugu
Premium Member
 
Duugu's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 764
I would say you'll have to monitor an event that fires if you disenchant something or prospect something. I have no idea which are the proper events. But there are a least two ways to find it out:

1. Look at http://wowprogramming.com/docs/events for the events.

2. Or create a test frame and try RegisterAllEvents (http://wowprogramming.com/docs/widge...isterAllEvents). Then disenchant/prospect something and see which events are fireing.
Duugu is offline   Reply With Quote
Unread 04-08-14, 03:14 PM   #3
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,192
There's an default tool for tracing events /eventtrace or /etrace
Dridzt is offline   Reply With Quote
Unread 04-08-14, 04:37 PM   #4
Haegr
A Murloc Raider
Join Date: Apr 2014
Posts: 4
/etrace helped me find the events I was looking for but none of them have given me the quantity of the item I am receiving, nor an ID it seems.
Haegr is offline   Reply With Quote
Unread 04-08-14, 05:19 PM   #5
Clamsoda
A Cobalt Mageweaver
Join Date: Nov 2011
Posts: 246
Often times, events just let you know when information is available. That being said, I've never tried to attempt what you are doing. If the events associated with DEing items don't return amounts and such, you may be able to filter chat events.

I know amounts DEed/prospected are printed to chat; you could pattern match chat to get the values.

That's off of the top of my head. I am sure someone knows a better way.
Clamsoda is offline   Reply With Quote
Unread 04-08-14, 05:33 PM   #6
Duugu
Premium Member
 
Duugu's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 764
Originally Posted by Dridzt View Post
There's an default tool for tracing events /eventtrace or /etrace
Wow. Never heared of it. Thanks.
Duugu is offline   Reply With Quote
Unread 04-08-14, 09:19 PM   #7
Cybeloras
A Fallenroot Satyr
 
Cybeloras's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 23
Use UNIT_SPELLCAST_SUCCEEDED to determine when you have cast disenchant or prospect: http://wowprogramming.com/docs/event...CAST_SUCCEEDED
Use ITEM_LOCK_CHANGED to determine what item was targeted: http://wowprogramming.com/docs/events/ITEM_LOCK_CHANGED
Use the loot API to figure out what you have received: http://wowprogramming.com/docs/api_categories#loot

Last edited by Cybeloras : 04-08-14 at 09:26 PM.
Cybeloras is offline   Reply With Quote
Unread 04-09-14, 12:41 AM   #8
Haegr
A Murloc Raider
Join Date: Apr 2014
Posts: 4
I looked at the loot API before Cybeloras but I don't know how it will perform when I am autolooting and there doesn't seem to be any method to return a count of a stacked item, just total items to be looted - unless GetNumLootItems is per slot, which it probably is.

I may actually just use the "GetItemInfo" method and count up all the known items when logging in and when logging out, which would suit my needs.

Thanks for all the help.

Last edited by Haegr : 04-09-14 at 12:43 AM.
Haegr is offline   Reply With Quote
Unread 04-09-14, 05:57 AM   #9
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,576
GetNumLootItems doesn't tell you anything about the individual items to be looted; it only tells you how many items to show in the list of items to loot. You can then pass values from 1-n, where n is the number it gave you, into GetLootSlotInfo to get information about each item, including how many of it are there.

I'd strongly suggest you look at the code of other addons that do things like this, or even the default UI, to get an idea of how to use these functions. There's also lots of detailed documentation on sites like Wowprogramming.com (which Cybeloras linked you to) and Wowpedia.org that tells you exactly what each function does and how to use it, so you don't have to guess or spend hours on trial-and-error attempts.

Edit:
Code:
local currentItem

local f = CreateFrame("Frame")
f:RegisterUnitEvent("UNIT_SPELLCAST_SUCCEEDED", "player")
f:SetScript("OnEvent", function(self, event, ...)
	if event == "UNIT_SPELLCAST_SUCCEEDED" then
		local unit, spell, rank, lineID, spellID = ...
		if spellID == 13262 then
			self:RegisterEvent("ITEM_LOCK_CHANGED")
			self:RegisterEvent("LOOT_OPENED")
		end
	elseif event == "ITEM_LOCK_CHANGED" then
		local bag, slot = ...
		local texture, count, locked, quality, readable, lootable, link = GetContainerItemInfo(bag, slot)
		if locked then
			currentItem = link
		else
			currentItem = nil
			self:UnregisterEvent("ITEM_LOCK_CHANGED")
			self:UnregisterEvent("LOOT_OPENED")
		end
	elseif event == "LOOT_OPENED" then
		print("Loot from disenchanting", currentItem)
		for i = 1, GetNumLootItems() do
			local lootType = GetLootSlotType(i)
			local texture, item, quantity, quality, locked = GetLootSlotInfo(i)
			if lootType == 2 then
				print("Money:", item)
			else
				print(GetLootSlotLink(i), "x", quantity)
			end
		end
	end
end)
Order of events goes:

1. UNIT_SPELLCAST_SUCCEEDED (player finishes casting Disenchant)
2. ITEM_LOCK_CHANGED (target item becomes locked)
3. LOOT_OPENED (loot window opens)
4. ITEM_LOCK_CHANGED (target item becomes unlocked after loot window closes)
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!

Last edited by Phanx : 04-09-14 at 06:33 AM.
Phanx is offline   Reply With Quote
Unread 04-10-14, 11:41 AM   #10
Haegr
A Murloc Raider
Join Date: Apr 2014
Posts: 4
I was reading through the API on breaks at work, I only have time to play around on weekends.

Many thanks for the code sample! I shall be testing it over the weekend. Thank you very much.
Haegr is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » General Authoring Discussion » API Reference for looted item

Thread Tools
Display Modes

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