In the OnLootUpdated function it checks with several rules and options if the item in the loot window should be looted or not.
This all works quite nicely so far, when all the items should be looted. Then this function OnLootUpdated is called only once. But if there are items in the list that should not be looted (e.g. trash or some configured not wanted items) the function is called multiple times, as many times as items were in the initial list. So if the initial list contained e.g. 5 items, with 2 unwanted ones, the function will be called 5 times.
I think that the removal of the wanted ones triggers a call of the event EVENT_LOOT_UPDATED again and the function is called again. When all items were looted in the first place the nect call of the function bails out as the loot list is empty.
I tried to unregister from the event at the beginning of the function and register at the end again, but with no luck.
>I think that the removal of the wanted ones triggers a call of the event EVENT_LOOT_UPDATED again and the function is called again.
You are easily able to find this out by adding a d("EVENT_LOOT_UPDATED") into your callback function
So you will see in chat how often, and when, it will be called.
I guess it will be called once per update to the loot window which might happen as you remove lines in there, yes. Or maybe even changing the position will call the event for the EVENT_LOOT_UPDATED. Depends on how ZOs implemented this.
maybe another event like EVENT_LOOT_RECEIVED could help here instead, you would have to try though.
If you do not want to let the event callback function self:OnLootUpdated( ... ) run multiple times try to surround it with a blocking/"already currently running" variable like this:
Should work the same with the unregister of the event, yes.
If this does not work there is something else triggering the code, maybe not via EVENT_LOOT_UPDATED?
Did you check if anything else in the addon calls self:OnLootUpdated function ?