• 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+ Item Reroll rarity TFS 1.3

WikiArk21

Member
Joined
Oct 24, 2023
Messages
23
Reaction score
5
I'm using this system here, which works very well for its purpose.
CreatureEvent - [TFS 1.3 / 1.4] Upgrade System (https://otland.net/threads/tfs-1-3-1-4-upgrade-system.264672/)

However, I tried to create this script to reroll the rarity of a certain item, but I wanted to know if there is any way to have persistence in obtaining a higher rarity. For example, after using the stone x times on that item, the next time it will give the highest rarity available.

Acript

LUA:
local ENCHANTMENT_ITEM_ID = 26427

function onUse(player, usedItem, fromPosition, target, toPosition, isHotkey)
    if usedItem:getId() ~= ENCHANTMENT_ITEM_ID then
        player:sendCancelMessage("This item cannot be used in this way.")
        return false
    end

    if not target or not target:isItem() then
        player:sendCancelMessage("You need to use the stone on an item.")
        return false
    end

    if not isEquipment(target) then
        player:sendCancelMessage("You can only reroll equipment.")
        return false
    end

    target:rollRarity()
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Item rarity has been rerolled!")
    usedItem:remove(1)
    return true
end

function isEquipment(item)
    local itemType = ItemType(item:getId())
    return itemType:getSlotPosition() ~= 0
end
 
You could use usedItem:setCustomAttribute("stones_used", count) to track the stone usage on that item, then check the amount used with usedItem:getCustomAttribute("stones_used")
 
cleared my mind and I had to take a look at the complete upgrade system, thanks for the help. I managed to find the solution and I will leave the script here for anyone who wants to use it.

There is a new feature that if the item already has an enchantment in the slot, it will not be lost, keeping it.



LUA:
local ENCHANTMENT_ITEM_ID = 26427
local MAX_USES_FOR_LEGENDARY = 10

function onUse(player, usedItem, fromPosition, target, toPosition, isHotkey)
    if usedItem:getId() ~= ENCHANTMENT_ITEM_ID then
        player:sendCancelMessage("This item cannot be used in this way.")
        return false
    end

    if not target or not target:isItem() then
        player:sendCancelMessage("You need to use the stone on an item.")
        return false
    end

    if not isEquipment(target) then
        player:sendCancelMessage("You can only reroll equipment.")
        return false
    end

    local count = target:getCustomAttribute("reroll_uses") or 0
    count = count + 1
    target:setCustomAttribute("reroll_uses", count)

    if count >= MAX_USES_FOR_LEGENDARY then
        local legendaryRarityId = #US_CONFIG.RARITY
        target:setRarity(legendaryRarityId)
        target:setCustomAttribute("reroll_uses", 0)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Legendary rarity achieved after " .. MAX_USES_FOR_LEGENDARY .. " enhancements!")
    else
        target:rollRarity()
        local remaining = MAX_USES_FOR_LEGENDARY - count
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE,
            "Rarity rerolled! [" .. count .. "/" .. MAX_USES_FOR_LEGENDARY .. "] enhancements used. " ..
            (remaining > 0 and remaining .. " more to guarantee Legendary." or "")
        )
    end

    usedItem:remove(1)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    return true
end

function isEquipment(item)
    local itemType = ItemType(item:getId())
    return itemType:getSlotPosition() ~= 0
end
 
Back
Top