Untitled
unknown
lua
10 months ago
2.9 kB
19
Indexable
local getLootBagByWindowId = {
[1] = CONST_LOOT_BAG_1,
[2] = CONST_LOOT_BAG_2,
[3] = CONST_LOOT_BAG_3,
[4] = CONST_LOOT_BAG_4,
}
local function getLootedLootList(corpse)
local itemList = {}
local itemsCount = corpse:getItemHoldingCount()
for i=1, itemsCount do
local item = corpse:getItem(i)
itemList[#itemList + 1] = item
end
return itemList
end
local function collectItemsByAutoLoot(player, corpse)
local message = ""
local getAutoLootWindows = player:getAutoLootItems()
if not getAutoLootWindows then
return message
end
local getLootedItems = getLootedLootList(corpse)
if #getLootedItems <= 0 then
return message
end
for i=1, #getLootedItems do
local lootedItem = getLootedItems[i]
local getFreeCapacity = player:getFreeCapacity() - 1000
local itemId = lootedItem:getId()
local count = lootedItem:getCount()
local itemType = ItemType(itemId)
local itemWeight = itemType:getWeight()
local maxPickUpItem = count
if itemWeight * count > getFreeCapacity then
maxPickUpItem = math.floor(getFreeCapacity / itemWeight)
if maxPickUpItem > 0 then
message = message.." Picking up only: "..maxPickUpItem.."x "..itemType:getName().." (limited by cap [AL ~ need more than 10 cap])"
else
message = message.." Cannot pickup: "..count.."x "..itemType:getName().." (too little cap[AL ~ need more than 10 cap])"
end
end
if maxPickUpItem > 0 then
for windowId, getAutolootItems in pairs(getAutoLootWindows) do
if getAutolootItems[itemId] then
local moveToSlot = getLootBagByWindowId[windowId]
if moveToSlot then
if player:addItemEx(lootedItem, false, moveToSlot, FLAG_DEEPCONTAINERSEARCH) == RETURNVALUE_NOTPOSSIBLE then
local itemQuality = lootedItem:getTrueQuality()
if itemQuality and itemQuality > 0 then
local qualityInfo = getItemQualityInfoByValue(itemQuality)
if qualityInfo then
message = message.." {"..count.."x "..itemType:getName().."| "..qualityInfo[4].."}"
else
message = message.." "..count.."x "..itemType:getName()
end
else
message = message.." "..count.."x "..itemType:getName()
end
end
break
end
end
end
end
end
return message
endEditor is loading...
Leave a Comment