WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   API Reference for looted item (https://www.wowinterface.com/forums/showthread.php?t=49181)

Haegr 04-08-14 10:35 AM

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.

Duugu 04-08-14 02:59 PM

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.

Dridzt 04-08-14 03:14 PM

There's an default tool for tracing events /eventtrace or /etrace

Haegr 04-08-14 04:37 PM

/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.

Clamsoda 04-08-14 05:19 PM

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.

Duugu 04-08-14 05:33 PM

Quote:

Originally Posted by Dridzt (Post 291961)
There's an default tool for tracing events /eventtrace or /etrace

Wow. Never heared of it. Thanks. :)

Cybeloras 04-08-14 09:19 PM

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

Haegr 04-09-14 12:41 AM

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.

Phanx 04-09-14 05:57 AM

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)

Haegr 04-10-14 11:41 AM

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.


All times are GMT -6. The time now is 08:25 AM.

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