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:
local DoTradeSkillByID; do
function DoTradeSkillByID(trade,id,count)
-- Prevent the TradeSkill UI from loading
UIParent:UnregisterEvent("TRADE_SKILL_SHOW");
UIParent:UnregisterEvent("TRADE_SKILL_CLOSE");
-- Trigger TradeSkill open
CastSpellByID(trade);
-- Clear all filters
SetTradeSkillInvSlotFilter(-1,1,1);
SetTradeSkillSubClassFilter(-1,1,1);
SetTradeSkillItemNameFilter("");
SetTradeSkillItemLevelFilter(0,0);
TradeSkillOnlyShowMakeable(false);
TradeSkillOnlyShowSkillUps(false);
-- Scan for recipe
local found,run=false,false;
for i=1,GetNumTradeSkills() do
local link=GetTradeSkillRecipeLink(i);
if link and tonumber(link:match("|Henchant:(%d+)|h"))==id then
if count and not IsFlying() then
SelectTradeSkill(i);-- This should help read the correct amount of repeats through UPDATE_TRADESKILL_RECAST
DoTradeSkill(i,count);
run=true;
end
found=true;
break;
end
end
-- Trigger TradeSkill close
if not run or not count or count<=1 then CloseTradeSkill(); end
-- Restore events
UIParent:RegisterEvent("TRADE_SKILL_SHOW");
UIParent:RegisterEvent("TRADE_SKILL_CLOSE");
return found;
end
local eventframe=CreateFrame()
eventframe:RegisterEvent("UPDATE_TRADESKILL_RECAST");
eventframe:SetScript(self,event
if event=="UPDATE_TRADESKILL_RECAST" and GetTradeskillRepeatCount()<=1 and not (TradeSkillFrame and TradeSkillFrame:IsShown()) then
CloseTradeSkill();
end
);
end