Thread Tools Display Modes
04-04-09, 08:16 PM   #1
Aezay
A Theradrim Guardian
 
Aezay's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 66
LibWeaponEnchant

If you have ever tried obtaining the temporary weapon enchant data in WoW, you will know how horrible this API is, no events or a way to get the enchant name in a proper way. This means you are forced to resort to some OnUpdate script polling GetWeaponEnchantInfo(). You are also forced set a tooltip to your weapons and scan them to get the name of the enchant.

There is a way to bypass the need to use an OnUpdate script to check for changes. Basically, enchanting a weapon will trigger the UNIT_INVENTORY_CHANGED event, during this event, the weapon enchant data from GetWeaponEnchantInfo() still hasn't been updated, but they will be right after the event. So you can use this event to start a timer that will check the enchants in a little while, I use 0.4 sec in this library.

The library will also keep track of the duration of the weapon enchant, not just the time left on it. All you have to do to use it, is to register a callback like this. The first parameter does not have to be a frame, but it should be unique in some way. Also, it has no dependencies.
Code:
local f = CreateFrame("Frame");
function f:UpdateEnchantsFunc(mhSlot,mhEnchant,mhDuration,mhEndTime,ohSlot,ohEnchant,ohDuration,ohEndTime)
	-- Update code here
end
LibWeaponEnchant.RegisterCallback(f,f.UpdateEnchantsFunc);
Currently I'm using this library in two plugins for AzCastBar, Auras and Shaman Timers.

I've never seen anyone using this method before, so I thought it might be useful to share. You can download the library here:

LibWeaponEnchant.lua
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » LibWeaponEnchant


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