O objetivo da função é remover varios itens com diferentes quantidades de um sqm, se remover todos retorna true, caso contrario false:
function doRemoveItemsFromPos(pos, items, quants) -- by MatheusMkalo items = type(items) == "table" and items or {items} local positems = {} local stat = false local quantss = {} local itemss = {} for i,x in ipairs(items) do if not isItemStackable(x) then for s = 1, quants[i] do table.insert(itemss, x) table.insert(quantss, 1) end else table.insert(itemss, x) table.insert(quantss, quants[i]) end end quants = quantss items = itemss local needitems = #items for i = 1,254 do pos.stackpos = i if table.find(items, getThingFromPos(pos).itemid) and (not quants or getThingFromPos(pos).type >= quants[table.find(items, getThingFromPos(pos).itemid)] or (getThingFromPos(pos).type == 0 and quants[table.find(items, getThingFromPos(pos).itemid)] == 1)) then local a = table.find(items, getThingFromPos(pos).itemid) table.insert(positems, {getThingFromPos(pos), quants[a]}) table.remove(quants, a) table.remove(items, a) end if #positems == needitems and #items == 0 then stat = true break end end if stat then for i,x in pairs(positems) do doRemoveItem(x[1].uid, x[2]) end return true end return false end
Parametros:
- pos - Posição do sqm que vai ser removido os itens.
- items - Table com os ids dos items que serão removidos
- quants (opcional) - Quantidades diretamente proporcionais aos ids.
Exemplo de uso:
if doRemoveItemsFromPos({x=1000, y=1000, z=7}, {2472, 2494, 2160}, {1, 1, 50}) then doPlayerSendTextMessage(cid, 21, "Parabens") else doPlayerSendTextMessage(cid, 21, "Não tem os items nescessarios na pos.") end
Como voces podem ver a table dos ids {2472, 2494, 2160} e suas quantidades {1, 1, 50}
2160 = Crystal Coin, ou seja precisam ter 50 crystal coins na pos.
Obs: A Quantidade maior que 1 funciona em qualquer item, agrupavel ou nao. Se voce botar a quantidade de um item agrupavel maior que 100 nao ira funcionar. Em breve funcionara.