View Single Post
01/15/17, 01:27 PM   #4
Augestflex
Join Date: Jan 2016
Posts: 4
Dolgubon, Baertram: Thank you so much for reading my post, I realize it is a bit lengthy, and for taking the time to respond to it.

Originally Posted by Dolgubon View Post
This is the code that I use (stripped of some additional unnecessary logic) It's possible the show inventory bit doesn't need to be on a delay, it's been a while since I coded it.

Code:
local function OnLootUpdated(event)
	if autoLoot then
		LOOT_SHARED:LootAllItems()
		zo_callLater(function() SYSTEMS:GetObject("mainMenu"):ShowCategory(MENU_CATEGORY_INVENTORY)end, 50)
	end
end

EVENT_MANAGER:RegisterForEvent(WritCreater.name, EVENT_LOOT_UPDATED ,OnLootUpdated )
l think that you need to do LOOT_SHARED:LootAllItems() instead of just LootAllItems(). Also, are you coming from Java or something? Lua has no concept of overloading functions. The second function you have listed will simply overwrite the first one listed. Instead, you'll need to build it in yourself, likely with if eventcode then 1stfunction() else 2ndfunction() end, or if not eventcode then eventcode = 1 end.

It looks like you've added the event properly, but double check that the event is added below the lootallcontents, or that it's added in the initialization function. If you add it before that, it's not going to call anything.

For structured languages that are developed with functions I'm not used to a positional requirement that certain code needs to be placed above calling code/events. Generally if the method name and parameters are correct, and you use the correct class/object/etc. then the location of a method becomes irrelevant in my experience. Good to know this is not the case with LUA. I've now moved my LootAllContents(eventCode) above the line number where I register it for the event.

Regarding function overloading, my programming experience is C++, light Java, and many years of C# and VB.NET development. Thanks for the heads up regarding no overloading support. No worries, as you describe, it is easy enough to make one method and then manually check with if/then to change program flow instead of the convenience of overloaded functions.

I've haven't tried LOOT_SHARED:LootAllItems() yet, but that is coming next.

Silly question, I do need the eventCode parameter in the functional decoration for LootAllItems() right?

e.g. I need this:
Code:
local function LootAllContents(eventCode)
Not this:
Code:
local function LootAllContents()

Originally Posted by Baertram View Post
Welcome. Just a quick question:
You know there is an option ingame to autoloot all (works with containers too if I remember right).

So maybe check the esoui sources too for this option.

Hello Baertram, thank you for the time to read and respond, greatly appreciated.

I do have the in game Settings --> Gameplay --> autoloot options (even for stolen items) set to Yes. Interestingly (and maybe this is due to an addon or ZOS bug, that I should look into), it works for "most" containers but not for all.

However, in this case looting all contents of the container in the inventory is only the second (or third) step of several things I want to do in the addon. e.g. In this case, the user explicitly calls the addon through either a keybind or item context menu. Then step two the addon opens and loots the container, then step three the addon continues to the next container, loots it, (repeat that step), then the last actions occur.


Thanks!

Last edited by Augestflex : 01/15/17 at 01:32 PM. Reason: edit to address question regarding overloading.
  Reply With Quote