Thread Tools Display Modes
04/30/23, 11:09 AM   #1
Lykeion
 
Lykeion's Avatar
AddOn Author - Click to view addons
Join Date: May 2022
Posts: 19
Does LootItemById() throws an EVENT_INVENTORY_SINGLE_SLOT_UPDATE?

I tried to add an autobind feature to my autoloot addon, but I can't seem to get the information about the looted gear via EVENT_INVENTORY_SINGLE_SLOT_UPDATE when LootItemById. This is a bit strange, is there something I'm doing wrong?

A simplified version of my code looks like this. I have tried leaving the print statement inside _onInventorySlotUpdate, but it doesn't look like this function is being called
Code:
function MyAddon:LootSetItem(link, lootId, isUnresearched, isOrnate, isIntricate, isSetItem, isUncollected)
	local function _onInventorySlotUpdate(eventCode, bagId, slotIndex, isNewItem, itemSoundCategory, updateReason, stackCountChange)
                d('_onInventorySlotUpdate is called')
		if (db.autoBind) then 
			BindItem(bagId, slotIndex) 
		end
	end
	
	EVENT_MANAGER:RegisterForEvent("SLOT_UPDATE", EVENT_INVENTORY_SINGLE_SLOT_UPDATE, _onInventorySlotUpdate)
        LootItemById(lootId)
	EVENT_MANAGER:UnregisterForEvent("SLOT_UPDATE", EVENT_INVENTORY_SINGLE_SLOT_UPDATE)
end
  Reply With Quote
04/30/23, 11:49 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,963
Just skip the loot check, add an EVENT_INVENTORY_SINGLE_SLOT_UPDATE with filter on BagId = BAG_BAGPACK and isNew = true.
https://wiki.esoui.com/AddFilterForEvent
Looted items definately throw that event but I cannot say in what order.
But with the new AND bag filter it should only count for really new "looted" or "crafted" items.

Install merTorchbug or Zgoo addons and enable the event tracking (merTorchbug: /tb command, then press on the e at the title bar, or use /tbe to get to the events tab and then press the e button at the titlebar) and see what events fire as you do things.

Btw: please! use unique names for the events registered !!!
do not simply use SLOT_UPDATE, add your addon name in there ("MyUniqueAddonName_SlotUpdate") so it's not overwriting ZOs or other event handlers by accident!!!
This applies to ALL uniqueNames for events, callbacks, global function names & variabnles, and so on.

Last edited by Baertram : 04/30/23 at 11:52 AM.
  Reply With Quote
04/30/23, 01:40 PM   #3
Lykeion
 
Lykeion's Avatar
AddOn Author - Click to view addons
Join Date: May 2022
Posts: 19
Thank you for your advice! After some troubleshooting I found that the parameter list returned by EVENT_INVENTORY_SINGLE_SLOT_UPDATE does not have eventcode as described in the documentation, so my addon didn't work as expected before because I wasn't handling the correct parameter. Perhaps the documentation for this needs some updating.

As I said at the beginning, the code I've given is simplified and for demonstration purposes only. I will not use over-generalized event names in the actual addon. Thanks for pointing that out though
  Reply With Quote
04/30/23, 02:33 PM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,963
Hm, the 1st param should always be the eventCode and last time I coded the event usage of was using it? Are you sure it's no local issue of your addon because you use the : notation in your addon without actually defining the past in front of the addon as real ZO_Object:SubClass?

If your part in front of the :is just s simple table, use the . notation and it should be fine with the parameters!

MyAddon.LootSetItemlink instead of :
If you would e. G. pass in MyAddon:OnEventItemLink (which was defined as this function name, with : )
MyAddon.OnEventItemLink at an EVENT_MANAGER:RegisterForEvent
Then the first param need to be MyAddon, else the param list is missplaced!

Last edited by Baertram : 04/30/23 at 02:37 PM.
  Reply With Quote
04/30/23, 02:42 PM   #5
Lykeion
 
Lykeion's Avatar
AddOn Author - Click to view addons
Join Date: May 2022
Posts: 19
Wow I had no idea that the difference between :and . would make such a big impact. Most likely you are right. I should spend some time studying the differences.
  Reply With Quote
05/01/23, 04:31 AM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,963
Basically the difference is not there, but it depends on if you create an object of a class (which basically is a table too, but uses metatable functionality of lua to create a "referencing copy" of the other tables -> object oriented inheritance).

You can reference the object created from myClass, via myClass:New(), by using self in the code then.

But if you define functions as myClass:functionName(param1, param2) and call the function from any code where you cannot directly use : notation, and need to switch to the . notation, the first param of the object created from myClass needs to be the reference to the object again.

myObjectCreatedFromMyClass.functionName(myObjectCreatedFromMyClass, param1, param2)
This replaces the self reference then.

So you may need to call your EVENT_MANAGER:RegisterForEvent("myAddonName_EventBlubb", EVENT_BLUBB, function(...) myObject.functionName(myObject, ...) )
where ... contains the eventId as 1st, then the other foloowing params of that event.
Or you need to use the : notation
EVENT_MANAGER:RegisterForEvent("myAddonName_EventBlubb", EVENT_BLUBB, function(...) myObject:functionName(...) )

You may not use myClass then, but the created object!
And if there is no object, just myClass = {} --simple table, then your call would be something like
EVENT_MANAGER:RegisterForEvent("myAddonName_EventBlubb", EVENT_BLUBB, function(...) myClass.functionName(...) )

If you directly call
EVENT_MANAGER:RegisterForEvent("myAddonName_EventBlubb", EVENT_BLUBB, myClass.functionName )
it may not work if your function was defined as
function myClass:functionName

If it was defined as
function myClass.functionName
it should work though IF the 1st param is the eventId then.

So there might be the need to capture it with an anonymous function around the myClass.functioName call

Last edited by Baertram : 05/01/23 at 04:35 AM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Does LootItemById() throws an EVENT_INVENTORY_SINGLE_SLOT_UPDATE?

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