Amigo tomei á liberdade de formatar o tópico e colocar o Script em Code espero não ter problema.
- Fórum
- OTServ
- Pedidos
- Resolvidos
- [Resolvido] Bloquear item na backpack
info
Grupo: Conde
Registrado: 23/05/17
Posts: 584
Reputação: +113
Gênero: Masculino
Char no Tibia: Não Tenho

19 horas atrás, Fjinst disse:Olá a todos, estou precisando de uma ajuda em criar um script no qual bloqueia os jogadores de colocarem qualquer item dentro de uma backpack especifica.
tentei de algumas maneiras mas a unica coisa que consegui fazer foi para não poder jogar tal item no chão ahuahua
function onMoveItem(moveItem, frompos, position, cid) if moveItem.itemid == 8908 then doPlayerSendTextMessage(cid,25,'Voce nao pode mover este item!') else return true endend
Se alguem puder ajudar, REPP++ ;D
Você já tem essa função adicionada à source né? Tente algo como:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos) if toContainer.itemid == 8908 and toPos.x == CONTAINER_POSITION then doPlayerSendTextMessage(cid, 25, "Você não pode adicionar itens a essa backpack.") return falseendend
info
Grupo: Visconde
Registrado: 26/04/08
Posts: 251
Reputação: +36
Gênero: Masculino
Char no Tibia: Senhor Mithril

3 horas atrás, Leoxtibia disse:
Você já tem essa função adicionada à source né? Tente algo como:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos) if toContainer.itemid == 8908 and toPos.x == CONTAINER_POSITION then doPlayerSendTextMessage(cid, 25, "Você não pode adicionar itens a essa backpack.") return falseendend
Pior que a função que tenho de onMoveItem não é essa, tentei achar ela na internet mas só achei outras versões,
A função que tenho no meu servidor seria essa.
function onMoveItem(moveItem, frompos, position, cid)
@Fjinst A função que eu citei é creaturescripts e tem que ser adicionada na source. Ou, para evitar precisar mexer nas sources, que tal tentarmos algo "meio doido"? Eu pensei em evitar que o player:
1 - Movesse um item de sua backpack para a backpack a ser bloqueada
2 - Colocasse a backpack a ser bloqueada no chão e tentasse mover um item
3 - Colocasse a backpack a ser bloqueada dentro de outro container no chão e tentasse mover um item
Vê aí.
Em creaturescripts/scripts crie o arquivo:
bpBlock.lua
--- (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
No login.lua, registre o evento:
registerCreatureEvent(cid, "BlockBp")
Em creaturescripts.xml, adicione a tag: <event type="think" name="BlockBp" event="script" value="bpBlock.lua"/>
info
Grupo: Visconde
Registrado: 26/04/08
Posts: 251
Reputação: +36
Gênero: Masculino
Char no Tibia: Senhor Mithril

35 minutos atrás, Leoxtibia disse:@Fjinst A função que eu citei é creaturescripts e tem que ser adicionada na source. Ou, para evitar precisar mexer nas sources, que tal tentarmos algo "meio doido"? Eu pensei em evitar que o player:
1 - Movesse um item de sua backpack para a backpack a ser bloqueada
2 - Colocasse a backpack a ser bloqueada no chão e tentasse mover um item
3 - Colocasse a backpack a ser bloqueada dentro de outro container no chão e tentasse mover um item
Vê aí.
Em creaturescripts/scripts crie o arquivo:
bpBlock.lua
--- (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
No login.lua, registre o evento:
registerCreatureEvent(cid, "BlockBp")
Em creaturescripts.xml, adicione a tag: <event type="think" name="BlockBp" event="script" value="bpBlock.lua"/>
Eu dei uma fuçada hoje pela manhã nessas sourcers, acabei conseguindo coloca-las, ahuahuahau, mas de qualquer jeito você ajudou muito
Me tira só uma dúvida, no caso eu uso TFS 0.4 (8.60)
Acabei de descobrir um bug nessas sourcers, quando a Backpack está equipada nas mãos, OU DENTRO DE UM CONTAINER, , ESPADA/ESCUDO a função não é ativada, Tem como bloquear essa bp de ser arrastada para os slots de mão/escudo?, acredito que usando a função de checar slot, mas não to conseguindo pensar em como colocar
local Esquerda = getPlayerSlotItem(cid, CONST_SLOT_RIGHT)
local Direita = getPlayerSlotItem(cid, CONST_SLOT_LEFT)
Editado Agosto 9 por Fjinst
Sim, em movements:
local id = 1111 -- id da bpfunction onEquip(cid, item, slot)if item.itemid == id and (slot == CONST_SLOT_RIGHT or slot == CONST_SLOT_LEFT) thenreturn falseend
<movevent type="Equip" itemid="1111" slot="pickupable" script="NOMEDOSCRIPT.lua"/>
Aproveita e posta aí como ficou seu script do OnMove.
info
Grupo: Visconde
Registrado: 26/04/08
Posts: 251
Reputação: +36
Gênero: Masculino
Char no Tibia: Senhor Mithril

O objetivo disso tudo é criar uma backpack na qual não se pode colocar items, só tirar, e não pode equipa-la,
<movevent type="Equip" itemid="8569" slot="backpack" script="BLOQUEAR.lua"/>
<movevent type="Equip" itemid="8569" slot="pickupable" script="BLOQUEAR.lua"/>
Movements \/
local id = 8569 -- id da bpfunction onEquip(cid, item, slot)if item.itemid == id and (slot == 1 or slot == 2 or slot == 3 or slot == 4 or slot == 5 or slot == 6 or slot == 7 or slot == 8 or slot == 9 or slot == 10 ) thenreturn falseendreturn trueend
Creaturescripts \/
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos) if toContainer.itemid == 8569 and toPos.x == CONTAINER_POSITION then doPlayerSendCancel(cid, "Sorry, is not possible.") return falseendreturn trueend
Agora me tira só uma dúvida, não sei se foi bug de compilação, mas se a backpack estiver dentro do dp, a função do creaturescripts (onmove) não funciona, ela não checa o item dentro do dp, tem como solucionar isso?
Outra dúvida, no talkactions, createitem, tem como colocar para não ser possivel criar essa backpack? por que quando cria ela e seu inventario estiver vazio, crasha o servidor, devido um loop infinito do script de ser possivel equipar ou não.
A minha ideia dessa gambiarra toda é tentar reproduzir aquela reward chest do tibia global, no qual você pode tirar os items mas não pode colocar item dentro dela
Editado Agosto 9 por Fjinst
info
Grupo: Herói
Registrado: 28/11/10
Posts: 3.4k
Reputação: +585
Gênero: Masculino





info
Grupo: Visconde
Registrado: 26/04/08
Posts: 251
Reputação: +36
Gênero: Masculino
Char no Tibia: Senhor Mithril
Olá a todos, estou precisando de uma ajuda em criar um script no qual bloqueia os jogadores de colocarem qualquer item dentro de uma backpack especifica.
tentei de algumas maneiras mas a unica coisa que consegui fazer foi para não poder jogar tal item no chão ahuahua
Se alguem puder ajudar, REPP++ ;D
Editado Agosto 8 por DarkWore
Colocado Code no Script