Quantcast
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:33
Total downloads:1,105
Favorites:0
MD5:
LibNeed4Research
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
Author
Date
R4
5kB
circonian
01/09/15 10:33 PM


There have been no comments posted to this file.
Be the first to add one.



Category Jump: