Thread Tools Display Modes
11/01/15, 02:33 PM   #1
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
v2.2 Easiest way to react on changed equippment items?

Hey there,

With update 2.2 the function "PlayOnEquippedAnimation" will be removed.
This one helped me a lot to update the marker textures at equipment slots, when the equipment got changed in the past :-(

So what is the easiest way with the next update 2.2 to react on equipped/unequipped items?
I need some event or PreHook callback function to run as any item gets
-equipped
-unequipped

I know there are the functions EquipItem and UnequipItem, but they won't give me all the info I need.
I need either the control name of the character control where the item get's equipped/got unequipped, or I need the slotIndex where it gets equipped/got unequipped.

And I need this to be executed as I use
-drag&drop
-double click
-right-click/context menu -> "Equip/Unequip"


EquipItem will only send the slotIndex of the item from your inventory, which you want to equip.
And then it calls the function to get the according free slot where this item could be equipped.

Example: double click, drag&drop or right-click and choose "Equip" on a helmet in your inventory will try to equip the helm in the helmet slot.
But the function EquipItem will only use the bagId of BAG_BACKPACK and the slotIndex of the helmet in your inventory.

Is there any easier way to get the slotIndex or control name where this helmet will "be equipped", or do I need to "search the possible slot(s)" by help of the itemType I want to equip in a callback function of a PreHook to function "EquipItem"?

And the same the other way around if you unequip an item.
  Reply With Quote
11/01/15, 02:52 PM   #2
Wandamey
Guest
Posts: n/a
EVENT_INVENTORY_SINGLE_SLOT_UPDATE (integer eventCode, integer bagId, integer slotIndex, boolean isNewItem, integer itemSoundCategory, integer updateReason)

check that bagId == BAG_WORN before anything else?
not sure if it informs of a newly emptied slot though.


edit : inventory item border is also using this : EVENT_ACTIVE_WEAPON_PAIR_CHANGED
might be useful.

Last edited by Wandamey : 11/01/15 at 03:00 PM.
  Reply With Quote
11/01/15, 02:53 PM   #3
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
I found one other way but I don't really like it:

use the event EVENT_INVENTORY_SINGLE_SLOT_UPDATE and check for bagId == BAG_WORN and updateReason == INVENTORY_UPDATE_REASON_DEFAULT

Then use the slotIndex to get the control name from the equipment controls and update the markers.

Edit:
Haha, thanks Wandamey! Just posted in the same time^^

Tested the unequipping of items: The EVENT_INVENTORY_SINGLE_SLOT_UPDATE will not be called for BAG_WORN then.
So you need to PreHook UnequipItem tpoo for those as it seems

Last edited by Baertram : 11/01/15 at 02:58 PM.
  Reply With Quote
11/01/15, 03:06 PM   #4
Wandamey
Guest
Posts: n/a
you can keep the count of the number of equipped items you have and if it goes down make a little check up of the paper doll, and a differential diagnosis. Huuuu, i'm mistaken with doctor House sorry.
  Reply With Quote
11/01/15, 03:12 PM   #5
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
This will notify you when the slot changes with the correct slotId for the slot the item is equipped to or unequipped from.

Lua Code:
  1. local function OnSharedSingleSlotUpdate(bagId, slotId, newItem, itemSoundCategory, updateReason)
  2.     if bagId ~= BAG_WORN then return end
  3.    
  4. end
  5.  
  6. SHARED_INVENTORY:RegisterCallback("SingleSlotInventoryUpdate", OnSharedSingleSlotUpdate)

Last edited by circonian : 11/01/15 at 03:14 PM.
  Reply With Quote
11/01/15, 03:24 PM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Thanks circonian
  Reply With Quote
11/01/15, 03:24 PM   #7
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
If all your wanting is the slot control then try this:

Lua Code:
  1. local function OnWornSlotUpdate(slotControl)
  2.  
  3. end
  4.  
  5. CALLBACK_MANAGER:RegisterCallback("WornSlotUpdate", OnWornSlotUpdate)

Edit:
Ooops, I should have tested it. If the user does a normal equip/unequip, double click, or drag to equip it fires once. But if they drag the item out of the slot (like to unequip by dragging to the inventory) it fires on the drag & again whenever they drop the item. So that one might not be useful.

Last edited by circonian : 11/01/15 at 06:13 PM.
  Reply With Quote
11/01/15, 04:31 PM   #8
Wandamey
Guest
Posts: n/a
Originally Posted by Baertram View Post
Tested the unequipping of items: The EVENT_INVENTORY_SINGLE_SLOT_UPDATE will not be called for BAG_WORN then.
So you need to PreHook UnequipItem tpoo for those as it seems
Tested it too because there is no reason that the event differs from circonian's callback and it's working on unequip too, sending an update reason = 0 (default). You must have made a typo while testing or just looked at the last result which may have been the item landing in the backpack.

Randactyl should take a look in here too ... got floating locks around my doll now , but it's refreshed on bag reopening in his case.

Last edited by Wandamey : 11/01/15 at 04:39 PM.
  Reply With Quote
11/01/15, 06:12 PM   #9
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by Wandamey View Post
Tested it too because there is no reason that the event differs from circonian's callback and it's working on unequip too, sending an update reason = 0 (default). You must have made a typo while testing or just looked at the last result which may have been the item landing in the backpack.

Randactyl should take a look in here too ... got floating locks around my doll now , but it's refreshed on bag reopening in his case.
Floating locks....oh, now I see what hes wanting this for. Once again I guess I didn't read the post very carefully. If that's all Baertram needs this for, to put markers on the equipment slots then use the
Lua Code:
  1. SHARED_INVENTORY:RegisterCallback("SingleSlotInventoryUpdate", OnSharedSingleSlotUpdate)
that's what I use in FilterIt.

Last edited by circonian : 11/03/15 at 01:15 PM.
  Reply With Quote
11/02/15, 05:12 PM   #10
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Yeah, it was all about the markers next to the equipment slots :-)
I had played around with the WornSlotUpdate callback too (checked the esoui 2.2 code from Ayantr and found it in there), but it didn't alwas/or did fire too ofter sometimes.

Upon opening of the inventory I'll update all slots too (same as ItemSaver probably does), but I wanted to update the slots properly as the items get equipped/unequipped already.

@Wandamey
This is woot. I've tried it for unequipped items and it never reached the part of the source code somehow.
Using the same event callback function etc. it just seemd to fire with another update reason or not the BAG_WORN (only BAG_BACKPACK). I'll try it again then, thanks for the info.
  Reply With Quote
11/02/15, 07:40 PM   #11
Wandamey
Guest
Posts: n/a
Originally Posted by Baertram View Post
@Wandamey
This is woot. I've tried it for unequipped items and it never reached the part of the source code somehow.
Using the same event callback function etc. it just seemd to fire with another update reason or not the BAG_WORN (only BAG_BACKPACK). I'll try it again then, thanks for the info.
Just so you know, you can tell you made me end up naked in the street while my chat was spamming "reason = 0" like a bad laugh.

no, seriously, check that you don't have something else running at the same time, seems weird that neither circonian's/ayantir's method or this one work exactly as intended.
  Reply With Quote
11/03/15, 01:15 PM   #12
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
All three methods will work: EVENT_INVENTORY_SINGLE_SLOT_UPDATE, OnSharedSingleSlotUpdate, & OnWornSlotUpdate.

I'm not sure if you tested it recently or if your comments about it not working properly were based on tests you did in the past, because I can tell you that in the past OnSharedSingleSlotUpdate use to NOT fire for unequipping items and OnWornSlotUpdate use to NOT fire for equipping items. But they changed the way it works and now both fire whether your equipping or unequipping via any method: double-click, drag & drop, or using the context menu.

You are correct that OnWornSlotUpdate does fire twice if you drag an item out of an equipment slot & drop it into the inventory slot. It fires once for the drag out of the equipment slot & once for the drop into the inventory slot. Any other method (including dragging items into the slot) only fires it once.

However, EVENT_INVENTORY_SINGLE_SLOT_UPDATE, OnWornSlotUpdate also fire for durability Updates. For EVENT_INVENTORY_SINGLE_SLOT_UPDATE you can't use the updateReason to filter it out because, for example, when you repair an item (and at other times) it fires both reasons INVENTORY_UPDATE_REASON_DURABILITY_CHANGE & INVENTORY_UPDATE_REASON_DEFAULT, but this one does not fire for durability updates, only when the item in the slot changes.
Lua Code:
  1. SHARED_INVENTORY:RegisterCallback("SingleSlotInventoryUpdate", OnSharedSingleSlotUpdate)

Last edited by circonian : 11/03/15 at 01:25 PM.
  Reply With Quote
11/05/15, 03:48 AM   #13
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
I've tested it before the update to 2.2 and I did not test it on PTS (as the download was too slow to finish in time before the update to 2.2 was live ).

I need to find the time to test it on 2.2 live now again and I guess I'll change to the SHARED_INVENTORY callback function then.

As I'm currently using the normal EVENT_INVENTORY_SINGLE_SLOT_UPDATE callback function to check new looted items, if they apply to some filters and should get a marker symbol then (like marking a new looted intricate item with the intricate texture marker):

Could I replace the event callback function with the same new callback function of SHARED_INVENTORY "SingleSlotInventoryUpdate" too in the future, to do these intricate checks etc.?
  Reply With Quote
11/05/15, 06:57 AM   #14
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Haven't looked too much into it. EVENT_INVENTORY_SINGLE_SLOT_UPDATE seems the most appropriate, since you can filter for BAG_WORN and INVENTORY_UPDATE_REASON_DEFAULT. "SingleSlotInventoryUpdate" doesn't receive updateReason.

As for non-worn inventories, your markers are display stuff, right? If so, you don't need to run code when a slot changes, but only when it's shown. I'd try hooking ZO_PlayerInventorySlot_SetupSlot -- or ZO_Inventory_SetupSlot, or ZO_ItemSlot_SetupSlot, if you want it in other "inventories" like mail, decon etc. but there you'll probably have to check slotType.
  Reply With Quote
11/05/15, 08:55 AM   #15
@AlphaLemming
 
@AlphaLemming's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 122
I'am using this for CraftStore:

Lua Code:
  1. local function OnSlotAdded(bag,slot,data)
  2.     < example > data.uid = Id64ToString(GetItemUniqueId(bag,slot))
  3.     < your code >
  4. end
  5.  
  6. local function OnSlotRemoved(bag,slot,data)
  7.     < your code >
  8. end
  9.  
  10. SHARED_INVENTORY:RegisterCallback('SlotAdded',OnSlotAdded)
  11. SHARED_INVENTORY:RegisterCallback('SlotRemoved',OnSlotRemoved)

This functions are instantly called on every item change. You can also use 'SlotUpdated'.
  Reply With Quote
11/06/15, 03:06 AM   #16
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Thanks merlight and @AlphaLemming.
I hope I'll get to test the different stuff after the weekend (birthday time )
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » v2.2 Easiest way to react on changed equippment items?

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