Untitled

mail@pastecode.io avatar
unknown
lua
2 years ago
3.0 kB
2
Indexable
Never
local items = {

    [2146] = { -- upgrader item id
        -- (archmages items start) -->
        [2453] = {       --normal wand
            transform_id = 7409, -- rare wand
            transform_chance = 100, -- percent
            transform_cost = 10,

            level_req = 500,
            storage = 2001
        },

        [7409] = {       --rare wand
            transform_id = 8911,
            transform_chance = 100, -- percent
            transform_cost = 80,

            level_req = 700,
            storage = 2002
        },
    }

    [7760] = {-- upgrader item id
        [7409] = {       --rare wand
            transform_id = 8911,
            transform_chance = 100, -- percent
            transform_cost = 80,

            level_req = 700,
            storage = 2002
        },
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    local upgrader = items[item:getId()]
    if not upgrader then
        return false
    end

    local data = upgrader[target:getId()]
    if not data then
        return player:sendTextMessage(MESSAGE_INFO_DESCR,"The target item is not upgradeable,\n[This only upgrades rare archmages items]."),
		player:getPosition():sendMagicEffect(232),
		player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end

    if player:getStorageValue(data.storage) > 0 then
        return player:sendTextMessage(MESSAGE_INFO_DESCR,"You have done this upgrading " .. ItemType(data.transform_id):getName() .. " before."),
		player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end

    if player:getLevel() < data.level_req then
        return player:sendTextMessage(MESSAGE_INFO_DESCR,"You need to be at least level " .. data.level_req .. " to upgrade this weapon."),
		player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end

    if not player:removeItem(item:getId(), data.transform_cost) then
        return player:sendTextMessage(MESSAGE_INFO_DESCR,"You need " .. data.transform_cost .. " " .. item:getName() .. "."),
		player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end

    local chance = data.transform_chance
    if math.random(100) > chance then
        return player:sendTextMessage(MESSAGE_INFO_DESCR,"Your upgrade has failed."),
            player:getPosition():sendMagicEffect(230),
			Game.sendAnimatedText("Failed", player:getPosition(), 180)
    end

    target:transform(data.transform_id, 1)
	Game.sendAnimatedText("Success", player:getPosition(), 180)
    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations! Your weapon " .. ItemType(data.transform_id):getName() .. " has been successfully upgraded.")
	player:sendTextMessage(MESSAGE_INFO_DESCR,"Congratulations! Your weapon " .. ItemType(data.transform_id):getName() .. " has been successfully upgraded.")
    player:setStorageValue(data.storage, 1)
    return true
end