• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua items sacrificed on the coal

bpm91

Intermediate OT User
Joined
May 23, 2019
Messages
931
Solutions
7
Reaction score
127
Location
Brazil
YouTube
caruniawikibr
I'm trying to make the items on the altars be sacrificed, but it's very complicated, if anyone has a script like this or knows how to solve it.
i use tfs .15


1710355612341.png


Lua:
function onUse(cid, item, frompos, item2, topos)
    -- Definindo as posições iniciais dos altares no mapa
    local altar_positions = {
        {x = 33246, y = 31590, z = 11, altar_id = 1485},
        {x = 33253, y = 31588, z = 11, altar_id = 1486},
        {x = 33260, y = 31590, z = 11, altar_id = 1487},
        {x = 33259, y = 31601, z = 11, altar_id = 1488},
        {x = 33247, y = 31601, z = 11, altar_id = 1489}
    }
    
    -- Definindo as posições iniciais dos itens no mapa
    local item_positions = {
        {x = 33246, y = 31590, z = 11, itemid = 5702},
        {x = 33253, y = 31588, z = 11, itemid = 5703},
        {x = 33260, y = 31590, z = 11, itemid = 5700},
        {x = 33259, y = 31601, z = 11, itemid = 3699},
        {x = 33247, y = 31601, z = 11, itemid = 5701}
    }

    -- Verificar se existem 100 itens em cada altar
local todos_itens_presentes = true
for _, altar_info in ipairs(altar_positions) do
    local altar_items_count = 0
    for _, item_info in ipairs(item_positions) do
        local item_on_altar = getTileItemById({x = altar_info.x, y = altar_info.y, z = altar_info.z, itemid = item_info.itemid})
        altar_items_count = altar_items_count + #item_on_altar
    end
    print("Altar ID:", altar_info.altar_id, "Quantidade de Itens:", altar_items_count)
    if altar_items_count < 100 then
        todos_itens_presentes = false
        break
    end
end
    
    -- Se todos os itens estiverem presentes, realizar as ações
    if todos_itens_presentes then
        -- Remover os itens dos altares
        for _, altar_info in ipairs(altar_positions) do
            local altar_items = getTileItemById({x = altar_info.x, y = altar_info.y, z = altar_info.z, itemid = altar_info.altar_id})
            for _, item in ipairs(altar_items) do
                doRemoveItem(item.uid)
            end
        end
        
        -- Remover os itens de cima dos altares
        for _, item_info in ipairs(item_positions) do
            local item_on_altar = getTileItemById({x = item_info.x, y = item_info.y, z = item_info.z, itemid = item_info.itemid})
            for _, item in ipairs(item_on_altar) do
                doRemoveItem(item.uid)
            end
        end
        
        -- Alterar a alavanca
        doTransformItem(item.uid, 1945)
        
        -- Dar ao jogador o item desejado
        doPlayerAddItem(cid, 2646, 1)
        
        -- Informar ao jogador que a operação foi bem sucedida
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Você realizou o ritual com sucesso!")
    else
        -- Informar ao jogador que a condição não foi atendida
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Você precisa ter 100 itens em cada altar para realizar o ritual.")
    end
end
 
Solution
For anyone wanting the finished script, its here:
Lua:
local config = {
    altars = {
        {x = 32367, y = 32214, z = 7, itemid = 2145, itemcount = 100},
        {x = 32368, y = 32214, z = 7, itemid = 2146, itemcount = 100},
        {x = 32369, y = 32214, z = 7, itemid = 2147, itemcount = 100},
        {x = 32370, y = 32214, z = 7, itemid = 2149, itemcount = 100},
        {x = 32371, y = 32214, z = 7, itemid = 2150, itemcount = 100}
    },
    rewards = {
        {id = 2646, count = 1},
    }
}
    
local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getId() == 1946 then
        item:transform(1945)
        return true
    end
 
    local altarItems = {}
    for _...
Tested it here, and it's working well. Honestly, I wasted my time trying to fix it, haha... But I liked it, and I'm sure I'll use it on my server!!!

Lua:
local altarConfig = {
    altars = {
        {x = 32367, y = 32214, z = 7, itemid = 2145, requiredCount = 100},
        {x = 32368, y = 32214, z = 7, itemid = 2146, requiredCount = 100},
        {x = 32369, y = 32214, z = 7, itemid = 2147, requiredCount = 100},
        {x = 32370, y = 32214, z = 7, itemid = 2149, requiredCount = 100},
        {x = 32371, y = 32214, z = 7, itemid = 2150, requiredCount = 100}
    },
    rewardItemId = 2540, -- Reward item ID
    actionId = 25634, -- Lever Action ID
    lever = {
        used = 1946, -- ID of lever used
        unused = 1945 -- Unused lever ID
    }
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getId() == altarConfig.lever.used then
        item:transform(altarConfig.lever.unused)
        return true
    end

    local allItemsCorrect = true
    for _, altar in pairs(altarConfig.altars) do
        local altarTile = Tile(altar.x, altar.y, altar.z)
        if altarTile then
            local altarItem = altarTile:getTopVisibleThing()

            if not altarItem or not altarItem:isItem() or altarItem:getId() ~= altar.itemid or altarItem:getCount() < altar.requiredCount then
                allItemsCorrect = false
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Você precisa ter 100 itens em cada altar para realizar o ritual.")
                break
            end
        else
            allItemsCorrect = false
            break
        end
    end

    if allItemsCorrect then
        for _, altar in pairs(altarConfig.altars) do
            local altarTile = Tile(altar.x, altar.y, altar.z)
            local altarItem = altarTile:getTopVisibleThing()
            altarItem:remove(altar.requiredCount)
        end

        player:addItem(altarConfig.rewardItemId, 1)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Você realizou o ritual com sucesso!")
    end

    item:transform(altarConfig.lever.used)
    return true
end

action:aid(altarConfig.actionId)
action:register()
 
Back
Top