function onUse(cid, item, frompos, item2, topos)
if isWatchingTv(cid) then return true end
local function getContainers(pos)
local things = getTileInfo(pos).things
local ret = {}
for stack = 0, things do
pos.stackpos = stack
local item = getTileThingByPos(pos)
if item and isContainer(item.uid) then
local quemMatou = getItemAttribute(item.uid, "corpseowner")
if quemMatou then
local player = getCreatureByName(quemMatou)
if isPlayer(player) then
local isInParyWithPlayer = false
if isInParty(cid) and isInParty(player) then
isInParyWithPlayer = isPartyEquals(player, cid)
end
if getCreatureName(cid) == quemMatou or isInParyWithPlayer then
table.insert(ret, item)
end
end
end
end
end
return ret
end
local corpses = getContainers(getThingPosition(item.uid))
if #corpses == 0 then
doPlayerSendCancel(cid, "Você não pode abrir um loot que não é seu.")
return true
end
local autoLootList = getAllItensInMyList(cid)
local bag = getPlayerSlotItem(cid, 3).uid
local itemsToRemove = {}
for _, corpse in pairs(corpses) do
for a = -1, getContainerSize(corpse.uid) - 1 do
local it = getContainerItem(corpse.uid, a)
if it.uid > 0 then
--if addItemInFreeBag(bag, it.itemid, it.type) ~= false then
if doPlayerAddItemStacking(cid, it.itemid, it.type) ~= false then
table.insert(itemsToRemove, it.uid)
end
end
end
end
if #itemsToRemove > 0 then
for i = 1, #itemsToRemove do
doChangeTypeItem(itemsToRemove
, 0) end end end