Thread Tools Display Modes
04-18-17, 11:25 AM   #1
bsmorgan
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 219
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?
  Reply With Quote
04-18-17, 02:05 PM   #2
briskman3000
A Flamescale Wyrmkin
 
briskman3000's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 108
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.
__________________
My Addons: Convert Ratings Honor Track
  Reply With Quote
04-18-17, 03:56 PM   #3
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
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.

Last edited by semlar : 04-18-17 at 04:00 PM.
  Reply With Quote
04-19-17, 08:35 AM   #4
bsmorgan
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 219
Originally Posted by semlar View Post
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).

Last edited by bsmorgan : 04-19-17 at 08:47 AM.
  Reply With Quote
04-19-17, 01:50 PM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
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.
  Reply With Quote
04-19-17, 04:20 PM   #6
bsmorgan
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 219
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.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Currency Name to Currency ID


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