WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Get gear item level question? (https://www.wowinterface.com/forums/showthread.php?t=59827)

Codger 03-18-24 08:59 AM

Get gear item level question?
 
I'm working on an addon and I want to report the gear item level but I'm having trouble with
lua errors when I attempt it.

Here's what I'm doing:

local slotID = GetInventorySlotInfo(Headslot)
--this works, returning a 1

local ilvl = C_Item.GetCurrentItemLevel(slotID)
--This fails (*temporary) = "bad argument #1 to '?' (Usage: local currentItemLevel = C_Item.GetCurrentItemLevel(itemLocation))"

I obviously don't have the correct itemLocation but not sure how to find that.
I'm currently attempting to get the gear level when I open the mailbox but I could change this
to use the character screen, just not sure what event triggers when I open it.

I think I have a solution now. Here is what I'm doing...oops not quite - numbers don't match character screen??
Lua Code:
  1. local function getGearItemLvl(slotName)
  2.     print("getGearItemLvl("..slotName..")")
  3.     local slotId, texture, checkRelic = GetInventorySlotInfo(slotName)
  4.     local itemId = GetInventoryItemID("player", slotId)    
  5.     if (itemId ~= nil) then
  6.         local name, _, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemId)
  7.         print("getGearItemLvl("..slotName.." is "..iLevel..")")
  8.     end
  9. end

Fizzlemizz 03-18-24 10:29 AM

C_Item.GetCurrentItemLevel requires an ItemLocationMixin not slotID
Lua Code:
  1. local slotID = GetInventorySlotInfo(Headslot)
  2. local itemLocation = ItemLocation:CreateFromEquipmentSlot(slotID)
  3. local lvl = C_Item.GetCurrentItemLevel(itemLocation)

Xrystal 03-18-24 10:52 AM

Oh, thanks for reminding me of that change. I haven't updated my item level addon in ages as I forgot that was added a while back.

Nevermind, I already updated to Dragonflight with no issues. Either I didn't need to use that function or I added it. But it did remind me of something I was envisioning adding to it at some point.

Fizzlemizz 03-18-24 10:56 AM

You never know what 11 may bring to the table ;)

Codger 03-18-24 11:56 AM

Working but clunky
 
Thank you for the help.
It's working now... had a bit of trouble with empty slots and used a clunky workaround by looking at the texture. I'm sure there must be a better way to detect an empty slot but haven't found it yet.
Here's what I have now...

Lua Code:
  1. local function getGearItemLvl(slotName)
  2.     local lvl = 0
  3.     local slotID, texture, checkRelic = GetInventorySlotInfo(slotName)
  4.     if (slotID ~= nil) then
  5.         if (texture ~= 136525) then
  6.             local itemLocation = ItemLocation:CreateFromEquipmentSlot(slotID)
  7.             if (itemLocation ~= nil) then
  8.                 lvl = C_Item.GetCurrentItemLevel(itemLocation)
  9.             end
  10.         end    
  11.     end
  12.     --print("getGearItemLvl("..slotName..") " .. "  slotID: " .. slotID .. "  itemlevel: " .. lvl)
  13.     return format("%s", lvl)
  14. end

Fizzlemizz 03-18-24 12:06 PM

C_Item.DoesItemExist
Lua Code:
  1. local slotID = GetInventorySlotInfo(Headslot)
  2. local itemLocation = ItemLocation:CreateFromEquipmentSlot(slotID)
  3. if C_Item.DoesItemExist(itemLocation) then
  4.     local lvl = C_Item.GetCurrentItemLevel(itemLocation)
  5.     -- ...
  6. end

Codger 03-18-24 12:42 PM

Working great now
 
Thank you for your help!!
It's working the way I want now.

Lua Code:
  1. local function getGearItemLvl(slotName)
  2.     local lvl = 0
  3.     if (slotName ~= nil) then
  4.         local slotID, texture, checkRelic = GetInventorySlotInfo(slotName)
  5.         --print("getGearItemLvl    " .. slotID .. "     " .. texture .. "     " .. tostring(checkRelic))
  6.         if (slotID ~= nil) then
  7.             local itemLocation = ItemLocation:CreateFromEquipmentSlot(slotID)
  8.             if C_Item.DoesItemExist(itemLocation) then
  9.                 lvl = C_Item.GetCurrentItemLevel(itemLocation)
  10.             end
  11.         end
  12.     end
  13.     --print("getGearItemLvl("..slotName..") " .. "  slotID: " .. slotID .. "  itemlevel: " .. lvl)
  14.     return format("%s", lvl)
  15. end

For anyone that needs this the slotName is one of "HeadSlot", "NeckSlot", "ShoulderSlot", "BackSlot"...

Fizzlemizz 03-18-24 01:00 PM

Quote:

Originally Posted by Codger (Post 343569)
For anyone that needs this the slotName is one of "HeadSlot", "NeckSlot", "ShoulderSlot", "BackSlot"...

For completeness: List of Slot IDs


All times are GMT -6. The time now is 05:32 PM.

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