Thread Tools Display Modes
05-08-14, 09:15 AM   #1
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
GetItemFamily, bitfield

I dont have WoW access atm but got little request to my addon and require help now
I want to find out if given item is used for enchanting or not. I found GetItemFamily but dunno how to work with bitfield, so probably something like
Lua Code:
  1. if (bit.band(GetItemFamily(item), 0x0040) ~= 64) then
dose not have much sense (i found those values here http://wowprogramming.com/docs/api_types#bitfield)
  Reply With Quote
05-08-14, 07:18 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
if bit.band(GetItemFamily(item), 0x0040) > 0 then
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
05-09-14, 03:47 PM   #3
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
i was 2nd hand testing

/run if bit.band(GetItemFamily("Sha Crystal"), 0x0040) > 0 then print("1") else print("0") end

it throws erorr:
Message: [string "if bit.band(GetItemFamily("Sha Crystal"), 0..."]:1: bad argument #1 to 'band' (number expected, got nil)
  Reply With Quote
05-09-14, 04:41 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,875
I just copied and pasted your run statement and got 1.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
05-09-14, 04:42 PM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by Mazzop View Post
/run if bit.band(GetItemFamily("Sha Crystal"), 0x0040) > 0 then print("1") else print("0") end

it throws erorr:
Message: [string "if bit.band(GetItemFamily("Sha Crystal"), 0..."]:1: bad argument #1 to 'band' (number expected, got nil)
Well, GetItemFamily("Sha Crystal") is returning nothing for you, so either you haven't cached information about Sha Crystals yet when you call the function or you can't use an item name like that if you haven't seen it or something.
  Reply With Quote
05-09-14, 04:48 PM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,875
I just re-started the game and logged on to a non enchanter and recieved the error so it seems the function is inteded for items already in your bags.

Originally Posted by semlar View Post
Well, GetItemFamily("Sha Crystal") is returning nothing for you, so either you haven't cached information about Sha Crystals yet when you call the function or you can't use an item name like that if you haven't seen it or something.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
05-09-14, 05:00 PM   #7
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by Fizzlemizz View Post
I just re-started the game and logged on to a non enchanter and recieved the error so it seems the function is inteded for items already in your bags.
You should be able to just call it once to request information about the item from the server then call it again a little later and have it return data, but you might have to use the itemID instead of the name.
  Reply With Quote
05-09-14, 05:01 PM   #8
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
thx all
wonder how it would act when disenchanting something into Sha Crystal (or anything else) without any of tht reagent in bags

its too much to ask for running that script with disenchant loot window open and no crystals in bags?
  Reply With Quote
05-09-14, 05:10 PM   #9
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,875
Sadly it also works if you have the item in your bank or bags.

Why not change it to:

/run local var = GetItemFamily("Sha Crystal"); if var and bit.band(var, 0x0040) > 0 then print("1") else print("0") end

Originally Posted by Mazzop View Post
thx all
wonder how it would act when disenchanting something into Sha Crystal (or anything else) without any of tht reagent in bags

its too much to ask for running that script with disenchant loot window open and no crystals in bags?
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
05-09-14, 05:18 PM   #10
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
but that wont determine if given item is a enchanting material or not
wanted it works for all, but well, i 'hardcode' it with sha crystal ID somehow without use of GetItemFamily
  Reply With Quote
05-09-14, 05:40 PM   #11
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,875
/run if bit.band(GetItemFamily(74248), 0x0040) > 0 then print("1") else print("0") end

Where 74248 is the item id of a Sha Crystal works on a non-enchanter with no crystals.

Originally Posted by Mazzop View Post
but that wont determine if given item is a enchanting material or not
wanted it works for all, but well, i 'hardcode' it with sha crystal ID somehow without use of GetItemFamily
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
05-09-14, 06:13 PM   #12
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
ive just changed

local _, item, quantity, quality = GetLootSlotInfo(i)
if quality >= 4 then

into

local _, item, quantity, quality = GetLootSlotInfo(i)
if item ~= GetItemInfo(74248) and quality >= 4 then

my lil addon will need rewrite in WoD anyway so i think then
  Reply With Quote
05-09-14, 06:53 PM   #13
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
If GetItemInfo works then so does GetitemFamily, they both rely on the item being cached.

If I understand what you're trying to do here, and you only want items that are at least epic quality and aren't considered enchanting materials, then you can try something like this..
Lua Code:
  1. local _, item, quantity, quality = GetLootSlotInfo(i)
  2. if quality >= 4 and bit.band(GetItemFamily(GetLootSlotLink(i) or '') or 0, 0x0040) == 0 then
  Reply With Quote
05-09-14, 07:16 PM   #14
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You should always use itemIDs anyway. Using item names has a number of flaws, such as restricting your addon to only work in English game clients, failing for items you haven't seem during your play session, etc. IDs are better in every way.

If you really need to compare strings against item names, rather than calling GetItemInfo every time, call it once and store the result in a variable outside of whatever function you're comparing in, then use the variable inside that function:
local SHA_CRYSTAL = GetItemInfo(74248)
Or use GetLootSlotLink instead of GetLootSlotInfo and extract the itemID from the link:
local link = GetLootSlotLink(i)
local id = link and tonumber(strmatch(link, "item:(%d+)"))
However, without knowing your actual goals (eg. why you want to know whether an item is used for enchanting, and what you want to do with that knowledge), it's hard to really offer any specific useful suggestions.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
05-10-14, 01:25 AM   #15
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
Originally Posted by semlar View Post
If GetItemInfo works then so does GetitemFamily, they both rely on the item being cached.
o cool, i was not sure if it need to be item cached or item already somewhere in bags situation


Phanx -> but i get item name from game, so its should be localized? Example was just for testing.
Figuring out if its enchanting material or not seemed more elegant then putting all those ID's and then update it with every WoW tier.

http://www.wowinterface.com/download...Announcer.html
its that addon (announces in raid chat numbered list of dropped items from boss, but can fire also on disenchanting loot window) i am talking about and got recently request to exclude disenchant info (can produce unnecessary spam and atm it is most likely Sha Crystals)

So i guess i can use GetItemFamily for my needs - item being checked will be in loot window and should be cached then?
Or maybe GetLootSourceInfo will produce something that will allows me to exclude disenchant in first place?
  Reply With Quote
05-10-14, 11:48 AM   #16
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Mazzop View Post
Phanx -> but i get item name from game, so its should be localized?
As long as you're getting it from GetItemInfo, it's fine. Just don't actually write "Sha Crystal" in your code.

Originally Posted by Mazzop View Post
... numbered list of dropped items from boss, but can fire also on disenchanting loot window ... Or maybe GetLootSourceInfo will produce something that will allows me to exclude disenchant in first place?
If you only want to list items dropped by a boss, I'd just use GetLootSourceInfo -- disenchanting products aren't looted from a unit, so they won't have a source GUID. This is simpler and more efficient anyway:

Code:
-- LOOT_OPENED
for i = 1, GetNumLootItems() do
     if GetLootSourceInfo(i) then
          -- this item was dropped by a unit, proceed with other checks
     end
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
05-10-14, 12:14 PM   #17
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
looks great but what if loot is not from body but from chest?

i use GetItemFamily just like in your first anwser

thanks all

Last edited by Mazzop : 05-10-14 at 12:42 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » GetItemFamily, bitfield

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