tuduras
Well-Known Member
- Joined
- Jun 4, 2017
- Messages
- 356
- Solutions
- 2
- Reaction score
- 61
Hello.
How to do item charge as upgrade like in photo:
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
Of course best regards..
How to do item charge as upgrade like in photo:

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..