View Single Post
02-10-13, 12:18 PM   #1
zachwlewis
A Murloc Raider
AddOn Author - Click to view addons
Join Date: May 2007
Posts: 5
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
  Reply With Quote