Untitled

mail@pastecode.io avatar
unknown
lua
12 days ago
6.9 kB
2
Indexable
Never
local gain = {
    gainArmor='&p+(1000)',loseArmor='&p-(1000)',
    gainShield='&s+#',loseShield='&s-(#+1000)',
    gainAttack='&a+(50000*(#))',loseAttack='&a-(0*(#+50000))',
    gainDefense='&d+(1000*(#))',loseDefense='&d-(0*(#+1000))',
    chance='(100/math.sqrt((((@/4)+(#*2))/@)*#))',
    maxlvl = 15,
    blocked_ids = {12430}
}

local it = {
    --[itemid] = [percent]
    [8306] = 101
}

local wands = {
    availableIds = {2436},
    damagePerUpgrade = 100000000
}

if not setItemName then

    function setItemName(uid,name)
        return doItemSetAttribute(uid,'name',name)
    end

    function setItemArmor(uid,name)
        return doItemSetAttribute(uid,'armor',name)
    end

    function setItemDefense(uid,name)
        return doItemSetAttribute(uid,'defense',name)
    end

    function setItemAttack(uid,name)
        return doItemSetAttribute(uid,'attack',name)
    end

    function setItemWandAttack(uid,value)
        return doItemSetAttribute(uid,'wand_attack',value)
    end

    function getItemAttack(uid)
        return getItemAttribute(uid,'attack')
    end

    function getItemWandAttack(uid)
        return getItemAttribute(uid,'wand_attack')
    end

    function getItemDefense(uid)
        return getItemAttribute(uid,'defense')
    end

    function getItemArmor(uid)
        if type(uid) == 'number' then
            return getItemAttribute(uid,'armor')
        else
            return getItemInfo(uid.itemid).armor
        end
    end
end
    
local function isArmor(uid)
    if (getItemInfo(uid.itemid).armor ~= 0) and (getItemWeaponType(uid.uid) == 0) then
        return true
    end
    return false
end

local function isWeapon(uid)
    uid = uid or 0
    local f = getItemWeaponType(uid)
    if f == 1 or f == 2 or f == 3 then
        return true
    end
    return false
end

local function isWand(uid)
    return getItemWeaponType(uid or 0) == 7 
end

local function isBow(uid)
    uid = uid or 0
    if getItemWeaponType(uid) == 4 then
        return true
    end
    return false
end

local function isShield(uid)
    uid = uid or 0
    if getItemWeaponType(uid) == 5 then
        return true
    end
    return false
end

local function getWeaponLevel(uid)
    uid = uid or 0
    local name = getItemName(uid.uid) or getItemInfo(uid.itemid).name or ''
    local lvl = string.match(name,'%s%+(%d+)%s*')
    return tonumber(lvl) or 0
end

local function doTransform(s,i)
    local c = string.gsub(s,'@',gain.maxlvl)
    local c = string.gsub(c,'&a',(getItemAttack(i.uid) ~= 0 and getItemAttack(i.uid) or getItemInfo(i.itemid).attack))
    local c = string.gsub(c,'&d',(getItemDefense(i.uid) ~= 0 and getItemDefense(i.uid) or getItemInfo(i.itemid).defense))
    local c = string.gsub(c,'&s',(getItemDefense(i.uid) ~= 0 and getItemDefense(i.uid) or getItemInfo(i.itemid).defense))
    local c = string.gsub(c,'&p',(getItemArmor(i.uid) ~= 0 and getItemArmor(i.uid) or getItemInfo(i.itemid).armor))
    local c = string.gsub(c,'#',getWeaponLevel(i))
    local q =  assert(loadstring('return '..c))
    return math.floor(assert(q()))
end
    
local function getBoostLevel(item)
    local name = ""
    local level = getItemAttribute(item, "boostTimes") or 0
    if level >= 1 and level < 3 then
        name = "Unique "
    elseif level >= 3 and level < 5 then
        name = "Super "
    elseif level >= 5 then
        name = "Epic "
    end
    return name
end

function onUse(cid, item, fromPosition, itemEx, toPosition)

    if item.aid == 3822 then
        return false
    end

    for s = 1, 10 do
        local item_boost = itemEx
        if (getPlayerSlotItem(cid, s).uid == item_boost.uid) then
            return doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, "Please unEquip your item to transform it.")
        end
    end
    
    if item.uid == 0 or item.itemid == 0 then 
        return false 
    end

    toPosition.stackpos = 255

    if isInArray(gain.blocked_ids, itemEx.itemid) or (not getItemWeaponType(itemEx.uid) or (getItemWeaponType(itemEx.uid) > 5 and (not getItemWeaponType(itemEx.uid) == 7 or not isInArray(wands.availableIds, itemEx.itemid))))
            or (getItemWeaponType(itemEx.uid) == 0 and not isArmor(itemEx)) or itemEx.itemid == 0 or itemEx.type > 1 or isItemStackable(itemEx.uid) then
        doPlayerSendTextMessage(cid, 24,"You cant upgrade this item.")
        return TRUE
    end

    if isCreature(itemEx.uid) == TRUE then
        return FALSE
    end

    local level = getWeaponLevel(itemEx)
    local chance = doTransform(gain.chance,itemEx)
    if level == gain.maxlvl then
        doSendMagicEffect(toPosition, 2)
        return doPlayerSendTextMessage(cid, 24,"Your item is already +15.")
    end

    if chance+it[item.itemid] >= math.random(0,100) then
        local nm = getItemName(itemEx.uid)
        local slot = nm:match('(%[.+%])') or ''
        slot = slot~='' and ' '..slot or slot
        setItemName(itemEx.uid, getBoostLevel(itemEx.uid)..getItemNameById(itemEx.itemid)..' +'..(level+1)..slot)
        addEvent(doPlayerSendTextMessage,1,cid, 24,"Your item has been upgrated to +"..(level+1)..slot..".")
        doSendAnimatedText(getThingPos(cid), "Up +"..(level+1)..slot.."", TEXTCOLOR_LIGHTBLUE)
        doSendMagicEffect(toPosition, 30)


        if isArmor(itemEx) then
            local get = doTransform(gain.gainArmor,itemEx)
            setItemArmor(itemEx.uid,get)
        elseif isBow(itemEx.uid) then
            setItemAttack(itemEx.uid, doTransform(gain.gainAttack,itemEx))
        elseif isWeapon(itemEx.uid) then
            setItemAttack(itemEx.uid, doTransform(gain.gainAttack,itemEx))
            setItemDefense(itemEx.uid, doTransform(gain.gainDefense,itemEx))
        elseif isShield(itemEx.uid) then
            setItemDefense(itemEx.uid, doTransform(gain.gainDefense,itemEx))
        elseif isWand(itemEx.uid) then
            setItemWandAttack(itemEx.uid, wands.damagePerUpgrade * (level + 1))
        end

    else

        if level == 0 then
            addEvent(doPlayerSendTextMessage,500,cid, 24,"No effect.")
            doSendMagicEffect(toPosition, 2)
        elseif level > 0 then

            local nm = getItemName(itemEx.uid)
            local slot = nm:match('(%[.+%])') or '' ---If you server use slot system dont change it ^^
            slot = slot~='' and ' '..slot or slot

            if level == 1 then
                setItemName(itemEx.uid, getBoostLevel(itemEx.uid)..getItemNameById(itemEx.itemid)..slot)
                addEvent(doPlayerSendTextMessage,500,cid, 24,"Your item back to normal.")
            else
                doSendAnimatedText(getThingPos(cid), "Failed!", TEXTCOLOR_RED)
            end

            if isWand(itemEx.uid) then
                setItemWandAttack(itemEx.uid, wands.damagePerUpgrade * level)
            end
        end
        doSendMagicEffect(toPosition, 0)
    end

    doRemoveItem(item.uid,1)
    return true
end
Leave a Comment