Thread Tools Display Modes
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
02-10-13, 02:26 PM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
There is a usable return in GetMerchantItemInfo. That might work better?
Code:
local name, texture, price, quantity, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(index)
__________________
Grab your sword and fight the Horde!
  Reply With Quote
02-10-13, 02:51 PM   #3
zachwlewis
A Murloc Raider
AddOn Author - Click to view addons
Join Date: May 2007
Posts: 5
Interesting. That returns something different than IsUsableItem(item); however, it will still return true if the recipe is already known.

Any suggestions there?

Last edited by zachwlewis : 02-10-13 at 03:25 PM.
  Reply With Quote
02-10-13, 03:31 PM   #4
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Originally Posted by zachwlewis View Post
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.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
02-11-13, 02:41 AM   #5
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
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
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Determining a recipe's "learnability."

Thread Tools
Display Modes

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