View Single Post
10-25-11, 06:31 PM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
I wrote a wrapper API to craft an item by the spell ID found in the recipe link. What it does is open the tradeskill briefly, block the actual tradeskill frame from showing, clear all filters, scan for the specific recipe by spell ID, then crafts any number of times. If the tradeskill doesn't exist or it's only to craft once, it automatically closes the tradeskill. If it's to craft multiple times, it'll wait until UPDATE_TRADESKILL_RECAST fires with GetTradeskillRepeatCount() returning 1. This happens even when crafting is interrupted.

Even though count is required to actually craft anything, it'll accept nil to just return whether the player had the recipe or not.

lua Code:
  1. local DoTradeSkillByID; do
  2.     function DoTradeSkillByID(trade,id,count)
  3. --      Prevent the TradeSkill UI from loading
  4.         UIParent:UnregisterEvent("TRADE_SKILL_SHOW");
  5.         UIParent:UnregisterEvent("TRADE_SKILL_CLOSE");
  6.  
  7. --      Trigger TradeSkill open
  8.         CastSpellByID(trade);
  9.  
  10. --      Clear all filters
  11.         SetTradeSkillInvSlotFilter(-1,1,1);
  12.         SetTradeSkillSubClassFilter(-1,1,1);
  13.         SetTradeSkillItemNameFilter("");
  14.         SetTradeSkillItemLevelFilter(0,0);
  15.         TradeSkillOnlyShowMakeable(false);
  16.         TradeSkillOnlyShowSkillUps(false);
  17.  
  18. --      Scan for recipe
  19.         local found,run=false,false;
  20.         for i=1,GetNumTradeSkills() do
  21.             local link=GetTradeSkillRecipeLink(i);
  22.             if link and tonumber(link:match("|Henchant:(%d+)|h"))==id then
  23.                 if count and not IsFlying() then
  24.                     SelectTradeSkill(i);--  This should help read the correct amount of repeats through UPDATE_TRADESKILL_RECAST
  25.                     DoTradeSkill(i,count);
  26.                     run=true;
  27.                 end
  28.                 found=true;
  29.                 break;
  30.             end
  31.         end
  32.  
  33. --      Trigger TradeSkill close
  34.         if not run or not count or count<=1 then CloseTradeSkill(); end
  35.  
  36. --      Restore events
  37.         UIParent:RegisterEvent("TRADE_SKILL_SHOW");
  38.         UIParent:RegisterEvent("TRADE_SKILL_CLOSE");
  39.  
  40.         return found;
  41.     end
  42.  
  43.     local eventframe=CreateFrame()
  44.     eventframe:RegisterEvent("UPDATE_TRADESKILL_RECAST");
  45.     eventframe:SetScript(self,event
  46.         if event=="UPDATE_TRADESKILL_RECAST" and GetTradeskillRepeatCount()<=1 and not (TradeSkillFrame and TradeSkillFrame:IsShown()) then
  47.             CloseTradeSkill();
  48.         end
  49.     );
  50. end
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-25-11 at 06:36 PM.