• 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!

TFS 1.X+ Imbuing system --tfs 1.5 -- tibia 8.60

tuduras

Well-Known Member
Joined
Jun 4, 2017
Messages
351
Solutions
2
Reaction score
59
Hello , how are U?

I have got imbu script :
LUA:
local ImbuingSystem = Action()

-- Requisitos para cada nivel de imbuimiento
local ImbuingNivel = {
    [1] = {crystalCoins = 100, successRate = 100},
    [2] = {crystalCoins = 200, successRate = 100},
    [3] = {crystalCoins = 300, successRate = 100},
    [4] = {crystalCoins = 400, successRate = 100},
    [5] = {crystalCoins = 500, successRate = 100},
    [6] = {crystalCoins = 600, successRate = 100},
    [7] = {crystalCoins = 700, successRate = 100},
    [8] = {crystalCoins = 800, successRate = 100},
    [9] = {crystalCoins = 900, successRate = 100},
    [10] = {crystalCoins = 1000, successRate = 100},
}

-- Definición de IDs para imbuimientos
local ImbuingIDs = {
    [2178] = "weapon",   -- Critical Chance
    [7761] = "helmet",   -- Life Leech
    [7762] = "armor",    -- Mana Leech
    [7760] = "boots",    -- Health/Mana Regen
    [2174] = "backpack", -- Extra Capacity
    [7759] = "shield",   -- Damage Absorb
    [2144] = "legs"      -- Speed
}

-- Definición de IDs para tipos de ítems
local ItemCategories = {
    weapon = {2400, 2453, 6528, 5803, 2431, 2444, 7366, 7958},
    helmet = {2493, 3972, 11302},
    armor = {8890, 8881, 8888, 2505, 12657},
    boots = {2195, 12646},
    backpack = {1987, 1988},
    shield = {2533, 2534},
    legs = {2466, 2467}
}

-- Determina el tipo de ítem basado en su ID
local function determineItemType(itemId)
    for type, ids in pairs(ItemCategories) do
        for _, id in ipairs(ids) do
            if id == itemId then
                return type
            end
        end
    end
    return "unknown"
end

-- Función para obtener el texto de bonus basado en el tipo de ítem y el nivel
local function getBonusText(itemType, tier)
    local bonusText = ""
    if itemType == "weapon" then
        bonusText = string.format("Critical Chance: %d%%", tier)
    elseif itemType == "helmet" then
        bonusText = string.format("Life Leech: %d%%", tier * 10)
    elseif itemType == "armor" then
        bonusText = string.format("Mana Leech: %d%%", tier * 10)
    elseif itemType == "boots" then
        bonusText = string.format("Health/Mana Regen: %d", tier * 10)
    elseif itemType == "backpack" then
        bonusText = string.format("Extra Capacity: %d%%", tier * 2)
    elseif itemType == "shield" then
        bonusText = string.format("Damage Absorb: %d%%", tier * 10)
    elseif itemType == "legs" then
        bonusText = string.format("Speed: %d%%", tier * 2)
    end
    return bonusText
end

function ImbuingSystem.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local imbuingId = item:getId()
    local targetItem = target
    
    if not targetItem or not targetItem:isItem() then
        return false
    end

    local currentDescription = targetItem:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) or ""
    local tierCheck = tonumber(currentDescription:match("Tier %((%d+)%)"))
    local itemType = determineItemType(targetItem:getId())

    -- Verifica si el ítem de imbuimiento es aplicable
    if ImbuingIDs[imbuingId] == itemType then
        local maxTier = 10
        if tierCheck == nil or (tierCheck >= 0 and tierCheck < maxTier) then
            local tier = (tierCheck or 0) + 1
            local required = ImbuingNivel[tier]

            if required then
                local playerCrystalCoins = player:getItemCount(2160)

                if playerCrystalCoins >= required.crystalCoins then
                    local successChance = required.successRate
                    if math.random(1, 100) <= successChance then
                        -- Sukces
                        player:removeItem(2160, required.crystalCoins)
                        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The item has been imbued successfully to Tier (" .. tier .. ").")
                        player:getPosition():sendMagicEffect(CONST_ME_ENERGY_HIT)

                        local bonusText = getBonusText(itemType, tier)
                        local newDescription = ""

                        -- POPRAWKA AKTUALIZACJI OPISU
                        if currentDescription:lower():find("tier") then
                            -- Aktualizujemy numer Tieru
                            newDescription = currentDescription:gsub("Tier %((%d+)%)", "Tier (" .. tier .. ")")
                            
                            -- Wyciągamy nazwę bonusu (np. "Life Leech") i aktualizujemy jego wartość
                            local bonusName = bonusText:match("^(.-):")
                            if bonusName then
                                -- Szuka wzoru "Nazwa Bonusu: wartość%" i zamienia na nowy bonusText
                                newDescription = newDescription:gsub(bonusName .. ": [%.%d]+%%?", bonusText)
                            end
                        else
                            -- Jeśli to pierwsze ulepszenie
                            newDescription = "Tier (" .. tier .. "). " .. bonusText
                        end

                        targetItem:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, newDescription)
                        player:removeItem(imbuingId, 1)
                    else
                        -- Porażka
                        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The imbuing failed. The item remains unchanged.")
                        player:getPosition():sendMagicEffect(CONST_ME_POFF)
                    end
                else
                    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need " .. required.crystalCoins .. " Crystal Coins to perform this imbuing.")
                end
            end
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your item already has the maximum level of imbuement.")
        end
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This imbuing stone cannot be used on this type of item.")
    end

    return true
end

-- Rejestracja wszystkich ID kamieni
local stones = {2178, 3027, 3028, 3029, 7762, 7760, 7761, 2174, 7759, 2144}
for _, id in ipairs(stones) do
    ImbuingSystem:id(id)
end
ImbuingSystem:register()

-- MoveEvent
local EquipEvent = MoveEvent()
function EquipEvent.onEquip(player, item, position, fromPosition)
    if not player or player:isInGhostMode() then
        return true
    end
    return true
end
EquipEvent:id(2178)
EquipEvent:register()

and i got imbu on item but it doesn't renew. look at screen imbumana.webp


I noticed on paladin works hp mp leech , on druid doesn't work.
hpmana.webp

how to solve it ? thanks and best regards
 
Your script is only changing the item description. This line:

LUA:
targetItem:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, newDescription)

does not give the item real life leech / mana leech. It only prints text on the item.

If your TFS 1.5 downgrade has the special skill attributes, add the real attributes to the item in items.xml, then register the item in movements.xml.

Example:

XML:
<item id="XXXX" name="your item">
    <attribute key="lifeleechchance" value="100" />
    <attribute key="lifeleechamount" value="10" />
    <attribute key="manaleechchance" value="100" />
    <attribute key="manaleechamount" value="10" />
</item>

And movements:

XML:
<movevent event="Equip" itemid="XXXX" slot="armor" function="onEquipItem" />
<movevent event="DeEquip" itemid="XXXX" slot="armor" function="onDeEquipItem" />

Also, in your script you register these stones:

LUA:
local stones = {2178, 3027, 3028, 3029, 7762, 7760, 7761, 2174, 7759, 2144}

but your ImbuingIDs table does not contain 3027, 3028 or 3029, so those stones will always fail this check:

LUA:
if ImbuingIDs[imbuingId] == itemType then

Either remove them from stones, or add them properly:

LUA:
local ImbuingIDs = {
    [2178] = "weapon",
    [3027] = "weapon", -- change this to the correct category
    [3028] = "helmet", -- change this to the correct category
    [3029] = "armor",  -- change this to the correct category
    [7761] = "helmet",
    [7762] = "armor",
    [7760] = "boots",
    [2174] = "backpack",
    [7759] = "shield",
    [2144] = "legs"
}

If leech works for paladin but not druid, the leech code is probably only being applied in weapon/ranged attacks. Druid damage mostly comes from spells, so you need to apply the leech in combat/onHealthChange too, or use the native special skill attributes if your source supports them.
 

Similar threads

Back
Top