WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   How to get the recipeID from a cast (https://www.wowinterface.com/forums/showthread.php?t=55570)

Splynx 07-16-17 03:45 AM

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 :D

Splynx 07-16-17 03:48 AM

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.

Splynx 07-16-17 04:35 AM

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.

Ketho 07-16-17 05:04 AM

Quote:

Originally Posted by Splynx (Post 324193)
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)

Splynx 07-16-17 05:30 AM

Nice!

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

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)

Splynx 07-16-17 05:37 AM

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 :D

Kanegasi 07-16-17 01:37 PM

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().

Splynx 07-17-17 04:41 AM

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


All times are GMT -6. The time now is 09:40 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI