• 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+ TFS 1.5 -- -Item count upgrade - as a charge on item

tuduras

Well-Known Member
Joined
Jun 4, 2017
Messages
357
Solutions
2
Reaction score
62
Hello.
How to do item charge as upgrade like in photo:upgrade.webp

I tried with AI to edit my upgrade system and otcv8/modules/game_interface/game_inferface.lua but with no results.
I need this. Has anyone ever done this?

PS: my upgrade system.lua
LUA:
local config = {
    maxLevel = 12,
    upgradeItem = 2150,
    successChance = 100,    -- Szansa na sukces (%)
    dropLevelOnFail = true, -- Czy poziom ma spaść o 1 przy porażce? (true = tak, false = reset do 0)
    multiplierPerLevel = 1.05,
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target or not target:isItem() then
        return false
    end

    local it = target:getType()
    local name = it:getName()
    
    if it:getWeaponType() == WEAPON_NONE and it:getArmor() == 0 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Mozesz ulepszac tylko bron lub pancerze.")
        return true
    end

    local currentLevel = target:getCustomAttribute("upgradeLevel") or 0

    if currentLevel >= config.maxLevel then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "Ten przedmiot osiagnal juz maksymalny poziom.")
        return true
    end

    -- Usunięcie kryształu
    item:remove(1)

    if math.random(100) <= config.successChance then
        -- SUKCES: Poziom w górę
        local nextLevel = currentLevel + 1
        target:setCustomAttribute("upgradeLevel", nextLevel)
        
        local totalMultiplier = math.pow(config.multiplierPerLevel, nextLevel)
        
        -- Aktualizacja statystyk (w górę)
        if it:getAttack() > 0 then target:setAttribute(ITEM_ATTRIBUTE_ATTACK, math.floor(it:getAttack() * totalMultiplier)) end
        if it:getArmor() > 0 then target:setAttribute(ITEM_ATTRIBUTE_ARMOR, math.floor(it:getArmor() * totalMultiplier)) end
        if it:getDefense() > 0 then target:setAttribute(ITEM_ATTRIBUTE_DEFENSE, math.floor(it:getDefense() * totalMultiplier)) end

        target:setAttribute(ITEM_ATTRIBUTE_NAME, name .. " +" .. nextLevel)
        
        -- KLUCZOWA ZMIANA: Ustawiamy ładunki (charges) na poziom ulepszenia
        target:setAttribute(ITEM_ATTRIBUTE_CHARGES, nextLevel)

        player:sendTextMessage(MESSAGE_INFO_DESCR, "Sukces! Twoje " .. name .. " jest teraz na poziomie +" .. nextLevel .. ".")
        target:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    
    else
        -- PORAŻKA: "Spalenie" bonusu (cofnięcie poziomu)
        local penaltyLevel = 0
        if config.dropLevelOnFail then
            penaltyLevel = math.max(0, currentLevel - 1)
        end
        
        target:setCustomAttribute("upgradeLevel", penaltyLevel)
        
        local failMultiplier = math.pow(config.multiplierPerLevel, penaltyLevel)
        
        if it:getAttack() > 0 then target:setAttribute(ITEM_ATTRIBUTE_ATTACK, math.floor(it:getAttack() * failMultiplier)) end
        if it:getArmor() > 0 then target:setAttribute(ITEM_ATTRIBUTE_ARMOR, math.floor(it:getArmor() * failMultiplier)) end
        if it:getDefense() > 0 then target:setAttribute(ITEM_ATTRIBUTE_DEFENSE, math.floor(it:getDefense() * failMultiplier)) end

        if penaltyLevel > 0 then
            target:setAttribute(ITEM_ATTRIBUTE_NAME, name .. " +" .. penaltyLevel)
            -- Ustawiamy niższy poziom w ładunkach
            target:setAttribute(ITEM_ATTRIBUTE_CHARGES, penaltyLevel)
        else
            -- Pełny reset przedmiotu
            target:removeAttribute(ITEM_ATTRIBUTE_ATTACK)
            target:removeAttribute(ITEM_ATTRIBUTE_ARMOR)
            target:removeAttribute(ITEM_ATTRIBUTE_DEFENSE)
            target:removeAttribute(ITEM_ATTRIBUTE_NAME)
            target:removeAttribute(ITEM_ATTRIBUTE_CHARGES)
        end
        
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "Porażka! Bonus zostal spalony. Przedmiot ma teraz poziom +" .. penaltyLevel .. ".")
        target:getPosition():sendMagicEffect(CONST_ME_POFF)
    end

    return true
end

action:id(config.upgradeItem)
action:register()

Of course best regards..
 
This small counter/icon is not just a simple “upgrade item” UI. It is basically the Tier system from Global Tibia.

There is a PR for OTClient Redemption (Mehah) related to this:

But that PR was made for 13.x+ clients, because the client reads this data from appearances.dat, using the classification/tier flag to display the tier icon on the item.

For a custom 8.60 / TFS 1.5 setup, it is possible, but it is not only a game_interface.lua change.

You would need to implement the system on the server side too, adding/adapting functions like getTier() and setTier() in the TFS source. After that, the protocol must be adjusted so the server sends the tier value to the client.

Then the client also needs source changes to receive this value and refresh the item rendering in inventory/container slots, so the tier icon is displayed correctly.

So, in short: this requires source changes on both sides: server and client. It cannot be done properly with Lua only.
 
That’s what I wanted to find out. With AI I'll see what can be done. Thanks for reply. Best regards
Another alternative is to use a Lua/client-side approach, similar to this rarity system:


That system does not require server source changes, because it works through OTClient Lua/UI logic.

You can study that implementation and try to replicate the same idea for tier/count icons. Basically, the client would check the item data and then draw/set an image over the inventory/container slot.

But it will require some work. You would need to handle inventory slots and container items separately, probably with if/else logic for each tier value, for example from tier 1 up to tier 10.

So yes, it is possible to do a custom fake tier icon using Lua only, but it is more of a workaround. The clean/global-like way still requires server + client source changes.

You can also ask your AI to adapt that rarity-frame logic into a tier/count icon system for inventory and containers.
 
Back
Top