WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Currency Name to Currency ID (https://www.wowinterface.com/forums/showthread.php?t=55334)

bsmorgan 04-18-17 11:25 AM

Currency Name to Currency ID
 
According to wow.gamepedia.com/API_GetMerchantItemCostItem the 3rd and 4th return values are:

itemLink
String - An itemLink for the cost item, nil if a currency.
currencyName
String - Name of the currency required, nil if an item.

I want to know how much of the currency the player has, but all the currency API functions seem to want an index or an ID, not the localized name of the currency. Am I missing something? Do I have to enumerate all the currencies until I find a localized name match to get the index or ID?

briskman3000 04-18-17 02:05 PM

From looking at how other currency tracking addons get the data, they loop through GetCurrencyListInfo() for GetCurrencyListSize() times to pull all of the currency info the player currently has into a table or a db, and then they manipulate the data into their output frames.

semlar 04-18-17 03:56 PM

Looks like you can just call GetMerchantItemCostItem for the item link and then call GetItemCount(itemLink, false, false, true) for your count.

This is what the interface does to check if you can afford something.

bsmorgan 04-19-17 08:35 AM

Quote:

Originally Posted by semlar (Post 322968)
Looks like you can just call GetMerchantItemCostItem for the item link and then call GetItemCount(itemLink, false, false, true) for your count.

As noted in the OP, GetMerchantItemCostItem returns nil for the itemLink if the cost is a currency (for example, Garrison Resources). I have what I need if the itemLink is not nil. If it is nil, all I have now is the localized name of the currency and no way to find how how much of that currency the player has without converting the localized name to something usable by the currency APIs.

Unfortunately, I think briskman3000 has the solution (I didn't want to go there).

semlar 04-19-17 01:50 PM

Since the UI lists out your currencies on the vendor frame, you can look at how it does that to get your currency counts.

It calls GetMerchantCurrencies() to get what currencies you can spend at the current vendor, and GetCurrencyInfo() to get the name and count for them.

You should only need to loop over your entire list of currencies if the vendor doesn't tell you what currencies you can spend at it.

bsmorgan 04-19-17 04:20 PM

For Skillet, I'm looking at further refinement of the "how many can I craft" counts. When I fixed the calculations because someone reported they were too low, I discovered that some counts were now too high because, for example, you could trade Blood of Sargaras for almost all of the Legion crafting materials, and Garrison Resources for most of the WoD crafting materials.

I now (optionally) ignore materials obtained that way, but if you change the option to consider them, it would be better to see how many you could buy with the currency you have as opposed to just using infinity.

Since I need to use the count at the time I do the calculations, GetCurrencyInfo(id) will work the best but finding the value for id isn't exactly obvious. I believe I've got it now.


All times are GMT -6. The time now is 10:33 AM.

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