function doPlayerAddDepotItems(cid, items, town)
if (not isPlayer(cid)) then
error("Player not found")
end
local town = town or getPlayerTown(cid)
local parcel = doCreateItemEx(ITEM_PARCEL)
for item, count in pairs(items) do
if (type(item) == "number") then
local attritemid = doAddContainerItem(parcel, item, count)
doItemSetAttribute(attritemid, "description", "This item belongs to ".. getPlayerName(cid) ..".")
doItemSetAttribute(attritemid, "aid", getPlayerGUID(cid)+10000)
elseif (type(item) == "string") then
doAddContainerItem(parcel, getItemIdByName(item), count)
else
error("Undefinied type of item name")
end
end
return doPlayerSendMailByName(getCreatureName(cid), parcel, town)
end
function onThink(interval, lastExecution, thinkInterval)
local result = db.getResult("SELECT * FROM shop_history WHERE `processed` = 0;")
if(result:getID() ~= -1) then
while(true) do
cid = getCreatureByName(tostring(result:getDataString("player")))
product = tonumber(result:getDataInt("product"))
itemr = db.getResult("SELECT * FROM shop_offer WHERE `id` = "..product..";")
if isPlayer(cid) then
local id = tonumber(itemr:getDataInt("item"))
local tid = tonumber(result:getDataInt("id"))
local count = tonumber(itemr:getDataInt("count"))
local tipe = tonumber(itemr:getDataInt("type"))
local productn = tostring(itemr:getDataString("name"))
if isInArray({5,8},tipe) then
if getPlayerFreeCap(cid) >= getItemWeightById(id, count) then
if isPlayer(cid) then
received = doPlayerAddDepotItems(cid, {[id]=count})
if received then
doPlayerSendTextMessage(cid,19, "You received "..productn.." in depot of your hometown.")
db.query("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
doPlayerSave(cid)
else
doPlayerSendTextMessage(cid,19, "You need a free slot on container to receive "..productn..".")
end
else
doPlayerSendTextMessage(cid,19, "You need a free container to receive "..productn..".")
end
else
doPlayerSendTextMessage(cid,19, "You need "..getItemWeightById(id, count).." of free capacity to receive "..productn..".")
end
elseif isInArray({6,7},tipe) then
if tipe == 6 then
bcap = 8
bid = 1987
elseif tipe == 7 then
bcap = 20
bid = 1988
end
if isItemRune(id) then
count = 1
end
if getPlayerFreeCap(cid) >= (getItemWeightById(1987, 1) + getItemWeightById(id,count * bcap)) then
local bag = doCreateItemEx(bid, 1)
for i = 1,bcap do
doAddContainerItem(bag, id, count)
end
received = doPlayerAddDepotItems(cid, bag)
if received == RETURNVALUE_NOERROR then
doPlayerSendTextMessage(cid,19, "You received "..productn.." in depot of your hometown.")
db.query("UPDATE `shop_history` SET `processed`='1' WHERE id = " .. tid .. ";")
doPlayerSave(cid)
else
doPlayerSendTextMessage(cid,19, "You need a free slot on container to receive "..productn..".")
end
else
doPlayerSendTextMessage(cid,19, "You need "..getItemWeightById(id, count).." of free capacity to receive "..productn..".")
end
end
end
itemr:free()
if not(result:next()) then
break
end
end
result:free()
end
return true
end