Download
(5 Kb)
Download
Updated: 01/19/15 06:13 PM
Compatibility:
Update 7 (1.7.0)
Updated:01/19/15 06:13 PM
Created:01/09/15 10:33 PM
Monthly downloads:20
Total downloads:15,023
Favorites:2
MD5:
LibNeed4Research  Popular! (More than 5000 hits)
Version: R5
by: circonian, prasoc
Does your addon depend on another addon to determine if an item is needed by a character for research?
Do you wish you could add features that require knowing if an item is needed for research by ANY character, but don't know how or don't want to write the code to do it?

LibNeed4Research...Now you don't have to.

What does it do?
LibNeed4Research is a library that keeps track of which traits/recipes each character knows that you can query to see if a specific item/recipe is needed for research by any character on the account (provided they've logged in at least once so the library can gather the necessary information).


Available Functions
Used to determine if a specific character needs the trait on an item for research.
Takes a character name, bagId (or link to item), and slotId (must be nil if passing in an item link).
Lua Code:
  1. -- Trait Function:
  2. function ln4r:DoesPlayerNeedTrait(_sPlayerName, _iBagIdOrLink, _iSlotId)
  3. -- Returns: return true, iCraftingSkillType, iResearchLineIndex, iTraitIndex
  4. -- or false

Used to determine ALL characters that need the trait on an item for research.
Takes a bagId (or link to item), and slotId (must be nil if passing in an item link).
Lua Code:
  1. -- Trait Function:
  2. function ln4r:DoAnyPlayersNeedTrait(_iBagIdOrLink, _iSlotId)
  3. --[[ Returns nil if no characters need the trait for research
  4. or the following table:
  5.     local tPlayersThatNeed = {
  6.         CraftingSkillType   = iCraftingSkillType,
  7.         ResearchLineIndex   = iResearchLineIndex,
  8.         TraitIndex          = iTraitIndex,
  9.         PlayerCount         = 0,
  10.         PlayerNames         = {},
  11.         PlayerNeeds         = false,
  12.         OtherNeeds          = false,
  13.     }
  14. -- PlayerCount is the number of players that need the item for research
  15. -- PlayerNames is a table containing the name of every player that needs the item for research
  16. -- PlayerNeeds & OtherNeeds is a boolean that allows you to quickly determine if the current player needs the item and/or if other characters need the item.
  17. --***************************************************************************--
  18. -- NOTE: The player name is stored as the KEY in the PlayerNames table,
  19. -- the corresponding VALUE is always true. This way you do not need to loop through the
  20. -- table to determine if any specific character is in the PlayerNames table. You can just check
  21. -- to see if: PlayerNames["MyCharsName"] == true
  22. --***************************************************************************--
  23. --]]

Used to determine if a specific character needs the recipe for research.
Takes a character name, bagId (or link to item), and slotId (must be nil if passing in an item link).
Lua Code:
  1. -- Recipe Function:
  2. function ln4r:DoesPlayerNeedRecipe(_sPlayerName, _iBagIdOrLink, _iSlotId)
  3. -- Returns: true or false (if the character needs the recipe or not)

Used to determine ALL characters that need the recipe for research.
Takes a bagId (or link to item), and slotId (must be nil if passing in an item link).
Lua Code:
  1. function ln4r:DoAnyPlayersNeedRecipe(_iBagIdOrLink, _iSlotId)
  2. --[[ Returns nil if no characters need the recipe for research
  3. or the following table:
  4.     local tPlayersThatNeed = {
  5.         CraftingSkillType   = CRAFTING_TYPE_PROVISIONING,
  6.         PlayerCount         = 0,
  7.         PlayerNames         = {},
  8.         PlayerNeeds         = false,
  9.         OtherNeeds          = false,
  10.     }
  11. -- PlayerCount is the number of players that need the item for research
  12. -- PlayerNames is a table containing the name of every player that needs the item for research
  13. -- PlayerNeeds & OtherNeeds is a boolean that allows you to quickly determine if the current player needs the item and/or if other characters need the item.
  14. --***************************************************************************--
  15. -- NOTE: The player name is stored as the KEY in the PlayerNames table,
  16. -- the corresponding VALUE is always true. This way you do not need to loop through the
  17. -- table to determine if any specific character is in the PlayerNames table. You can just check
  18. -- to see if: PlayerNames["MyCharsName"] == true
  19. --***************************************************************************--
  20. --]]



How Do I Use It?
Your Addon .txt
To use LibNeed4Research make sure you register libstub & LibNeed4Research in your addons .txt file. The following is an example:
Create a libs folder in your addons folder which will contain the libStub & LibNeed4Research folders. You would then register libstub & LibNeed4Research it in your .txt file like this:
Lua Code:
  1. ## Title: JunkIt
  2. ## APIVersion: 100010
  3. ## OptionalDependsOn: LibAddonMenu-2.0
  4. ## SavedVariables: JunkItSavedVars
  5. ## Version: 2.8
  6. ## Author: Circonian
  7. ## Description: Circonians JunkIt Version 2.8
  8.  
  9. -- Add these --
  10. libs\LibStub\LibStub.lua
  11. libs\LibNeed4Research\LibNeed4Research.lua
  12.  
  13. -- ... Other files your addon uses --


Loading The Library
In order to use LibNeed4Research in your addon you must also load the library. To do so add the following code at the top of any/every code file where you intend to call any LibNeed4Research functions:
Lua Code:
  1. local LN4R = LibStub:GetLibrary("LibNeed4Research")


Examples
Lua Code:
  1. local bDoesPlayerNeed = LN4R:DoesPlayerNeedRecipe("OneL33tDude", 1, 3)
  2.  
  3. local tNeedInfo = LN4R:DoAnyPlayersNeedRecipe(1, 3)
  4.  
  5. local sCurrentPlayerName = GetUnitName("player")
  6. local bDoesPlayerNeed = LN4R:DoesPlayerNeedTrait(sCurrentPlayerName, someItemLink)
  7.  
  8. local tNeedInfo = LN4R:DoAnyPlayersNeedTrait(someItemLink)
Version R5

CRAFTING_TYPE_INVALID Added a check for when EVENT_SMITHING_TRAIT_RESEARCH_STARTED calls AddKnownTrait(..) to make sure the crafting type is not CRAFTING_TYPE_INVALID.
Archived Files (1)
File Name
Version
Size
Uploader
Date
R4
5kB
01/09/15 10:33 PM


Post A Reply Comment Options
Unread 10/15/18, 05:43 PM  
tomtomhotep
 
tomtomhotep's Avatar
AddOn Author - Click to view AddOns

Forum posts: 21
File comments: 217
Uploads: 6
Exclamation Is this Library Abandoned?

Is this Library Abandoned?

If so, authors should stop using it.
Report comment to moderator  
Reply With Quote
Unread 09/23/18, 02:29 PM  
tomtomhotep
 
tomtomhotep's Avatar
AddOn Author - Click to view AddOns

Forum posts: 21
File comments: 217
Uploads: 6
Exclamation LUA Error

user:/AddOns/LibNeed4Research/LibNeed4Research.lua:324: attempt to index a nil value
stack traceback:
user:/AddOns/LibNeed4Research/LibNeed4Research.lua:324: in function 'AddKnownTrait'
<Locals> _EventCode = 131520, _iCraftingSkillType = 7, _iResearchLineIndex = 1, _iTraitIndex = 2, sPlayerName = "K'Temoc" </Locals>
This happened when I started a Jewelry research.


(Since authors no longer bundle Libraries with their add-ons, I'm posting this here.)
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: