WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Determining a recipe's "learnability." (https://www.wowinterface.com/forums/showthread.php?t=45812)

zachwlewis 02-10-13 12:18 PM

Determining a recipe's "learnability."
 
I've an addon that currently will look through a merchant's inventory and tell the user how many recipes he has. I'd also like it to list how many recipes he has that are currently learnable.

I tried using the function IsUsableItem(itemLink), but that function returns true for any recipe I currently have in my inventory (which, technically, is usable, I suppose). What function should I be using to determine an item's "learnability?" The more information I can get, the better.

Here's my current merchant search:

Lua Code:
  1. function checkMerchantInventory()
  2.   local itemCount = GetMerchantNumItems()
  3.   local recipeCount = 0
  4.   local usableCount = 0
  5.   for i=1,itemCount do
  6.     -- Our current item.
  7.     local currentItem = GetMerchantItemLink(i)
  8.     if (currentItem == nil) then
  9.       scanSuccessful = false
  10.       return
  11.     end
  12.    
  13.     -- Get assorted information about the item.
  14.     local name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(currentItem)
  15.  
  16.     if (class == "Recipe") then
  17.       recipeCount = recipeCount + 1
  18.  
  19.       -- Get usability information about the item.
  20.       local isUsable = IsUsableItem(currentItem)
  21.       if (isUsable) then
  22.         usableCount = usableCount + 1
  23.         print(currentItem)
  24.       end
  25.     end
  26.   end
  27.  
  28.   -- Search output
  29.   if recipeCount > 0 then
  30.     print("|cFFFF6666 Look! New Recipe!|r "..recipeCount.." recipes, of which "..usableCount.." are useable.")
  31.     PlaySoundFile("Sound/Creature/Cat/CatStepA.ogg")
  32.   else
  33.     print("|cFFFF9999 No new recipes found.|r")
  34.   end
  35.  
  36.   scanSuccessful = true
  37. end

Lombra 02-10-13 02:26 PM

There is a usable return in GetMerchantItemInfo. That might work better?
Code:

local name, texture, price, quantity, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(index)

zachwlewis 02-10-13 02:51 PM

Interesting. That returns something different than IsUsableItem(item); however, it will still return true if the recipe is already known.

Any suggestions there?

Lombra 02-10-13 03:31 PM

Quote:

Originally Posted by zachwlewis (Post 272921)
Interesting. That returns something different than IsUsableItem(item); however, it will still return true if the recipe is already known.

Any suggestions there?

That is what the UI uses to deterrmine whether to color items red in the vendor frame. I was going to quote just before you editted your post (not that it matters, I guess), but I don't think there's another solution than scanning the tooltip. You can only get a generic "Learning" spell from GetItemSpell, unfortunately. You could try to parse the created item from the recipe name/tooltip and compare to your trade skills, but that's not really reliable.

Rilgamon 02-11-13 02:41 AM

Tooltip scanning comes to my mind. You create a tooltip and then you check for the line that says this recipe is known. Unluckily I never tried it myself so I just know the theory ;)


All times are GMT -6. The time now is 12:27 PM.

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