Thread Tools Display Modes
05-18-13, 04:28 AM   #1
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
LUA function for getting item enchants

Is there a way in the API to check the enchants on an item that I currently have equipped? I've been unable to find one so far...
  Reply With Quote
05-18-13, 04:50 AM   #2
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
To check for an enchant, you need to parse the itemstring.

You can get an itemlink for a slot in your inventory with GetInventoryItemLink:
lua Code:
  1. local slotId = GetInventorySlotInfo("ChestSlot")
  2. local link = GetInventoryItemLink("player", slotId)
  3. local itemId, enchantId, gem1, gem2, gem3, gem4 = link:match("item:(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)")
Tekkub's Bimbo is an excellent example of how you can detect enchants/gems.
  Reply With Quote
05-18-13, 05:07 AM   #3
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
Ooh, I didn't know you could get that sort of info out of an item link... thanks

[edit]
I can't find anything about what these enchant/ gem numbers mean though, including in Bimbo... they aren't spell IDs nor item IDs.

Last edited by Malsomnus : 05-18-13 at 06:35 AM.
  Reply With Quote
05-18-13, 06:53 AM   #4
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
Well, there's this page: http://www.wowpedia.org/EnchantId

It doesn't look very updated. Not sure what the best practice is for dealing with enchantIds.
  Reply With Quote
08-29-13, 06:51 AM   #5
Taraezor
A Fallenroot Satyr
 
Taraezor's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2012
Posts: 21
Forgive the Necro but this thread shows up in searches and I don't want people to get the wring idea: The above discussion does NOT apply to the buffs Shaman put on their weapon.

Aside from parsing Tooltips and/or monitoring logs to see when Windfury etc were applied, there is no way of knowing the enchant put on a Shaman's weapon.

In the case of Shaman's, you will get a 0 (zero) in the colon separated string list.
  Reply With Quote
08-29-13, 08:09 AM   #6
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
Well, if this thread has already been resurrected...
I eventually solved the problem by creating an item link for a stat-less item with the given enchant ID and parsing its tooltip, and would like to thank the author of this add-on for the idea (and most of the implementation).

As for shamans, I used GetWeaponEnchantInfo to see if a weapon enchant exists, but this indeed does not tell me what the enchant is.
__________________
SanityCheck - If you've ever said the words "Sorry, I forgot" then you need this add-on.

Remember, every time you post a comment on an add-on, a kitten gets its wings!
  Reply With Quote
08-29-13, 08:11 AM   #7
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Taraezor View Post
Forgive the Necro but this thread shows up in searches and I don't want people to get the wring idea: The above discussion does NOT apply to the buffs Shaman put on their weapon.

Aside from parsing Tooltips and/or monitoring logs to see when Windfury etc were applied, there is no way of knowing the enchant put on a Shaman's weapon.

In the case of Shaman's, you will get a 0 (zero) in the colon separated string list.
What about this: http://wowprogramming.com/docs/api/GetWeaponEnchantInfo ?
  Reply With Quote
08-29-13, 05:48 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by suicidalkatt View Post
As both the post directly before yours and the linked page itself point out, that function does not tell you which temporary enchant is on the weapon. The only way to determine which temporary enchant is on the weapon is to scan its tooltip and use localized string matching. If anyone is trying to do this, feel free to copy the code from PhanxBuffs; it detects all temp enchants currently in the game, and maps them to the spell that applies them.
__________________
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
08-30-13, 02:59 AM   #9
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
I think the best method is if you really want to find all enchants for weapons is that you scan the mainhand/offhand weapons tooltip with the enchant id's localized name.
  Reply With Quote
08-30-13, 03:10 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
... that's what I just said?
__________________
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
08-30-13, 05:49 PM   #11
humfras
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 131
Originally Posted by Phanx View Post
... that's what I just said?
No. But that's what you just wrote!
__________________
Author of VuhDo CursorCastBar OptiTaunt Poisoner RaidMobMarker
  Reply With Quote
02-17-16, 09:00 AM   #12
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Since 6.0 you can get the temporary enchant ids from GetWeaponEnchantInfo():

Lua Code:
  1. local hasMainHandEnchant, mainHandExpiration, mainHandCharges, mainHandEnchantID, hasOffHandEnchant, offHandExpiration, offHandCharges, offHandEnchantId = GetWeaponEnchantInfo()

The issue now, is that you don't know the duration of the enchants.

But you can filter the fishing lure enchants or fall back to 3600 like this:

Lua Code:
  1. local tempEnchantID = {
  2.     [256] = 600, -- (+75)
  3.     [263] = 600, -- (+25)
  4.     [264] = 600, -- (+50)
  5.     [265] = 600, -- (+75)
  6.     [266] = 600, -- (+100)
  7.     [3868] = 3600, -- (+100)
  8.     [4225] = 900, -- (+150)
  9.     [4264] = 600, -- (+15)
  10.     [4919] = 600, -- (+150)
  11.     [5386] = 600, -- (+200)
  12. }
  13.  
  14. local hasMainHandEnchant, mainHandExpiration, mainHandCharges, mainHandEnchantID, hasOffHandEnchant, offHandExpiration, offHandCharges, offHandEnchantId = GetWeaponEnchantInfo()
  15. local duration = tempEnchantID[mainHandEnchantID] or 3600
  16. frame.cooldown:SetCooldown(GetTime() + ((mainHandExpiration / 1000) - duration), duration)

Last edited by Resike : 02-17-16 at 09:18 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » LUA function for getting item enchants

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