Thread Tools Display Modes
09/14/14, 12:17 PM   #1
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
Question Item Equip Event

Hello,

is there a way to catch the "Item equipped" event? I would like to make a custom addon on retrieve some item information when I equip or use an item in my inventory.

thanks in advance!
  Reply With Quote
09/14/14, 12:51 PM   #2
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
You can use a few different way how to detect change in equiped items. First is event EVENT_INVENTORY_SINGLE_SLOT_UPDATE, second is registering for callback "WornSlotUpdate" - CALLBACK_MANAGER:RegisterCallback("WornSlotUpdate", function(slotControl) end), third is hooking EquipItem(...) function and maybe you can find some other ways.

I'd try to use event first:
Lua Code:
  1. local function OnSlotUpdate(eventCode, bagId, slotId, isNewItem, itemSoundCategory, updateReason)
  2.     if bagId == BAG_WORN and updateReason == INVENTORY_UPDATE_REASON_DEFAULT then
  3.         d("Equipped item changed.")
  4.     end
  5. end
  6. EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_INVENTORY_SINGLE_SLOT_UPDATE, OnSlotUpdate)
I'm not really sure if the code above will work, I have typed it off the top of my head. What I'm not sure about is if this will be enough or if you will have to store item instance IDs first - GetItemInstanceId(bagId, slotIndex) - and then compare if the item was actually changed.

If you want to use callback, it will look like this:
Lua Code:
  1. local slotNames = {
  2.     [EQUIP_SLOT_HEAD] = "Head",
  3.     [EQUIP_SLOT_NECK] = "Neck",
  4.     [EQUIP_SLOT_CHEST]= "Chest",
  5.     [EQUIP_SLOT_SHOULDERS] = "Shoulders",
  6.     [EQUIP_SLOT_MAIN_HAND] = "Main Hand",
  7.     [EQUIP_SLOT_OFF_HAND] = "Off Hand",
  8.     [EQUIP_SLOT_WAIST] = "Waist",
  9.     [EQUIP_SLOT_LEGS] = "Legs",
  10.     [EQUIP_SLOT_FEET]= "Feet",
  11.     [EQUIP_SLOT_COSTUME] = "Costume",
  12.     [EQUIP_SLOT_RING1] = "Ring 1",
  13.     [EQUIP_SLOT_RING2] = "Ring 2",
  14.     [EQUIP_SLOT_HAND] = "Gloves",
  15.     [EQUIP_SLOT_BACKUP_MAIN] = "Backup Main Hand",
  16.     [EQUIP_SLOT_BACKUP_OFF] = "Backup Off Hand",
  17. }
  18.  
  19.  
  20. local function WornSlotUpdate(slotControl)
  21.     d("Equip slot changed: " .. slotNames[slotControl.slotIndex])
  22. end
  23.  
  24. CALLBACK_MANAGER:RegisterCallback("WornSlotUpdate", WornSlotUpdate)

Last edited by Garkin : 09/17/14 at 08:33 PM. Reason: added missing eventCode argument to the code
  Reply With Quote
09/15/14, 05:16 PM   #3
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
Great thanks for the information, I really appreciate it. Once i have a chance to try this out, I will let you know how it goes!
  Reply With Quote
09/16/14, 04:36 AM   #4
Deome
 
Deome's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 29
Thumbs up

I've been pouring through the API all weekend, and I broke a promise to myself and dove headfirst into the tooltips and callbacks. I'll try to remember to post a short blurb on how to catch and hook any event--it's so stunningly easy.

Will also be releasing a tooltip modification library, a la LibAddonMenu, only for tooltips

@Garkin So easy I was able to get rid of dd.Focus and wrap all the prehooks into one function!
  Reply With Quote
09/17/14, 08:21 PM   #5
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
Update!!

I was able to get the event hooked up with the following args (looks like there was an "eventCode" arg as the first param)

local function OnSlotUpdate (eventCode, bagId, slotId, isNewItem, itemSoundCategory, updateReason)


Is it possible to "catch" this event and cancel it to prevent an item to be equipped? I'm a developer so i'm familiar with doing this in other languages, i'm just struggling to find alot of docs on Lua and ESO.

I really appreciate the help.
  Reply With Quote
09/17/14, 08:46 PM   #6
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by skobyjay View Post
I was able to get the event hooked up with the following args (looks like there was an "eventCode" arg as the first param)

local function OnSlotUpdate (eventCode, bagId, slotId, isNewItem, itemSoundCategory, updateReason)


Is it possible to "catch" this event and cancel it to prevent an item to be equipped? I'm a developer so i'm familiar with doing this in other languages, i'm just struggling to find alot of docs on Lua and ESO.

I really appreciate the help.
EVENT_INVENTORY_SINGLE_SLOT_UPDATE is fired after item is equipped. In this case you will probably need to hook EquipItem function.

Lua Code:
  1. local doNotWork = true
  2. ZO_PreHook("EquipItem", function(...) return doNotWork end)

ZO_PreHook([objectTable,] originalFunctionName, yourFunction) allows you to run your function before the actual function is called. Original function is called only if your function returns nil or false.
  Reply With Quote
09/22/14, 03:37 PM   #7
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
Awesome thanks for the info, sorry for the late response. I have been playing too much to work on this :-) I'll give this a try. Is there a place other than the wiki I can reference?
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Item Equip Event

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