C_TradeSkillUI.CraftRecipe always returning numCasts = 1

I’m getting 1 back regardless of the quantity I’m crafting. (Tested with Cooking and Tailoring)

hooksecurefunc(C_TradeSkillUI, 'CraftRecipe', function(_, num)
	print("CraftRecipe",num)
end);

Same thing with CraftEnchant

hooksecurefunc(C_TradeSkillUI, 'CraftEnchant', function(_, num)
	print('CraftEnchant',num)
end);

By contrast, CraftSalvage is returning the correct number. (Tested with JC)

hooksecurefunc(C_TradeSkillUI, 'CraftSalvage', function(_, num)
	print('CraftSalvage',num)
end);

Am I doing something wrong or is the API just a mess?

TLDR (my post is a tldr of the code, not I didn’t read your post),

There’s a whole bunch of code wrapping it up but essentially Blizzard is iterating the number of items to craft, doing some stuff and calling the function each time passing a count of 1.

So is there another function that would give me the total recipes/enchants being crafted?

I can take a look a bit later but my initial thought would be to grab it at the starting point rather than the end call. But that might depend on what you’re using it for.

Combined cast bar in Gnosis.
Gnosis.lua:449

function Gnosis:SetupHooks()
	if (wowmainline) then
		-- tradeskill hooking
		hooksecurefunc(C_TradeSkillUI, 'CraftRecipe', function(index, num)
				Gnosis.bNewTradeSkill = tonumber(num) and true or nil;
				Gnosis.iLastTradeSkillCnt = tonumber(num);
			end
		);

		hooksecurefunc(C_TradeSkillUI, 'CraftSalvage', function(index, num)
				Gnosis.bNewTradeSkill = tonumber(num) and true or nil;
				Gnosis.iLastTradeSkillCnt = tonumber(num);
			end
		);

		hooksecurefunc(C_TradeSkillUI, 'CraftEnchant', function(index, num)
				Gnosis.bNewTradeSkill = tonumber(num) and true or nil;
				Gnosis.iLastTradeSkillCnt = tonumber(num);
			end
		);

		hooksecurefunc(C_TradeSkillUI, 'CloseTradeSkill', function()
				Gnosis.bNewTradeSkill = nil;
				Gnosis.iLastTradeSkillCnt = nil;
				Gnosis:CloseAllTradeskillBars();
			end
		);

Bars.lua:2107

	-- tradeskill stuff
	local bDoResize = true;
	local bnTS = true;
	if (cfg.unit == "player" and cfg.bMergeTrade) then
		if (isTradeSkill) then
			bnTS = false;
			cb.tscnt = self.iLastTradeSkillCnt and self.iLastTradeSkillCnt or 1;

Then it’s basically checking if cb.tscnt > 1 to create a combined cast bar with the full craft duration rather than creating a bar on each cast.

It’s checking cb.tscnt is not nil and if it is, setting the value to 1.

Maybe try:

hooksecurefunc(ProfessionsFrame.CraftingPage, "CreateInternal", function(recipeID, count, recipeLevel)
	print("Create Count", recipeID, count, recipeLevel)
end)

1 Like

That did it, thanks!

For anyone else trying to use this, there’s actually some table it passes as the first arg

hooksecurefunc(ProfessionsFrame.CraftingPage, "CreateInternal", function(_, recipeID, count, recipeLevel)
	print("Create Count", recipeID, count, recipeLevel)
end)

Oops, that would be self and in this case, self is ProfessionsFrame.CraftingPage

C_TradeSkillUI.CraftRecipe is actually called in two places and that code is only for one of them.

I tested CreateInternal with all 3 varieties of batch crafting and it seemed to work :slight_smile:

The other is to do with previewing orders but I didn’t go any futher than that.

Glad it works :slight_smile:,

Whelp, Blizz changed something in 10.1.5

attempt to index global 'ProfessionsFrame' (a nil value)

It’s still there. The addon is LOD so maybe it’s just not being loaded as soon as it used to be.

Yeah, I’m just not sure how to wait for it before hooking into it.

Open the profession window or forced a load

ProfessionsFrame_LoadUI()
1 Like