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:
-- Trait Function:
function ln4r:DoesPlayerNeedTrait(_sPlayerName, _iBagIdOrLink, _iSlotId)
-- Returns: return true, iCraftingSkillType, iResearchLineIndex, iTraitIndex
-- 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:
-- Trait Function:
function ln4r:DoAnyPlayersNeedTrait(_iBagIdOrLink, _iSlotId)
--[[ Returns nil if no characters need the trait for research
or the following table:
local tPlayersThatNeed = {
CraftingSkillType = iCraftingSkillType,
ResearchLineIndex = iResearchLineIndex,
TraitIndex = iTraitIndex,
PlayerCount = 0,
PlayerNames = {},
PlayerNeeds = false,
OtherNeeds = false,
}
-- PlayerCount is the number of players that need the item for research
-- PlayerNames is a table containing the name of every player that needs the item for research
-- 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.
--***************************************************************************--
-- NOTE: The player name is stored as the KEY in the PlayerNames table,
-- the corresponding VALUE is always true. This way you do not need to loop through the
-- table to determine if any specific character is in the PlayerNames table. You can just check
-- to see if: PlayerNames["MyCharsName"] == true
--***************************************************************************--
--]]
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:
-- Recipe Function:
function ln4r:DoesPlayerNeedRecipe(_sPlayerName, _iBagIdOrLink, _iSlotId)
-- 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:
function ln4r:DoAnyPlayersNeedRecipe(_iBagIdOrLink, _iSlotId)
--[[ Returns nil if no characters need the recipe for research
or the following table:
local tPlayersThatNeed = {
CraftingSkillType = CRAFTING_TYPE_PROVISIONING,
PlayerCount = 0,
PlayerNames = {},
PlayerNeeds = false,
OtherNeeds = false,
}
-- PlayerCount is the number of players that need the item for research
-- PlayerNames is a table containing the name of every player that needs the item for research
-- 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.
--***************************************************************************--
-- NOTE: The player name is stored as the KEY in the PlayerNames table,
-- the corresponding VALUE is always true. This way you do not need to loop through the
-- table to determine if any specific character is in the PlayerNames table. You can just check
-- to see if: PlayerNames["MyCharsName"] == true
--***************************************************************************--
--]]
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:
## Title: JunkIt
## APIVersion: 100010
## OptionalDependsOn: LibAddonMenu-2.0
## SavedVariables: JunkItSavedVars
## Version: 2.8
## Author: Circonian
## Description: Circonians JunkIt Version 2.8
-- Add these --
libs\LibStub\LibStub.lua
libs\LibNeed4Research\LibNeed4Research.lua
-- ... 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:
local LN4R = LibStub:GetLibrary("LibNeed4Research")
Examples
Lua Code:
local bDoesPlayerNeed = LN4R:DoesPlayerNeedRecipe("OneL33tDude", 1, 3)
local tNeedInfo = LN4R:DoAnyPlayersNeedRecipe(1, 3)
local sCurrentPlayerName = GetUnitName("player")
local bDoesPlayerNeed = LN4R:DoesPlayerNeedTrait(sCurrentPlayerName, someItemLink)
local tNeedInfo = LN4R:DoAnyPlayersNeedTrait(someItemLink)