local t = {
remove = {
{2499, 1},
{2500, 1}
},
add = {
{2501, 1},
{2502, 1},
{2400, 1}
},
storage = 30045
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerStorageValue(cid, t.storage) < 1 then
local v, w, h = "", 0, true
for i = 1, #t.remove do
if getPlayerItemCount(cid, t.remove[i][1]) < t.remove[i][2] then
h = false
break
end
end
if h then
for i = 1, #t.add do
v = v .. (i == #t.add and " and " or i > 1 and ", " or "") .. (t.add[i][2] > 1 and t.add[i][2] or getItemInfo(t.add[i][1]).article) .. " " .. (t.add[i][2] > 1 and getItemInfo(t.add[i][1]).plural or getItemInfo(t.add[i][1]).name)
w = w + getItemWeightById(t.add[i][1], t.add[i][2] or 1)
end
if getPlayerFreeCap(cid) >= w then
for i = 1, #t.remove do
doPlayerRemoveItem(cid, t.remove[i][1], t.remove[i][2] or 1)
end
for i = 1, #t.add do
doPlayerAddItem(cid, t.add[i][1], t.add[i][2] or 1)
end
setPlayerStorageValue(cid, t.storage, 1)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found " .. v .. ".")
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found " .. v .. ". Weighing " .. w .. " oz it is too heavy.")
end
else
for i = 1, #t.remove do
v = v .. (i == #t.remove and " and " or i > 1 and ", " or "") .. (t.remove[i][2] > 1 and t.remove[i][2] or getItemInfo(t.remove[i][1]).article) .. " " .. (t.remove[i][2] > 1 and getItemInfo(t.remove[i][1]).plural or getItemInfo(t.remove[i][1]).name)
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You don't have " .. v .. ".")
end
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR,"You have already done this.")
end
return true
end