--- (DontMoveToBp) Credits: Leoxtibia
local id = 2001 -- id da backpack a ser bloqueada
function onThink(cid, interval)
if not isPlayer(cid) then return true end
if #getAllBps(cid, id) > 0 then
for i, v in ipairs(getAllBps(cid, id)) do
local itns = getContainerItem(v, 0)
if itns.uid ~= 0 then
doPlayerAddItem(cid, itns.itemid, itns.type)
doRemoveItem(itns.uid)
doPlayerSendCancel(cid, "You can't add items inside this backpack.")
end
end
end
DontAddInto(cid, id)
end
function getAllBps(cid, id)
local allBps, p = {}, getPlayerPosition(cid)
for i = -1, 1 do
for j = -1, 1 do
pos = {x = p.x+i, y=p.y+j, z = p.z}
for _, v in pairs(checkItemsOnFloorContainer(cid, id, pos)) do
table.insert(allBps, v.uid)
end
local check_floor = getTileItemById(pos, id)
if check_floor.uid > 0 then
table.insert(allBps, check_floor.uid)
end
end
end
return allBps
end
function checkItemsOnFloorContainer(cid, id, pos)
local backpacks = {}
local check = false
for i = 0, 255 do
pos.stackpos = i
tile = getTileThingByPos(pos)
if tile.uid > 0 and isContainer(tile.uid) then
check = true break
end
end
if check == true then
local items = getContainerItems(tile.uid)
for i,x in pairs(items) do
if id == tonumber(x.itemid) then
table.insert(backpacks, x)
end
end
end
return backpacks
end
function getContainerItems(containeruid)
local items = {}
local containers = {}
if type(getContainerSize(containeruid)) ~= "number" then
return false
end
for slot = 0, getContainerSize(containeruid)-1 do
local item = getContainerItem(containeruid, slot)
if item.itemid == 0 then
break
end
if isContainer(item.uid) then
table.insert(containers, item.uid)
end
table.insert(items, item)
end
if #containers > 0 then
for i,x in ipairs(getContainerItems(containers[1])) do
table.insert(items, x)
end
table.remove(containers, 1)
end
return items
end
function DontAddInto(cid, id)
local bps = {}
if getPlayerItemCount(cid, id) == 0 then
return true
end
for _, item in pairs(getAllItemsById(cid, id)) do
table.insert(bps, item.uid)
end
if #bps > 0 then
for i, v in ipairs(bps) do
local itns = getContainerItem(v, 0)
if itns.uid ~= 0 then
doRemoveItem(itns.uid)
doPlayerAddItem(cid, itns.itemid, itns.type)
doPlayerSendCancel(cid, "You can't add items inside this backpack.")
end
end
end
end
function getAllItemsById(cid, id)
local containers = {}
local items = {}
for i = CONST_SLOT_FIRST, CONST_SLOT_LAST do
local sitem = getPlayerSlotItem(cid, i)
if sitem.uid > 0 then
if isContainer(sitem.uid) then
table.insert(containers, sitem.uid)
if not(id) or id == sitem.itemid then table.insert(items, sitem) end
elseif not(id) or id == sitem.itemid then
table.insert(items, sitem)
end
end
end
while #containers > 0 do
for k = (getContainerSize(containers[1]) - 1), 0, -1 do
local tmp = getContainerItem(containers[1], k)
if isContainer(tmp.uid) then
table.insert(containers, tmp.uid)
if not(id) or id == tmp.itemid then table.insert(items, tmp) end
elseif not(id) or id == tmp.itemid then
table.insert(items, tmp)
end
end
table.remove(containers, 1)
end
return items
end