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

Solved TFS 1.5, OT Client Redemption: Upgrade table help

eardrums

Member
Joined
May 27, 2010
Messages
101
Solutions
1
Reaction score
11
Hello everyone,

So I made a script for an upgrade table using modal windows in my server and it worked fine. The issue came when I tried to upgrade my bag because it removed my bag and all the items that were in it. I realized that I had done the script wrong because I had it set to remove the item then add it again instead of transform. Now im trying to fix it and have it transform the items but it wont work and keeps bugging out. Im not good at all at coding and I use a lot of AI so I would love it if someone could show me the error of my ways. Here is the script that im trying to get working:
Code:
-- Utility function to check if player has an item with a given ID and count
local function playerHasItem(player, itemId, count)
    return player:getItemCount(itemId) >= count
end

-- Utility function to remove an item from player's backpack
local function removeItemFromPlayer(player, itemId, count)
    player:removeItem(itemId, count)
end

local function upgradeGear(player, baseItemId, newItemId, requiredItems)
    -- Check if player has the base item
    if not playerHasItem(player, baseItemId, 1) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You do not have the base item required to upgrade your gear.")
        return
    end

    -- Check if player has all required items
    for _, item in ipairs(requiredItems) do
        if not playerHasItem(player, item.id, item.count) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You do not have the required materials to upgrade your gear.")
            return
        end
    end

    -- Remove the required items from player
    for _, item in ipairs(requiredItems) do
        removeItemFromPlayer(player, item.id, item.count)
    end

    -- Transform the base item into the new item
    local baseItem = player:getItemById(baseItemId)
    if baseItem then
        baseItem:transform(newItemId)
        player:getPosition():sendMagicEffect(CONST_ME_PURPLEENERGY)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have successfully upgraded your gear.")
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Failed to find the base item in your inventory.")
    end
end



local function showUpgradeMenu(player, modalWindowId, title, message, choices)
    local window = ModalWindow(modalWindowId, title, message)

    window:addButton(100, "Confirm")
    window:addButton(101, "Cancel")

    for i, choice in ipairs(choices) do
        window:addChoice(i, choice)
    end

    window:setDefaultEnterButton(100)
    window:setDefaultEscapeButton(101)
    window:sendToPlayer(player)
end

local function handleUpgradeChoice(player, choiceId, upgradeMap)
    if upgradeMap[choiceId] then
        local upgradeData = upgradeMap[choiceId]
        upgradeGear(player, upgradeData.baseItemId, upgradeData.newItemId, upgradeData.requiredItems)
    end
end

-- Map of upgrade choices for each vocation and gear type
local hunterGearUpgrades = {
    helmet = {
        [1] = { baseItemId = 49148, newItemId = 49203, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49203, newItemId = 49204, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49204, newItemId = 49205, requiredItems = {{id = 48908, count = 30}}},
    },
    armor = {
        [1] = { baseItemId = 49152, newItemId = 49216, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49216, newItemId = 49217, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49217, newItemId = 49218, requiredItems = {{id = 48908, count = 30}}},
    },
    legs = {
        [1] = { baseItemId = 49149, newItemId = 49206, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49206, newItemId = 49207, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49207, newItemId = 49208, requiredItems = {{id = 48908, count = 30}}},
    },
    boots = {
        [1] = { baseItemId = 49147, newItemId = 49200, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49200, newItemId = 49201, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49201, newItemId = 49202, requiredItems = {{id = 48908, count = 30}}},
    },
    shield = {
        [1] = { baseItemId = 49151, newItemId = 49213, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49213, newItemId = 49214, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49214, newItemId = 49215, requiredItems = {{id = 48908, count = 30}}},
    },
    ring = {
        [1] = { baseItemId = 49209, newItemId = 49210, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49210, newItemId = 49211, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49211, newItemId = 49212, requiredItems = {{id = 48908, count = 30}}},
    },
    amulet = {
        [1] = { baseItemId = 49143, newItemId = 49156, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49156, newItemId = 49157, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49157, newItemId = 49158, requiredItems = {{id = 48908, count = 30}}},
    },
    bag = {
        [1] = { baseItemId = 49145, newItemId = 49153, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49153, newItemId = 49198, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49198, newItemId = 49199, requiredItems = {{id = 48908, count = 30}}},
    },
}

local mageGearUpgrades = {
    helmet = {
        [1] = { baseItemId = 49148, newItemId = 49162, requiredItems = {{id = 12403, count = 10},}},
        [2] = { baseItemId = 49162, newItemId = 49163, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49163, newItemId = 49164, requiredItems = {{id = 48908, count = 30}}},
    },
and so on...

-- Main function to handle onUse event
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    player:registerEvent("gear menu")

    local choices = {"Hunter", "Mage", "Warrior"}
    showUpgradeMenu(player, 1010, "Vocation Menu", "Select the vocation for which you want to upgrade gear.", choices)
    return true
end

-- Modal window event handler
function onModalWindow(player, modalWindowId, buttonId, choiceId)
    if buttonId == 101 then
player:unregisterEvent("gear menu")
    return
    end

    if modalWindowId == 1010 then
        if choiceId == 1 then showUpgradeMenu(player, 1011, "Hunter Gear Menu", "Select the gear type you would like to upgrade.", {"Helmet", "Armor", "Legs", "Boots", "Shield", "Ring", "Amulet", "Bag"}) end
        if choiceId == 2 then showUpgradeMenu(player, 1012, "Mage Gear Menu", "Select the gear type you would like to upgrade.", {"Helmet", "Armor", "Legs", "Boots", "Shield", "Ring", "Amulet", "Bag"}) end
        if choiceId == 3 then showUpgradeMenu(player, 1013, "Warrior Gear Menu", "Select the gear type you would like to upgrade.", {"Helmet", "Armor", "Legs", "Boots", "Shield", "Ring", "Amulet", "Bag"}) end
    elseif modalWindowId == 1011 then
        if choiceId == 1 then showUpgradeMenu(player, 1014, "Hunter Helmet Upgrade", "Select the tier you would like to upgrade to.                                                                   ", {"(Journeyman) Requires 10x normal stones, 1x apprentice helmet.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman helmet.", "(Worldbreaker) Requires 30x warden stones, 1x champion helmet."}) end
        if choiceId == 2 then showUpgradeMenu(player, 1015, "Hunter Armor Upgrade", "Select the tier you would like to upgrade to.                                                                   ", {"(Journeyman) Requires 10x normal stones, 1x apprentice armor.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman armor.", "(Worldbreaker) Requires 30x warden stones, 1x champion armor."}) end
        if choiceId == 3 then showUpgradeMenu(player, 1016, "Hunter Legs Upgrade", "Select the tier you would like to upgrade to.                                                                   ", {"(Journeyman) Requires 10x normal stones, 1x apprentice legs.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman legs.", "(Worldbreaker) Requires 30x warden stones, 1x champion legs."}) end
        if choiceId == 4 then showUpgradeMenu(player, 1017, "Hunter Boots Upgrade", "Select the tier you would like to upgrade to.                                                                   ", {"(Journeyman) Requires 10x normal stones, 1x apprentice boots.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman boots.", "(Worldbreaker) Requires 30x warden stones, 1x champion boots."}) end
        if choiceId == 5 then showUpgradeMenu(player, 1018, "Hunter Shield Upgrade", "Select the tier you would like to upgrade to.                                                                   ", {"(Journeyman) Requires 10x normal stones, 1x apprentice shield.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman shield.", "(Worldbreaker) Requires 30x warden stones, 1x champion shield."}) end
        if choiceId == 6 then showUpgradeMenu(player, 1019, "Hunter Ring Upgrade", "Select the tier you would like to upgrade to.                                                                   ", {"(Journeyman) Requires 10x normal stones, 1x apprentice ring.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman ring.", "(Worldbreaker) Requires 30x warden stones, 1x champion ring."}) end
and so on..
    elseif modalWindowId == 1014 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.helmet)
    elseif modalWindowId == 1015 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.armor)
    elseif modalWindowId == 1016 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.legs)
    elseif modalWindowId == 1017 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.boots)
    elseif modalWindowId == 1018 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.shield)
    elseif modalWindowId == 1019 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.ring)
    elseif modalWindowId == 1020 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.amulet)
    elseif modalWindowId == 1021 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.bag)
    elseif modalWindowId == 1022 then
        handleUpgradeChoice(player, choiceId, mageGearUpgrades.helmet)
    elseif modalWindowId == 1023 then
        handleUpgradeChoice(player, choiceId, mageGearUpgrades.armor)
    elseif modalWindowId == 1024 then
        handleUpgradeChoice(player, choiceId, mageGearUpgrades.legs)
and so on..
    end
end

I pretty sure that its and easy fix for any decent programmer. this is a shortened version to fit the character cap. anyways would love an assist. thanks!
 
I also asked AI, I haven't tried it.

Transform item instead of removing and adding:
The upgradeGear function now uses baseItem:transform(newItemId) instead of removing the base item and adding the new one. This preserves the contents of containers like bags.

LUA:
-- Utility function to check if player has an item with a given ID and count
local function playerHasItem(player, itemId, count)
    return player:getItemCount(itemId) >= count
end

-- Utility function to remove an item from player's backpack
local function removeItemFromPlayer(player, itemId, count)
    player:removeItem(itemId, count)
end

local function upgradeGear(player, baseItemId, newItemId, requiredItems)
    -- Check if player has the base item
    if not playerHasItem(player, baseItemId, 1) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You do not have the base item required to upgrade your gear.")
        return
    end

    -- Check if player has all required items
    for _, item in ipairs(requiredItems) do
        if not playerHasItem(player, item.id, item.count) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You do not have the required materials to upgrade your gear.")
            return
        end
    end

    -- Remove the required items from player
    for _, item in ipairs(requiredItems) do
        removeItemFromPlayer(player, item.id, item.count)
    end

    -- Transform the base item into the new item
    local baseItem = player:getItemById(baseItemId)
    if baseItem then
        baseItem:transform(newItemId)
        player:getPosition():sendMagicEffect(CONST_ME_PURPLEENERGY)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have successfully upgraded your gear.")
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Failed to find the base item in your inventory.")
    end
end

local function showUpgradeMenu(player, modalWindowId, title, message, choices)
    local window = ModalWindow(modalWindowId, title, message)

    window:addButton(100, "Confirm")
    window:addButton(101, "Cancel")

    for i, choice in ipairs(choices) do
        window:addChoice(i, choice)
    end

    window:setDefaultEnterButton(100)
    window:setDefaultEscapeButton(101)
    window:sendToPlayer(player)
end

local function handleUpgradeChoice(player, choiceId, upgradeMap)
    if upgradeMap[choiceId] then
        local upgradeData = upgradeMap[choiceId]
        upgradeGear(player, upgradeData.baseItemId, upgradeData.newItemId, upgradeData.requiredItems)
    end
end

-- Map of upgrade choices for each vocation and gear type
local hunterGearUpgrades = {
    helmet = {
        [1] = { baseItemId = 49148, newItemId = 49203, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49203, newItemId = 49204, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49204, newItemId = 49205, requiredItems = {{id = 48908, count = 30}}},
    },
    armor = {
        [1] = { baseItemId = 49152, newItemId = 49216, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49216, newItemId = 49217, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49217, newItemId = 49218, requiredItems = {{id = 48908, count = 30}}},
    },
    legs = {
        [1] = { baseItemId = 49149, newItemId = 49206, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49206, newItemId = 49207, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49207, newItemId = 49208, requiredItems = {{id = 48908, count = 30}}},
    },
    boots = {
        [1] = { baseItemId = 49147, newItemId = 49200, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49200, newItemId = 49201, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49201, newItemId = 49202, requiredItems = {{id = 48908, count = 30}}},
    },
    shield = {
        [1] = { baseItemId = 49151, newItemId = 49213, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49213, newItemId = 49214, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49214, newItemId = 49215, requiredItems = {{id = 48908, count = 30}}},
    },
    ring = {
        [1] = { baseItemId = 49209, newItemId = 49210, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49210, newItemId = 49211, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49211, newItemId = 49212, requiredItems = {{id = 48908, count = 30}}},
    },
    amulet = {
        [1] = { baseItemId = 49143, newItemId = 49156, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49156, newItemId = 49157, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49157, newItemId = 49158, requiredItems = {{id = 48908, count = 30}}},
    },
    bag = {
        [1] = { baseItemId = 49145, newItemId = 49153, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49153, newItemId = 49198, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49198, newItemId = 49199, requiredItems = {{id = 48908, count = 30}}},
    },
}

local mageGearUpgrades = {
    helmet = {
        [1] = { baseItemId = 49148, newItemId = 49162, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49162, newItemId = 49163, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49163, newItemId = 49164, requiredItems = {{id = 48908, count = 30}}},
    },
    -- Continue for other mage gear types
}

-- Main function to handle onUse event
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    player:registerEvent("gear menu")

    local choices = {"Hunter", "Mage", "Warrior"}
    showUpgradeMenu(player, 1010, "Vocation Menu", "Select the vocation for which you want to upgrade gear.", choices)
    return true
end

-- Modal window event handler
function onModalWindow(player, modalWindowId, buttonId, choiceId)
    if buttonId == 101 then
        player:unregisterEvent("gear menu")
        return
    end

    if modalWindowId == 1010 then
        if choiceId == 1 then showUpgradeMenu(player, 1011, "Hunter Gear Menu", "Select the gear type you would like to upgrade.", {"Helmet", "Armor", "Legs", "Boots", "Shield", "Ring", "Amulet", "Bag"}) end
        if choiceId == 2 then showUpgradeMenu(player, 1012, "Mage Gear Menu", "Select the gear type you would like to upgrade.", {"Helmet", "Armor", "Legs", "Boots", "Shield", "Ring", "Amulet", "Bag"}) end
        if choiceId == 3 then showUpgradeMenu(player, 1013, "Warrior Gear Menu", "Select the gear type you would like to upgrade.", {"Helmet", "Armor", "Legs", "Boots", "Shield", "Ring", "Amulet", "Bag"}) end
    elseif modalWindowId == 1011 then
        if choiceId == 1 then showUpgradeMenu(player, 1014, "Hunter Helmet Upgrade", "Select the tier you would like to upgrade to.", {"(Journeyman) Requires 10x normal stones, 1x apprentice helmet.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman helmet.", "(Worldbreaker) Requires 30x warden stones, 1x champion helmet."}) end
        if choiceId == 2 then showUpgradeMenu(player, 1015, "Hunter Armor Upgrade", "Select the tier you would like to upgrade to.", {"(Journeyman) Requires 10x normal stones, 1x apprentice armor.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman armor.", "(Worldbreaker) Requires 30x warden stones, 1x champion armor."}) end
        if choiceId == 3 then showUpgradeMenu(player, 1016, "Hunter Legs Upgrade", "Select the tier you would like to upgrade to.", {"(Journeyman) Requires 10x normal stones, 1x apprentice legs.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman legs.", "(Worldbreaker) Requires 30x warden stones, 1x champion legs."}) end
        if choiceId == 4 then showUpgradeMenu(player, 1017, "Hunter Boots Upgrade", "Select the tier you would like to upgrade to.", {"(Journeyman) Requires 10x normal stones, 1x apprentice boots.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman boots.", "(Worldbreaker) Requires 30x warden stones, 1x champion boots."}) end
        if choiceId == 5 then showUpgradeMenu(player, 1018, "Hunter Shield Upgrade", "Select the tier you would like to upgrade to.", {"(Journeyman) Requires 10x normal stones, 1x apprentice shield.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman shield.", "(Worldbreaker) Requires 30x warden stones, 1x champion shield."}) end
        if choiceId == 6 then showUpgradeMenu(player, 1019, "Hunter Ring Upgrade", "Select the tier you would like to upgrade to.", {"(Journeyman) Requires 10x normal stones, 1x apprentice ring.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman ring.", "(Worldbreaker) Requires 30x warden stones, 1x champion ring."}) end
        -- Continue for other gear types
    elseif modalWindowId == 1014 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.helmet)
    elseif modalWindowId == 1015 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.armor)
    elseif modalWindowId == 1016 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.legs)
    elseif modalWindowId == 1017 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.boots)
    elseif modalWindowId == 1018 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.shield)
    elseif modalWindowId == 1019 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.ring)
    elseif modalWindowId == 1020 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.amulet)
    elseif modalWindowId == 1021 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.bag)
    elseif modalWindowId == 1022 then
        handleUpgradeChoice(player, choiceId, mageGearUpgrades.helmet)
    elseif modalWindowId == 1023 then
        handleUpgradeChoice(player, choiceId, mageGearUpgrades.armor)
    elseif modalWindowId == 1024 then
        handleUpgradeChoice(player, choiceId, mageGearUpgrades.legs)
        -- Continue for other modal windows
    end
end
Hello everyone,

So I made a script for an upgrade table using modal windows in my server and it worked fine. The issue came when I tried to upgrade my bag because it removed my bag and all the items that were in it. I realized that I had done the script wrong because I had it set to remove the item then add it again instead of transform. Now im trying to fix it and have it transform the items but it wont work and keeps bugging out. Im not good at all at coding and I use a lot of AI so I would love it if someone could show me the error of my ways. Here is the script that im trying to get working:
Code:
-- Utility function to check if player has an item with a given ID and count
local function playerHasItem(player, itemId, count)
    return player:getItemCount(itemId) >= count
end

-- Utility function to remove an item from player's backpack
local function removeItemFromPlayer(player, itemId, count)
    player:removeItem(itemId, count)
end

local function upgradeGear(player, baseItemId, newItemId, requiredItems)
    -- Check if player has the base item
    if not playerHasItem(player, baseItemId, 1) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You do not have the base item required to upgrade your gear.")
        return
    end

    -- Check if player has all required items
    for _, item in ipairs(requiredItems) do
        if not playerHasItem(player, item.id, item.count) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You do not have the required materials to upgrade your gear.")
            return
        end
    end

    -- Remove the required items from player
    for _, item in ipairs(requiredItems) do
        removeItemFromPlayer(player, item.id, item.count)
    end

    -- Transform the base item into the new item
    local baseItem = player:getItemById(baseItemId)
    if baseItem then
        baseItem:transform(newItemId)
        player:getPosition():sendMagicEffect(CONST_ME_PURPLEENERGY)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have successfully upgraded your gear.")
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Failed to find the base item in your inventory.")
    end
end



local function showUpgradeMenu(player, modalWindowId, title, message, choices)
    local window = ModalWindow(modalWindowId, title, message)

    window:addButton(100, "Confirm")
    window:addButton(101, "Cancel")

    for i, choice in ipairs(choices) do
        window:addChoice(i, choice)
    end

    window:setDefaultEnterButton(100)
    window:setDefaultEscapeButton(101)
    window:sendToPlayer(player)
end

local function handleUpgradeChoice(player, choiceId, upgradeMap)
    if upgradeMap[choiceId] then
        local upgradeData = upgradeMap[choiceId]
        upgradeGear(player, upgradeData.baseItemId, upgradeData.newItemId, upgradeData.requiredItems)
    end
end

-- Map of upgrade choices for each vocation and gear type
local hunterGearUpgrades = {
    helmet = {
        [1] = { baseItemId = 49148, newItemId = 49203, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49203, newItemId = 49204, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49204, newItemId = 49205, requiredItems = {{id = 48908, count = 30}}},
    },
    armor = {
        [1] = { baseItemId = 49152, newItemId = 49216, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49216, newItemId = 49217, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49217, newItemId = 49218, requiredItems = {{id = 48908, count = 30}}},
    },
    legs = {
        [1] = { baseItemId = 49149, newItemId = 49206, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49206, newItemId = 49207, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49207, newItemId = 49208, requiredItems = {{id = 48908, count = 30}}},
    },
    boots = {
        [1] = { baseItemId = 49147, newItemId = 49200, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49200, newItemId = 49201, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49201, newItemId = 49202, requiredItems = {{id = 48908, count = 30}}},
    },
    shield = {
        [1] = { baseItemId = 49151, newItemId = 49213, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49213, newItemId = 49214, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49214, newItemId = 49215, requiredItems = {{id = 48908, count = 30}}},
    },
    ring = {
        [1] = { baseItemId = 49209, newItemId = 49210, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49210, newItemId = 49211, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49211, newItemId = 49212, requiredItems = {{id = 48908, count = 30}}},
    },
    amulet = {
        [1] = { baseItemId = 49143, newItemId = 49156, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49156, newItemId = 49157, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49157, newItemId = 49158, requiredItems = {{id = 48908, count = 30}}},
    },
    bag = {
        [1] = { baseItemId = 49145, newItemId = 49153, requiredItems = {{id = 12403, count = 10}}},
        [2] = { baseItemId = 49153, newItemId = 49198, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49198, newItemId = 49199, requiredItems = {{id = 48908, count = 30}}},
    },
}

local mageGearUpgrades = {
    helmet = {
        [1] = { baseItemId = 49148, newItemId = 49162, requiredItems = {{id = 12403, count = 10},}},
        [2] = { baseItemId = 49162, newItemId = 49163, requiredItems = {{id = 44068, count = 10}, {id = 44071, count = 10}}},
        [3] = { baseItemId = 49163, newItemId = 49164, requiredItems = {{id = 48908, count = 30}}},
    },
and so on...

-- Main function to handle onUse event
function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    player:registerEvent("gear menu")

    local choices = {"Hunter", "Mage", "Warrior"}
    showUpgradeMenu(player, 1010, "Vocation Menu", "Select the vocation for which you want to upgrade gear.", choices)
    return true
end

-- Modal window event handler
function onModalWindow(player, modalWindowId, buttonId, choiceId)
    if buttonId == 101 then
player:unregisterEvent("gear menu")
    return
    end

    if modalWindowId == 1010 then
        if choiceId == 1 then showUpgradeMenu(player, 1011, "Hunter Gear Menu", "Select the gear type you would like to upgrade.", {"Helmet", "Armor", "Legs", "Boots", "Shield", "Ring", "Amulet", "Bag"}) end
        if choiceId == 2 then showUpgradeMenu(player, 1012, "Mage Gear Menu", "Select the gear type you would like to upgrade.", {"Helmet", "Armor", "Legs", "Boots", "Shield", "Ring", "Amulet", "Bag"}) end
        if choiceId == 3 then showUpgradeMenu(player, 1013, "Warrior Gear Menu", "Select the gear type you would like to upgrade.", {"Helmet", "Armor", "Legs", "Boots", "Shield", "Ring", "Amulet", "Bag"}) end
    elseif modalWindowId == 1011 then
        if choiceId == 1 then showUpgradeMenu(player, 1014, "Hunter Helmet Upgrade", "Select the tier you would like to upgrade to.                                                                   ", {"(Journeyman) Requires 10x normal stones, 1x apprentice helmet.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman helmet.", "(Worldbreaker) Requires 30x warden stones, 1x champion helmet."}) end
        if choiceId == 2 then showUpgradeMenu(player, 1015, "Hunter Armor Upgrade", "Select the tier you would like to upgrade to.                                                                   ", {"(Journeyman) Requires 10x normal stones, 1x apprentice armor.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman armor.", "(Worldbreaker) Requires 30x warden stones, 1x champion armor."}) end
        if choiceId == 3 then showUpgradeMenu(player, 1016, "Hunter Legs Upgrade", "Select the tier you would like to upgrade to.                                                                   ", {"(Journeyman) Requires 10x normal stones, 1x apprentice legs.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman legs.", "(Worldbreaker) Requires 30x warden stones, 1x champion legs."}) end
        if choiceId == 4 then showUpgradeMenu(player, 1017, "Hunter Boots Upgrade", "Select the tier you would like to upgrade to.                                                                   ", {"(Journeyman) Requires 10x normal stones, 1x apprentice boots.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman boots.", "(Worldbreaker) Requires 30x warden stones, 1x champion boots."}) end
        if choiceId == 5 then showUpgradeMenu(player, 1018, "Hunter Shield Upgrade", "Select the tier you would like to upgrade to.                                                                   ", {"(Journeyman) Requires 10x normal stones, 1x apprentice shield.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman shield.", "(Worldbreaker) Requires 30x warden stones, 1x champion shield."}) end
        if choiceId == 6 then showUpgradeMenu(player, 1019, "Hunter Ring Upgrade", "Select the tier you would like to upgrade to.                                                                   ", {"(Journeyman) Requires 10x normal stones, 1x apprentice ring.", "(Champion) Requires 10x water stones, 10x lava stones, 1x journeyman ring.", "(Worldbreaker) Requires 30x warden stones, 1x champion ring."}) end
and so on..
    elseif modalWindowId == 1014 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.helmet)
    elseif modalWindowId == 1015 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.armor)
    elseif modalWindowId == 1016 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.legs)
    elseif modalWindowId == 1017 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.boots)
    elseif modalWindowId == 1018 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.shield)
    elseif modalWindowId == 1019 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.ring)
    elseif modalWindowId == 1020 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.amulet)
    elseif modalWindowId == 1021 then
        handleUpgradeChoice(player, choiceId, hunterGearUpgrades.bag)
    elseif modalWindowId == 1022 then
        handleUpgradeChoice(player, choiceId, mageGearUpgrades.helmet)
    elseif modalWindowId == 1023 then
        handleUpgradeChoice(player, choiceId, mageGearUpgrades.armor)
    elseif modalWindowId == 1024 then
        handleUpgradeChoice(player, choiceId, mageGearUpgrades.legs)
and so on..
    end
end

I pretty sure that its and easy fix for any decent programmer. this is a shortened version to fit the character cap. anyways would love an assist. thanks!
 
Last edited:
sadly that doesn't work. same problem ive been having with this :
LUA:
-- Function to handle gear upgrade
local function upgradeGear(player, baseItemId, newItemId, requiredItems)
    -- Check if player has the base item
    if not playerHasItem(player, baseItemId, 1) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You do not have the base item required to upgrade your gear.")
        return
    end

    -- Check if player has all required items
    for _, item in ipairs(requiredItems) do
        if not playerHasItem(player, item.id, item.count) then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You do not have the required materials to upgrade your gear.")
            return
        end
    end

    -- Remove the required items from player
    for _, item in ipairs(requiredItems) do
        removeItemFromPlayer(player, item.id, item.count)
    end

    -- Transform the base item into the new item
    local baseItem = player:getItemById(baseItemId)
    if baseItem then
        baseItem:transform(newItemId)
        player:getPosition():sendMagicEffect(CONST_ME_PURPLEENERGY)
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have successfully upgraded your gear.")
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Failed to find the base item in your inventory.")
    end
end


Its just been giving me the message failed to find the base item in your inventory and it also takes the required items . even though it did find the baseitems which i dont get.
 
Back
Top