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

Lua Upgrade system

Zoool

New Member
Joined
Jul 18, 2014
Messages
163
Reaction score
2
Could someone edit this script to work like this:

If item used on xxxx id it gives +1mlvl
If item used on xxxx id it gives +1dist fighting
If item used on xxxx id it gives +1sword, +1axe, +1club fighting

On the rest items it works like in script:
Code:
  --- Perfect refine system by Mock the bear (MTB).
--- Email: [email protected]
local gain = {
gainArmor='&p+1',loseArmor='&p-1',
gainShield='&s+#',loseShield='&s-(#+1)',
gainAttack='&a+(2*(#))',loseAttack='&a-(2*(#+1))',
gainDefense='&d+(2*(#))',loseDefense='&d-(2*(#+1))',
chance='100/((#*(1/(@/2)))*(@/2))',  -- Eu fiz essa equaça~o para variar de +0 a +7 o item
--- Essa equaça~o deve retornar em % a chance do item se refinar (0-100) 100 = sempre, 0 = nunca
maxlvl = 2,
blocked_ids = {2488,8881}
}
-- &a = weapon attack
-- &d = weapon defense
-- &s = shield defense
-- &p = armor defense
-- # = nivel do item
-- @ = max level
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 getItemAttack(uid)
           return getItemAttribute(uid,'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
function isArmor(uid) -- Function by Mock the bear.
         if (getItemArmor(uid) and getItemArmor(uid) ~= 0 and not getItemInfo(uid.itemid,'attack') and not getItemInfo(uid.itemid,'defense') and getItemWeaponType(uid.uid) == 0) then
            return true
         end
         return false
end
function isWeapon(uid) -- Function by Mock the bear.
         uid = uid or 0
         local f = getItemWeaponType(uid)
         if f == 1 or f == 2 or f == 3 then
             return TRUE
         end
         return FALSE
end
function isShield(uid) -- Function by Mock the bear.
         uid = uid or 0
         if getItemWeaponType(uid) == 4 then
             return TRUE
         end
         return FALSE
end

function getWeaponLevel(uid) -- Function by Mock the bear.
   uid = uid or 0
   local name = getItemName(uid)
   local lvl = string.match(name,'+(%d)')
   return tonumber(lvl) or 0
end
function doTransform(s,i) -- Function by Mock the bear.
    local c = string.gsub(s,'@',gain.maxlvl)
    local c = string.gsub(c,'&a',getItemAttack(i.uid) or getItemInfo(i.itemid).attack)
    local c = string.gsub(c,'&d',getItemDefense(i.uid) or getItemInfo(i.itemid).defense)
    local c = string.gsub(c,'&s',getItemDefense(i.uid) or getItemInfo(i.itemid).defense)
    local c = string.gsub(c,'&p',getItemArmor(i.uid) or getItemInfo(i.itemid).armor)
    local c = string.gsub(c,'#',getWeaponLevel(i.uid))
    local q,err = loadstring('return '..c)
    assert(q,err)
    return assert(q())
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
         toPosition.stackpos = 255
         if isInArray(gain.blocked_ids, itemEx.itemid) == TRUE
          or getItemWeaponType(itemEx.uid) > 4
           or (getItemWeaponType(itemEx.uid) == 0
            and isArmor(itemEx) == FALSE)
             or itemEx.itemid == 0 then
                doPlayerSendTextMessage(cid, 24,"You cant refine this item.")
                return TRUE
         end
         if isCreature(itemEx.uid) == TRUE then
            return FALSE
         end
        local level = getWeaponLevel(itemEx.uid)
        local chance = doTransform(gain.chance,itemEx)
        if chance >= math.random(0,100) or item.actionid >= 1000 or (item.actionid == 500 and math.random(0,100) <= 25) then
           if level+1 > gain.maxlvl then
              doSendMagicEffect(toPosition, 2)
              return doPlayerSendTextMessage(cid, 24,"Your item is on max level, you can't upgrade it.")
           else
              setItemName(itemEx.uid, getItemNameById(itemEx.itemid)..' +'..(level+1))
              doPlayerSendTextMessage(cid, 24,"Your item has been upgrated to +"..(level+1)..".")
              doSendMagicEffect(toPosition, 12)
              if isArmor(itemEx) == TRUE then
                 local get = doTransform(gain.gainArmor,itemEx)
                 setItemArmor(itemEx.uid,get)
              elseif isWeapon(itemEx.uid) == TRUE then
                  setItemAttack(itemEx.uid, doTransform(gain.gainAttack,itemEx))
                  setItemDefense(itemEx.uid, doTransform(gain.gainDefense,itemEx))
              elseif isShield(itemEx.uid) == TRUE then
                  setItemDefense(itemEx.uid, doTransform(gain.gainShield,itemEx))
              end
           end
        else

           if level == 0 then
               doPlayerSendTextMessage(cid, 24,"No effect.")
               doSendMagicEffect(toPosition, 2)
           elseif level == gain.maxlvl then
                  doSendMagicEffect(toPosition, 2)
                  return doPlayerSendTextMessage(cid, 24,"Your item is on max level, you can't upgrade it.")
           elseif level > 0 then
               if level == 1 then
                   setItemName(itemEx.uid, getItemNameById(itemEx.itemid))
                   doPlayerSendTextMessage(cid, 24,"Your item back to normal.")
               else
                   setItemName(itemEx.uid, getItemNameById(itemEx.itemid)..' +'..(level-1))
                   doPlayerSendTextMessage(cid, 24,"Your item back to +"..(level-1)..".")
               end
              if isArmor(itemEx) == TRUE then
                 setItemArmor(itemEx.uid,doTransform(gain.loseArmor  ,itemEx))
              elseif isWeapon(itemEx.uid) == TRUE then
                  setItemAttack(itemEx.uid, doTransform(gain.loseAttack,itemEx))
                  setItemDefense(itemEx.uid, doTransform(gain.loseDefense,itemEx))
              elseif isShield(itemEx.uid) == TRUE then
                  setItemDefense(itemEx.uid, doTransform(gain.loseShield,itemEx))
              end
           end
           doSendMagicEffect(toPosition, 9)
        end
     doRemoveItem(item.uid,1)
     return TRUE
end


Thanks alot for help
 
Something like this? Its an old script but has more options

Code:
local gain = {
gainArmor='&p+1',loseArmor='&p-1',
gainSpeed='&v-100',loseSpeed='&v+100',
gainHit='&h+5',loseHit='&h-5',
gainShield='&s+1',loseShield='&s-1',
gainAttack='&a+2',loseAttack='&a-2',
gainDefense='&d+2',loseDefense='&d-2',
chance='(100/math.sqrt((((@/4)+(#*2))/@)*#))'
}
local config = {
maxlvl = 12, -- max item level
fprotec = 12508, -- item ID f-protect
minlvlbroad = 5, -- min level of the fortification to broadcast
maxlvlbroad = 11, -- max level of the fortification to broadcast
lvllose = 6, -- level of the gear to not lose level if fail
blocked_ids = {} -- bloked IDS
}
local it = {
--[itemid] = [percent]
[8306] = 0, -- 0% additional
[8300] = 10, -- 10% additional
[8305] = 100, -- 100% additional
}
if not setItemName then
    function setItemName(uid,name)
        return doItemSetAttribute(uid,'article',name)
    end
    function setItemArmor(uid,name)
        return doItemSetAttribute(uid,'armor',name)
    end
    function setItemHitChance(uid,name)
        return doItemSetAttribute(uid,'hitchance',name)
    end
    function getItemHitChance(uid)
   if type(uid) == 'number' then
      return getItemAttribute(uid,'hitchance')
   else
      return getItemInfo(uid.itemid).hitchance
   end
end
    function setItemDefense(uid,name)
        return doItemSetAttribute(uid,'defense',name)
    end
    function setItemAttackSpeed(uid,name)
        return doItemSetAttribute(uid,'attackspeed',name)
    end
    function getItemAttackSpeed(uid)
        return getItemAttribute(uid,'attackspeed')
    end
    function setItemAttack(uid,name)
        return doItemSetAttribute(uid,'attack',name)
    end
    function getItemAttack(uid)
        return getItemAttribute(uid,'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) -- Function by Mock the bear.
    if (getItemInfo(uid.itemid).armor ~= 0) and (getItemWeaponType(uid.uid) == 0) then
        return true
    end
    return false
end
local function isWeapon(uid) -- Function by Mock the bear.
    uid = uid or 0
    local f = getItemWeaponType(uid)
    if f == 1 or f == 2 or f == 3 or f == 6 then
        return true
    end
    return false
end
local function isShield(uid) -- Function by Mock the bear.
    uid = uid or 0
    if getItemWeaponType(uid) == 5 then
        return true
    end
    return false
end
local function isWand(uid) -- Function by Mock the bear.
    uid = uid or 0
    if getItemWeaponType(uid) == 7 then
        return true
    end
    return false
end
local function isBow(uid) -- Function by Mock the bear.
    uid = uid or 0
    if getItemWeaponType(uid) == 4 then
        return true
    end
    return false
end
local function getWeaponLevel(uid) -- Function by Mock the bear.
   uid = uid or 0
   local name = getItemArticle(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) -- Function by Mock the bear.
    local c = string.gsub(s,'@',config.maxlvl)
    local c = string.gsub(c,'&v',(getItemAttackSpeed(i.uid) ~= 0 and getItemAttackSpeed(i.uid) or getItemInfo(i.itemid).attackSpeed))
    local c = string.gsub(c,'&h',(getItemHitChance(i.uid) ~= 0 and getItemHitChance(i.uid) or getItemInfo(i.itemid).hitChance))
    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
function onUse(cid, item, fromPosition, itemEx, toPosition)
         if item.uid == 0 or item.itemid == 0 then return false end
         toPosition.stackpos = 255
         if isInArray(config.blocked_ids, itemEx.itemid)
          or (not getItemWeaponType(itemEx.uid) or getItemWeaponType(itemEx.uid) > 7)
           or (getItemWeaponType(itemEx.uid) == 0 and not isArmor(itemEx))
             or itemEx.itemid == 0 or itemEx.type > 1 or isItemStackable(itemEx.uid) then
                doPlayerSendTextMessage(cid, 19,"[F-SYSTEM] You can't fortify 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 == config.maxlvl then
            doSendMagicEffect(toPosition, 2)
            return doPlayerSendTextMessage(cid, 19,"[F-SYSTEM] Your "..getItemName(itemEx.uid).." is on max level.")
        end
        doPlayerSendTextMessage(cid, 4,"[F-SYSTEM] Trying to fortify with "..(chance+it[item.itemid] > 100 and 100 or chance+it[item.itemid]).."% of success....")
   
        if chance+it[item.itemid] >= math.random(0,100) 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    
            doSendMagicEffect(toPosition, 12)
             
            if level == config.minlvlbroad then        
            addEvent (doPlayerSendTextMessage, 100,cid, 4,"Now your "..getItemName(itemEx.uid).." will not back level below 6.")
            doSendMagicEffect(toPosition, 30)
            doBroadcastMessage("[F-SYSTEM] The player "..getCreatureName(cid).." has been succeeded to fortify "..getItemArticleById(itemEx.itemid).." +6 "..getItemName(itemEx.uid)..".")
         
            elseif level == config.maxlvlbroad then        
            doSendMagicEffect(toPosition, 28)
            doBroadcastMessage("[F-SYSTEM] GRATZ!! The player "..getCreatureName(cid).." has been succeeded to fortify "..getItemArticleById(itemEx.itemid).." +12 "..getItemName(itemEx.uid).."!! Reached the max fortification level!!")
            end
         
            doItemSetAttribute(itemEx.uid,'article', getItemArticleById(itemEx.itemid)..' +'..(level+1))
            addEvent(doPlayerSendTextMessage,100,cid, 4,"Your "..getItemName(itemEx.uid).." has been fortified to level +"..(level+1)..".")
            if isArmor(itemEx) then
                local get = doTransform(gain.gainArmor,itemEx)
                setItemArmor(itemEx.uid,get)
            elseif isBow(itemEx.uid) then        
                setItemHitChance(itemEx.uid, doTransform(gain.gainHit,itemEx))
                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 isWand(itemEx.uid) then
                setItemAttackSpeed(itemEx.uid, doTransform(gain.gainSpeed,itemEx))
            elseif isShield(itemEx.uid) then
                setItemDefense(itemEx.uid, doTransform(gain.gainShield,itemEx))
            end
        else
            if level == config.lvllose or doPlayerRemoveItem(cid, config.fprotec, 1) == true then
                addEvent(doPlayerSendTextMessage,100,cid, 4,"Failed but doesn't back level.")
                doSendMagicEffect(toPosition, 2)
                doRemoveItem(item.uid,1)
                return true
            end
            if 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
                    doItemSetAttribute(itemEx.uid,'article', getItemArticleById(itemEx.itemid))
                    addEvent(doPlayerSendTextMessage,100,cid, 19,"Your "..getItemName(itemEx.uid).." is back to normal.")
                else
                    doItemSetAttribute(itemEx.uid,'article', getItemArticleById(itemEx.itemid)..' +'..(level-1))
                    addEvent(doPlayerSendTextMessage,100,cid, 4,"Your "..getItemName(itemEx.uid).." is back to level +"..(level-1)..".")
                end
                if isArmor(itemEx) then
                    setItemArmor(itemEx.uid,doTransform(gain.loseArmor  ,itemEx))
                elseif isWeapon(itemEx.uid) then
                    setItemAttack(itemEx.uid, doTransform(gain.loseAttack,itemEx))
                    setItemDefense(itemEx.uid, doTransform(gain.loseDefense,itemEx))
                elseif isBow(itemEx.uid) then
                setItemHitChance(itemEx.uid, doTransform(gain.loseHit,itemEx))
                    setItemAttack(itemEx.uid, doTransform(gain.loseAttack,itemEx))
            elseif isWand(itemEx.uid) then
                setItemAttackSpeed(itemEx.uid, doTransform(gain.loseSpeed,itemEx))
                elseif isShield(itemEx.uid) then
                    setItemDefense(itemEx.uid, doTransform(gain.loseDefense,itemEx))
                end
            end
            doSendMagicEffect(toPosition, 9)
        end
    doRemoveItem(item.uid,1)
    return true
end
 
I would really prefer upgrade system this way:
If item used on xxxx id it gives +1 attack
If item used on xxxx id it gives +1 armor
If item used on xxxx id it gives +1mlvl
If item used on xxxx id it gives +1club/sword/axe fighting

can someone do it? its even possible to do it on lua?
 
Back
Top