EC: Add a macro action that blindly loots all open containers
The EC does not have a macro action that will blindly loot all open containers. It does have a Vacuum action that only loots predetermined item types. The following code changes will add the Actions.MassLootAll function. To use it use "script Actions.MassLootAll()" with the Command action.
It is equivalent to manually clicking on the LootAll buttons on all of the open containers.
To the file source\Actions.lua add the following code:
It is equivalent to manually clicking on the LootAll buttons on all of the open containers.
To the file source\Actions.lua add the following code:
--start of added code
Actions.MassLootAllEnabled = false
Actions.MassLootObjects = {}
function Actions.MassLootAll()
if (Actions.MassLootAllEnabled == false) then
Actions.MassLootAllEnabled = true
if(ContainerWindow.StopOrganizer ~= nil) then
ContainerWindow.StopOrganizer()
end
if(ContainerWindow.StopLootAll ~= nil) then
ContainerWindow.StopLootAll()
end
else
Actions.MassLootAllEnabled = false
end
end
function Actions.StopMassLootAll()
Actions.MassLootAllEnabled = false
end
function Actions.MassLootAller(timePassed)
local LootBoxID = Interface.LootBoxID
if not LootBoxID or LootBoxID == 0 then
LootBoxID = ContainerWindow.PlayerBackpack
end
if (Actions.MassLootAllEnabled == true and ContainerWindow.CanPickUp == true and SystemData.DragItem.DragType ~= SystemData.DragItem.TYPE_ITEM) then
if not Actions.MassLootObjects or #Actions.MassLootObjects == 0 then
Actions.MassLootObjects = {}
for id, value in pairs(ContainerWindow.OpenContainers) do
if (DoesWindowNameExist("ContainerWindow_"..id) and id ~= ContainerWindow.PlayerBackpack and id ~= LootBoxID) then
local numItems = WindowData.ContainerWindow[id].numItems
for i = 1, numItems do
local item = WindowData.ContainerWindow[id].ContainedItems[i]
RegisterWindowData(WindowData.ObjectInfo.Type, item.objectId)
local itemData = WindowData.ObjectInfo[item.objectId]
local weight = ItemProperties.GetItemWeight(item.objectId)
if(weight == 50 and itemData.quantity == 1) then
itemData = nil --do not loot items that weigh 50 stones
end
if (itemData) then
local data = {itemId = item.objectId, containerId = id}
table.insert(Actions.MassLootObjects, data)
end
UnregisterWindowData(WindowData.ObjectInfo.Type, item.objectId)
end
end
end
end
if (Actions.MassLootAllEnabled == true and Actions.MassLootObjects and #Actions.MassLootObjects > 0) then
-- cleanup by removing items that are in no longer open containers
local objectsInStillOpenContainers = {}
for id, data in pairs(Actions.MassLootObjects) do
if(ContainerWindow.OpenContainers[data.containerId] ~= nil) then
table.insert(objectsInStillOpenContainers, data) -- item's container is open, keep trying to move it
end
end
Actions.MassLootObjects = objectsInStillOpenContainers
end
if (Actions.MassLootAllEnabled == true and Actions.MassLootObjects and #Actions.MassLootObjects > 0) then
local data = Actions.MassLootObjects[1]
if(data ~= nil) then
local itemId = data.itemId
RegisterWindowData(WindowData.ObjectInfo.Type, itemId)
local itemData = WindowData.ObjectInfo[itemId]
UnregisterWindowData(WindowData.ObjectInfo.Type, itemId)
ContainerWindow.TimePassedSincePickUp = 0
ContainerWindow.CanPickUp = false
ObjectHandleWindow.lastItem = itemId
MoveItemToContainer(itemId, itemData.quantity, LootBoxID)
end
table.remove(Actions.MassLootObjects, 1)
if #Actions.MassLootObjects == 0 then
Actions.MassLootObjects = {}
-- check for newly opened containers that can be mass looted
for id, value in pairs(ContainerWindow.OpenContainers) do
if (DoesWindowNameExist("ContainerWindow_"..id) and id ~= ContainerWindow.PlayerBackpack and id ~= LootBoxID) then
local numItems = WindowData.ContainerWindow[id].numItems
for i = 1, numItems do
local item = WindowData.ContainerWindow[id].ContainedItems[i]
RegisterWindowData(WindowData.ObjectInfo.Type, item.objectId)
local itemData = WindowData.ObjectInfo[item.objectId]
local weight = ItemProperties.GetItemWeight(item.objectId)
if(weight == 50 and itemData.quantity == 1) then
itemData = nil --do not loot items that weigh 50 stones
end
if (itemData) then
local data = {itemId = item.objectId, containerId = id}
table.insert(Actions.MassLootObjects, data)
end
UnregisterWindowData(WindowData.ObjectInfo.Type, item.objectId)
end
end
end
if #Actions.MassLootObjects == 0 then
Actions.MassLootAllEnabled = false -- nothing left to loot so stop trying to loot
end
end
end
if (Actions.MassLootAllEnabled == true and Actions.MassLootObjects and #Actions.MassLootObjects == 0) then
Actions.MassLootAllEnabled = false -- nothing left to loot so stop trying to loot
end
end
if(Actions.MassLootAllEnabled == false and Actions.MassLootObjects and #Actions.MassLootObjects > 0) then
Actions.MassLootObjects = {} -- clean up
end
end
--end of added code
To the file source\ItemProperties.lua add the following code if you have not already added it from one of my previous enhancements
--start of added codeTo the function TextParsing.SpecialTexts() in the file source\TextParsing.lua add the following code. It replaces code from another of my earlier enhancements.
function ItemProperties.GetItemWeight(itemId)
local weight = 0
local props = ItemProperties.GetObjectPropertiesArray( itemId, "GetItemWeight" )
if (props) then
local params = ItemProperties.BuildParamsArray( props )
for j = 1, #props.PropertiesTids do
if (ItemPropertiesInfo.WeightONLYTid[props.PropertiesTids[j]]) then
token = ItemPropertiesInfo.WeightONLYTid[props.PropertiesTids[j]]
val = tostring(params[props.PropertiesTids[j]][token])
weight = tonumber(val)
return weight
end
end
end
return weight
end
--end of added code
--start of added codeTo the function Interface.Update in the file Interface.lua add the following code
if ( senderText ~= nil) then
local tooMuchWeight = GetStringFromTid(1080016) -- "That container cannot hold more weight."
local tooManyItems = GetStringFromTid(1080017) -- "That container cannot hold more items."
if( senderText == tooMuchWeight or senderText == tooManyItems) then
if(ContainerWindow.StopOrganizer ~= nil) then
ContainerWindow.StopOrganizer()
end
if(ContainerWindow.StopLootAll ~= nil) then
ContainerWindow.StopLootAll()
end
if(Actions.StopMassLootAll ~= nil) then
Actions.StopMassLootAll()
end
end
end
--end of added code
ok, err = pcall(Actions.MassOrganizer, timePassed)
Interface.ErrorTracker(ok, err)
--start of added code
ok, err = pcall(Actions.MassLootAller, timePassed)
Interface.ErrorTracker(ok, err)
--end of added code
Comments
I will be slow to reply because I cannot log in/stay logged in to the forums.
Make this your signature if you are tired of Vendor Search being broken, over FIVE YEARS and counting.
Vendor search rendered useless after Publish 106 – Forsaken Foes on August 14, 2019.