function doSearchItemsID(cid, items, container, cost)
for i = getContainerSize(container.uid), 0, -1 do
local container = getContainerItem(container.uid, i)
if not ( isContainer(container.uid) ) then
for k, v in pairs(items) do
if container.itemid == v[1] then
local count = container.type
if isItemStackable(v[1]) and count > 1 then
cost = cost + (count * v[2])
doRemoveItem(container.uid)
else
cost = cost + v[2]
doRemoveItem(container.uid, 1)
end
end
end
else
doSearchItemsID(cid, items, container, cost)
end
end
return cost
end
local items = {
{2465,150},
{2466,20000},
{2486,1500},
{2487,13000}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local pos = getThingPos(item.uid)
pos.x = pos.x - 1
local cost = 0
for i = 254, 1, -1 do
pos.stackpos = i
local temp = getThingFromPos(pos)
if isContainer(temp.uid) then
cost = doSearchItemsID(cid, items, temp, cost)
break
end
end
if item.itemid == 1945 then
doTransformItem(item.uid, 1946)
else
doTransformItem(item.uid, 1945)
end
if cost ~= 0 then
doPlayerAddMoney(cid, cost)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Sprzedales loot i zarobiles '..cost..' sztuk zlota.')
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'Pojemnik z lootem jest pusty.')
end
return true
end