--<talkaction words="/depot;!depot" event="script" value="depot.lua"/>--
local sendToDepot = false
local depotIDs = {2589, 2590, 2591, 2592} -- South, West, North and East
local middleItems = {1643, 1645} -- Eixo Y, Eixo X
function onSay(cid, words, param, channel)
if not getPosition(getThingPos(cid)).depot then
doPlayerSendCancel(cid, "You're not on the depot.")
return true
end
param = string.lower(param)
if (param == "clean") then
doCleanTile(getPosition(getThingPos(cid)).depot)
doCleanTile(getPosition(getThingPos(cid)).middle)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "The depot and its surrounding were cleaned.")
elseif (param == "collect") then
local pos = getPosition(getThingPos(cid)).depot
while getThingFromPos(pos).itemid > 0 do
pos.stackpos = pos.stackpos + 1
if (pos.stackpos > 2) and (isInArray(depotIDs, getThingFromPos(pos).itemid)) then
pos.stackpos = pos.stackpos - 1
break
elseif (getThingFromPos(pos).itemid == 0) then
break
end
end
local toAdd = getThingFromPos(pos)
if toAdd.itemid > 0 then
if sendToDepot then
doRemoveItem(toAdd.uid)
local parcel = doCreateItemEx(ITEM_PARCEL)
doAddContainerItem(parcel, toAdd.itemid, toAdd.type)
doPlayerSendMailByName(getPlayerName(cid), parcel, getPlayerTown(cid))
local itemArticle = isItemStackable(toAdd.itemid) and toAdd.type or getItemArticleById(toAdd.itemid)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You just received "..itemArticle.." "..getItemNameById(toAdd.itemid).." in your depot.")
else
doRemoveItem(toAdd.uid)
doPlayerAddItem(cid, toAdd.itemid, toAdd.type)
local itemArticle = isItemStackable(toAdd.itemid) and toAdd.type or getItemArticleById(toAdd.itemid)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, string.upper(itemArticle).." "..getItemNameById(toAdd.itemid).." was added to your inventory.")
end
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "There's no item to be collected on your depot.")
end
else
doPlayerSendCancel(cid, "Use the parameters clean or collect.")
end
return true
end
function getPosition(playerPos)
local position = {}
local crossDir = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}
local depotPos, middleItemPos
for i = 1, #depotIDs do
for k, v in pairs(crossDir) do
depotPos = {x = playerPos.x, y = playerPos.y, z = playerPos.z, stackpos = playerPos.stackpos}
depotPos.x = depotPos.x + v[1]
depotPos.y = depotPos.y + v[2]
local depot = getTileItemById(depotPos, depotIDs[i])
if depot.itemid == depotIDs[i] then
depotPos.stackpos = 2
position.depot = {x = depotPos.x, y = depotPos.y, z = depotPos.z, stackpos = depotPos.stackpos}
middleItemPos = {x = depotPos.x, y = depotPos.y, z = depotPos.z, stackpos = depotPos.stackpos}
if playerPos.y ~= depotPos.y then
middleItemPos.x = middleItemPos.x - 1
if getTileItemById(middleItemPos, middleItems[1]).itemid ~= middleItems[1] then
middleItemPos.x = middleItemPos.x + 2
end
elseif playerPos.x ~= depotPos.x then
middleItemPos.y = middleItemPos.y - 1
if getTileItemById(middleItemPos, middleItems[2]).itemid ~= middleItems[2] then
middleItemPos.y = middleItemPos.y + 2
end
end
position.middle = {x = middleItemPos.x, y = middleItemPos.y, z = middleItemPos.z, stackpos = middleItemPos.stackpos}
break
end
end
end
return position
end