Ir para conteúdo
Propaganda

Posts Recomendados

Na pasta creaturescripts, abra creaturescripts.xml e adicione:

<event type="kill" name="AutoLootOnKill" script="autoloot_onkill.lua"/>

Procure por login.lua na pasta de scripts e adicione:

player:registerEvent("AutoLootOnKill")

Crie um arquivo chamado autoloot_onkill.lua na pasta creaturescripts/scrpits e dentro adicione:

local HORI = 3 -- 7 horizontal
local VERT = 2 -- 5 vertical
local LOOT_POUCH_ID = 26377

-- Retorna o container correto (Loot Pouch ou Backpack)
local function getLootContainer(player)
    -- Procura a loot pouch em todo o inventário
    local pouch = player:getItemById(LOOT_POUCH_ID, true)
    if pouch and pouch:isContainer() then
        return pouch
    end

    -- Se não tiver pouch, usa a backpack normal
    return player:getSlotItem(CONST_SLOT_BACKPACK)
end

-- Função para transferir itens do corpo para o container
local function transferLoot(player, container, tile)
    local itensTransferidos = {}

    for i = 0, tile:getThingCount() - 1 do
        local thing = tile:getThing(i)
        if thing and thing:isItem() and thing:isContainer() then
            local name = thing:getName():lower()
            if name:find("slain") then
                for j = thing:getSize() - 1, 0, -1 do
                    local subItem = thing:getItem(j)
                    if subItem then
                        local amount = subItem:getCount()
                        local itemId = subItem:getId()
                        local itemName = subItem:getName()

                        if container:getEmptySlots() > 0 then
                            container:addItem(itemId, amount)
                            itensTransferidos[itemName] = (itensTransferidos[itemName] or 0) + amount
                            subItem:remove()
                        end
                    end
                end
            end
        end
    end

    return itensTransferidos
end

-- Função chamada pelo timer
local function collectLootDelayed(cid, targetPos)
    local player = Player(cid)
    if not player then return end

    local container = getLootContainer(player)
    if not container then return end

    local itensTransferidosTotais = {}

    for dx = -HORI, HORI do
        for dy = -VERT, VERT do
            local tile = Tile({
                x = targetPos.x + dx,
                y = targetPos.y + dy,
                z = targetPos.z
            })

            if tile then
                local itens = transferLoot(player, container, tile)
                for k, v in pairs(itens) do
                    itensTransferidosTotais[k] = (itensTransferidosTotais[k] or 0) + v
                end
            end
        end
    end
end

-- Evento onKill
function onKill(player, target)
    local pos = target:getPosition()
    addEvent(collectLootDelayed, 400, player:getId(), pos) -- delay para o loot gerar
    return true
end

Pronto, agora só reiniciar o servidor ou dar um /reload creaturescripts e ter seu autoloot funcionando.

  • Like 3
Link para o comentário
https://tibiadevs.com/forums/topic/1310-adicionando-autoloot-por-creaturescripts/
Compartilhar em outros sites

  • Filipe Carvalho mudou o título para Adicionando autoloot por creaturescripts

Crie uma conta ou entre para comentar

Você precisar ser um membro para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar Agora
×
  • Criar Novo...