Quantcast How to get the recipeID from a cast - WoWInterface
Thread Tools Display Modes
07-16-17, 03:45 AM   #1
Splynx
A Deviate Faerie Dragon
 
Splynx's Avatar
Join Date: Jul 2017
Posts: 10
How to get the recipeID from a cast

Hello all.

I am in a situation where I have made a listener for when the user starts casting, and the different variations of when a cast is stopped.

From this I can now identify when a cast or a batch of casts that would create an item

Code:
local castName, _, _, _, _, _, isTradeSkill, _, _ = UnitCastingInfo("player");
Is it at all possible for me to somehow get the ID of the recipe that is used for this cast/craft from this position?

If I can get that then I get a hold of a lot more data that I need via

Code:
C_TradeSkillUI
I would very much appreciate some help since I have been stuck on this for a few days.

This is my VERY VERY FIRST lua program at all - have never tried this before - but I am a programmer in my work life.

I have a TS server we can talk on if anyone would like to help me out - and I have also created a GIT repo with my code for you to view.

Not sharing the GIT or idea of my addon since I spent a LONG time finding a good addon to make that would provide value, and I don't want someone to steal it
  Reply With Quote
07-16-17, 03:48 AM   #2
Splynx
A Deviate Faerie Dragon
 
Splynx's Avatar
Join Date: Jul 2017
Posts: 10
Just a note in case this will be the answer.

No I do not wish to listen for click's on a recipe and get it that way, a craft can begin in other ways than this.
  Reply With Quote
07-16-17, 04:35 AM   #3
Splynx
A Deviate Faerie Dragon
 
Splynx's Avatar
Join Date: Jul 2017
Posts: 10
Just to clarify more.

Since this seems near on impossible (from what I have tried to find out, I am here hoping someone tells me it is easy) to get this done I have toyed with other ideas.

Like on first cast start take a snapshot of the inventory - then on last cast end take a new snapshot of the inventory and hold them up against each other.

This would in theory give me the item and number of items created - but there are some uncertainties with this way as some craft has a higher yield than 1 pr cast to begin with.

I could probably also do a regex of the cast name since there is a pattern to it "<type>: <item name>" - but this pattern MAY not be complete (I have not seen all recepies) and may at some time become broken.

All in all - I need that recipeID somehow - and hope I can get help.
  Reply With Quote
07-16-17, 05:04 AM   #4
Ketho
A Molten Giant
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 846
Originally Posted by Splynx View Post
No I do not wish to listen for click's on a recipe and get it that way, a craft can begin in other ways than this.

Why not just hook C_TradeSkillUI.CraftRecipe this will track any craft start
Lua Code:
  1. hooksecurefunc(C_TradeSkillUI, "CraftRecipe", function(recipeID, amount)
  2.     print(recipeID, amount)
  3. end)
  Reply With Quote
07-16-17, 05:30 AM   #5
Splynx
A Deviate Faerie Dragon
 
Splynx's Avatar
Join Date: Jul 2017
Posts: 10
Nice!

That is amazing - and knowing this exists actually changes a lot of my code

I did get around to finding a solution, and was about to post here - so for the sake of that..

Code:
function addon:GetTradeSkillFromCastName(name)
  local recipeIDs = C_TradeSkillUI.GetAllRecipeIDs();
  local tradeSkill = nil;

  for id = 1, #recipeIDs do
    local recipe = C_TradeSkillUI.GetRecipeInfo(recipeIDs[id]);
    if recipe.name == name then
      tradeSkill = recipe;
      break;
    end
  end

  return tradeSkill;
end

I felt I could be somewhat 100% certain that the cast name and the recipe name would always match.

But your solution is the clean way, and bypasses like some 500 iterations (if you are unlucky and it is last)

Last edited by Splynx : 07-16-17 at 05:33 AM.
  Reply With Quote
07-16-17, 05:37 AM   #6
Splynx
A Deviate Faerie Dragon
 
Splynx's Avatar
Join Date: Jul 2017
Posts: 10
And thank you very very much - my main problem so far is finding out what is available for me.

I have only been at it for 2 days with LUA and WoW Addon programming - so really a n00b, only found out how to debug properly and how to dump variables today
  Reply With Quote
07-16-17, 01:37 PM   #7
Kanegasi
A Cobalt Mageweaver
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 225
Hooking functions is a staple part of doing something in response to something that doesn't have a direct or reliable event or the event doesn't pass the data you want, especially if you're going off what another addon is doing.

To explain what Ketho used, there are three ways to hook something:

Code:
hooksecurefunc("GlobalFunction",yourFunction) -- used if the function is in _G by itself, like GetItemInfo()

hooksecurefunc(table,"FuncInTable",yourFunction) -- what Ketho used, this is for functions inside a global table, like C_TradeSkillUI or frame functions like RegisterEvent or SetPoint

frame:HookScript("OnWhatever",yourFunction) -- used to hook action scripts for frames, like OnHide, OnShow, OnEnter, etc.
All three pass the exact arguments the original functions used, so if you used the first one on GetItemInfo(), the first argument in yourFunction will be the item name, item ID, or item link that was just given to GetItemInfo().
  Reply With Quote
07-17-17, 04:41 AM   #8
Splynx
A Deviate Faerie Dragon
 
Splynx's Avatar
Join Date: Jul 2017
Posts: 10
Thank you very much - I will need to go over my script again and give it a clean up I can tell.

The source code can be found here - again pointers are very much welcome

https://github.com/IgorSzyporyn/ProcRateInformer
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » How to get the recipeID from a cast

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