WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   GetItemFamily, bitfield (https://www.wowinterface.com/forums/showthread.php?t=49271)

Mazzop 05-08-14 09:15 AM

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)

Phanx 05-08-14 07:18 PM

if bit.band(GetItemFamily(item), 0x0040) > 0 then

Mazzop 05-09-14 03:47 PM

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)

Fizzlemizz 05-09-14 04:41 PM

I just copied and pasted your run statement and got 1.

semlar 05-09-14 04:42 PM

Quote:

Originally Posted by Mazzop (Post 292660)
/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.

Fizzlemizz 05-09-14 04:48 PM

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.

Quote:

Originally Posted by semlar (Post 292663)
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.


semlar 05-09-14 05:00 PM

Quote:

Originally Posted by Fizzlemizz (Post 292664)
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.

Mazzop 05-09-14 05:01 PM

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

Fizzlemizz 05-09-14 05:10 PM

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

Quote:

Originally Posted by Mazzop (Post 292666)
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? :D


Mazzop 05-09-14 05:18 PM

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 05-09-14 05:40 PM

/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.

Quote:

Originally Posted by Mazzop (Post 292669)
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


Mazzop 05-09-14 06:13 PM

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

semlar 05-09-14 06:53 PM

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

Phanx 05-09-14 07:16 PM

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.

Mazzop 05-10-14 01:25 AM

Quote:

Originally Posted by semlar (Post 292673)
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?

Phanx 05-10-14 11:48 AM

Quote:

Originally Posted by Mazzop (Post 292679)
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.

Quote:

Originally Posted by Mazzop (Post 292679)
... 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


Mazzop 05-10-14 12:14 PM

looks great but what if loot is not from body but from chest?

i use GetItemFamily just like in your first anwser :)

thanks all


All times are GMT -6. The time now is 03:27 PM.

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