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

block dodge in item

carlinhous1996

New Member
Joined
Apr 14, 2022
Messages
54
Reaction score
3
could someone help me with this script?

in the upgrade script there is a blocked_ids to block certain items from being upgraded, is it possible to do the same with dodge?
DODGE
function isHandItem(uid) -- NW based on Mock
uid = uid or 0
if isInArray({1,2,3,4,5,6}, getItemWeaponType(uid)) then
return true
end
return false
end


function getItemDodgePercent(itemuid)
return getItemAttribute(itemuid, "dodgePercent") or 0
end


function setItemDodgePercent(uid, percent)
doItemSetAttribute(uid, "description", "[Dodge: "..percent.."%]")
doItemSetAttribute(uid, "dodgePercent", percent)
end








function onUse(cid, item, fromPosition, itemEx, toPosition)
level = 0
local upgrade = {
[1] = {min = 1, max = 5, chance = 100},
[2] = {min = 5, max = 10, chance = 80},
[3] = {min = 10, max = 20, chance = 60},
[4] = {min = 20, max = 40, chance = 40},
[5] = {min = 40, max = 50, chance = 20}
}


function isWearing(uid) -- NW based on Mock
uid = uid or 0
if isInArray({uid}, getPlayerSlotItem(cid, 1).uid) or isInArray({uid}, getPlayerSlotItem(cid, 4).uid) or isInArray({uid}, getPlayerSlotItem(cid, 7).uid) or isInArray({uid}, getPlayerSlotItem(cid, 8).uid) then
return true
end
return false
end




if isHandItem(itemEx.uid) or isWearing(itemEx.uid) then
local name = getItemName(itemEx.uid)
local atual = math.floor(getItemDodgePercent(itemEx.uid)*10)/10
for i = 1, #upgrade do
if string.find(tostring(name),"+".. i .."") then
level = i
end
end


if level >= #upgrade then
doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,"Your item is already on max level, you can't upgrade it any further.")
return true
end




if math.random(0,100) <= upgrade[level + 1].chance then
doRemoveItem(item.uid, 1)
doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,"You leveled your "..getItemNameById(itemEx.itemid).." to ".. level+1 ..".")
setItemDodgePercent(itemEx.uid, atual + (math.random(upgrade[level+1].min,upgrade[level+1].max))/10)
doItemSetAttribute(itemEx.uid,'name', getItemNameById(itemEx.itemid)..' +'..(level+1))
doSendMagicEffect(toPosition, math.random(28,30))
else
doRemoveItem(itemEx.uid, 1)
doRemoveItem(item.uid, 1)
doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,"Your "..getItemNameById(item.itemid).." has failed and destroyed your "..getItemNameById(itemEx.itemid).." in the process")
doSendMagicEffect(toPosition, 4)
end


else
doPlayerSendTextMessage(cid, 24,"You cant refine this item.")
end
return true
end
UPGRADE
--- Perfect refine system by Mock the bear (MTB).
--- Email: [email protected]
-- &a = weapon attack
-- &d = weapon defense
-- &s = shield defense
-- &p = armor defense
-- # = nivel do item
-- @ = max level
local gain = {
gainArmor='&p+(2)',loseArmor='&p-(2)',
gainShield='&s+(2)',loseShield='&s-(2)',
gainAttack='&a+(2)',loseAttack='&a-(2)',
gainDefense='&d+(2)',loseDefense='&d-(2)',
chance='(100/math.sqrt((((@/4)+(#2))/@)#))',
maxlvl = 5,
blocked_ids = {7878, 2454, 7772, 7863, 7753, 7406, 7857, 7872, 7766, 7747, 7415, 7756, 7881, 7881, 7775, 8905, 8909, 8908, 8906, 8907, 2342, 2343, 8854, 8851, 10313, 2397, 7385, 8209, 5924, 10316, 9735} -- items que nao podem ser aprimorados
}
local it = {
--[itemid] = [percent]
[8300] = 30, -- 50%
}
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

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 then
return true
end
return false
end
local function isShield(uid) -- Function by Mock the bear.
uid = uid or 0
if getItemWeaponType(uid) == 4 then
return true
end
return false
end
local function isBow(uid) -- Function by Mock the bear.
uid = uid or 0
if getItemWeaponType(uid) == 5 then
return true
end
return false
end
local function getWeaponLevel(uid) -- Function by Mock the bear.
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) -- Function by Mock the bear.
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
function onUse(cid, item, fromPosition, itemEx, toPosition)
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)
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 refine 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 on max level, you can't upgrade it.")
end
doPlayerSendTextMessage(cid, 24,"Trying refine with "..(chance+it[item.itemid] > 100 and 100 or chance+it[item.itemid]).."% of sucess!")
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
setItemName(itemEx.uid, getItemNameById(itemEx.itemid)..' +'..(level+1)..slot)
addEvent(doPlayerSendTextMessage,500,cid, 24,"Your item has been upgrated to +"..(level+1)..slot..".")
doSendMagicEffect(toPosition, 28)
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.gainShield,itemEx))
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, getItemNameById(itemEx.itemid)..slot)
addEvent(doPlayerSendTextMessage,500,cid, 24,"Your item back to normal.")
else
setItemName(itemEx.uid, getItemNameById(itemEx.itemid)..' +'..(level-1)..slot)
addEvent(doPlayerSendTextMessage,500,cid, 24,"Your item back to +"..(level-1)..slot..".")
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
setItemAttack(itemEx.uid, doTransform(gain.loseAttack,itemEx))
elseif isShield(itemEx.uid) then
setItemDefense(itemEx.uid, doTransform(gain.loseShield,itemEx))
end
end
doSendMagicEffect(toPosition, 4)
end
doRemoveItem(item.uid,1)
return true
end
 
Try this:
Lua:
local blocked_ids = { 7878, 2454, 7772, 7863, 7753, 7406, 7857, 7872, 7766, 7747, 7415, 7756, 7881, 7881, 7775, 8905,
    8909, 8908, 8906, 8907, 2342, 2343, 8854, 8851, 10313, 2397, 7385, 8209, 5924, 10316, 9735 }

function isHandItem(uid) -- NW based on Mock
    uid = uid or 0
    if isInArray({ 1, 2, 3, 4, 5, 6 }, getItemWeaponType(uid)) then
        return true
    end
    return false
end

function getItemDodgePercent(itemuid)
    return getItemAttribute(itemuid, "dodgePercent") or 0
end

function setItemDodgePercent(uid, percent)
    doItemSetAttribute(uid, "description", "[Dodge: " .. percent .. "%]")
    doItemSetAttribute(uid, "dodgePercent", percent)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    level = 0
    local upgrade = {
        [1] = { min = 1, max = 5, chance = 100 },
        [2] = { min = 5, max = 10, chance = 80 },
        [3] = { min = 10, max = 20, chance = 60 },
        [4] = { min = 20, max = 40, chance = 40 },
        [5] = { min = 40, max = 50, chance = 20 }
    }

    if not isInArray(blocked_ids, itemEx.itemid) then
      
        function isWearing(uid) -- NW based on Mock
            uid = uid or 0
            if isInArray({ uid }, getPlayerSlotItem(cid, 1).uid) or isInArray({ uid }, getPlayerSlotItem(cid, 4).uid) or
                isInArray({ uid }, getPlayerSlotItem(cid, 7).uid) or isInArray({ uid }, getPlayerSlotItem(cid, 8).uid) then
                return true
            end
            return false
        end

        if isHandItem(itemEx.uid) or isWearing(itemEx.uid) then
            local name = getItemName(itemEx.uid)
            local atual = math.floor(getItemDodgePercent(itemEx.uid) * 10) / 10
            for i = 1, #upgrade do
                if string.find(tostring(name), "+" .. i .. "") then
                    level = i
                end
            end
            if level >= #upgrade then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                    "Your item is already on max level, you can't upgrade it any further.")
                return true
            end
            if math.random(0, 100) <= upgrade[level + 1].chance then
                doRemoveItem(item.uid, 1)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                    "You leveled your " .. getItemNameById(itemEx.itemid) .. " to " .. level + 1 .. ".")
                setItemDodgePercent(itemEx.uid,
                    atual + (math.random(upgrade[level + 1].min, upgrade[level + 1].max)) / 10)
                doItemSetAttribute(itemEx.uid, 'name', getItemNameById(itemEx.itemid) .. ' +' .. (level + 1))
                doSendMagicEffect(toPosition, math.random(28, 30))
            else
                doRemoveItem(itemEx.uid, 1)
                doRemoveItem(item.uid, 1)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                    "Your " ..
                    getItemNameById(item.itemid) ..
                    " has failed and destroyed your " .. getItemNameById(itemEx.itemid) .. " in the process")
                doSendMagicEffect(toPosition, 4)
            end
        else
            doPlayerSendTextMessage(cid, 24, "You cant refine this item.")
        end
    end

    return true
end
 
Try this:
Lua:
local blocked_ids = { 7878, 2454, 7772, 7863, 7753, 7406, 7857, 7872, 7766, 7747, 7415, 7756, 7881, 7881, 7775, 8905,
    8909, 8908, 8906, 8907, 2342, 2343, 8854, 8851, 10313, 2397, 7385, 8209, 5924, 10316, 9735 }

function isHandItem(uid) -- NW based on Mock
    uid = uid or 0
    if isInArray({ 1, 2, 3, 4, 5, 6 }, getItemWeaponType(uid)) then
        return true
    end
    return false
end

function getItemDodgePercent(itemuid)
    return getItemAttribute(itemuid, "dodgePercent") or 0
end

function setItemDodgePercent(uid, percent)
    doItemSetAttribute(uid, "description", "[Dodge: " .. percent .. "%]")
    doItemSetAttribute(uid, "dodgePercent", percent)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    level = 0
    local upgrade = {
        [1] = { min = 1, max = 5, chance = 100 },
        [2] = { min = 5, max = 10, chance = 80 },
        [3] = { min = 10, max = 20, chance = 60 },
        [4] = { min = 20, max = 40, chance = 40 },
        [5] = { min = 40, max = 50, chance = 20 }
    }

    if not isInArray(blocked_ids, itemEx.itemid) then
    
        function isWearing(uid) -- NW based on Mock
            uid = uid or 0
            if isInArray({ uid }, getPlayerSlotItem(cid, 1).uid) or isInArray({ uid }, getPlayerSlotItem(cid, 4).uid) or
                isInArray({ uid }, getPlayerSlotItem(cid, 7).uid) or isInArray({ uid }, getPlayerSlotItem(cid, 8).uid) then
                return true
            end
            return false
        end

        if isHandItem(itemEx.uid) or isWearing(itemEx.uid) then
            local name = getItemName(itemEx.uid)
            local atual = math.floor(getItemDodgePercent(itemEx.uid) * 10) / 10
            for i = 1, #upgrade do
                if string.find(tostring(name), "+" .. i .. "") then
                    level = i
                end
            end
            if level >= #upgrade then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                    "Your item is already on max level, you can't upgrade it any further.")
                return true
            end
            if math.random(0, 100) <= upgrade[level + 1].chance then
                doRemoveItem(item.uid, 1)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                    "You leveled your " .. getItemNameById(itemEx.itemid) .. " to " .. level + 1 .. ".")
                setItemDodgePercent(itemEx.uid,
                    atual + (math.random(upgrade[level + 1].min, upgrade[level + 1].max)) / 10)
                doItemSetAttribute(itemEx.uid, 'name', getItemNameById(itemEx.itemid) .. ' +' .. (level + 1))
                doSendMagicEffect(toPosition, math.random(28, 30))
            else
                doRemoveItem(itemEx.uid, 1)
                doRemoveItem(item.uid, 1)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                    "Your " ..
                    getItemNameById(item.itemid) ..
                    " has failed and destroyed your " .. getItemNameById(itemEx.itemid) .. " in the process")
                doSendMagicEffect(toPosition, 4)
            end
        else
            doPlayerSendTextMessage(cid, 24, "You cant refine this item.")
        end
    end

    return true
end
thank you so much!! you have helped me a lot today.
deserves an award

I tested it here and everything worked fine, except for the
You cant refine this item
 
Last edited:
Try this:
Lua:
local config = {
    blocked_ids = { 7878, 2454, 7772, 7863, 7753, 7406, 7857, 7872, 7766, 7747, 7415, 7756, 7881, 7881, 7775, 8905,
        8909, 8908, 8906, 8907, 2342, 2343, 8854, 8851, 10313, 2397, 7385, 8209, 5924, 10316, 9735 },
}

function getItemDodgePercent(itemuid)
    return getItemAttribute(itemuid, "dodgePercent") or 0
end

function setItemDodgePercent(uid, percent)
    doItemSetAttribute(uid, "description", "[Dodge: " .. percent .. "%]")
    doItemSetAttribute(uid, "dodgePercent", percent)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    level = 0
    local upgrade = {
        [1] = { min = 1, max = 5, chance = 100 },
        [2] = { min = 5, max = 10, chance = 80 },
        [3] = { min = 10, max = 20, chance = 60 },
        [4] = { min = 20, max = 40, chance = 40 },
        [5] = { min = 40, max = 50, chance = 20 }
    }

    if not isInArray(config.blocked_ids, itemEx.itemid) then
        local getItemInfo = getItemInfo(itemEx.itemid)
        if ((getItemInfo.attack > 0) or (getItemInfo.defense > 0) or (getItemInfo.armor > 0)) then
            local name = getItemName(itemEx.uid)
            local atual = math.floor(getItemDodgePercent(itemEx.uid) * 10) / 10
            for i = 1, #upgrade do
                if string.find(tostring(name), "+" .. i .. "") then
                    level = i
                end
            end
            if level >= #upgrade then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                    "Your item is already on max level, you can't upgrade it any further.")
                return true
            end
            if math.random(0, 100) <= upgrade[level + 1].chance then
                doRemoveItem(item.uid, 1)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                    "You leveled your " .. getItemNameById(itemEx.itemid) .. " to " .. level + 1 .. ".")
                setItemDodgePercent(itemEx.uid,
                    atual + (math.random(upgrade[level + 1].min, upgrade[level + 1].max)) / 10)
                doItemSetAttribute(itemEx.uid, 'name', getItemNameById(itemEx.itemid) .. ' +' .. (level + 1))
                doSendMagicEffect(toPosition, math.random(28, 30))
            else
                doRemoveItem(itemEx.uid, 1)
                doRemoveItem(item.uid, 1)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                    "Your " ..
                    getItemNameById(item.itemid) ..
                    " has failed and destroyed your " .. getItemNameById(itemEx.itemid) .. " in the process")
                doSendMagicEffect(toPosition, 4)
            end
        else
            doPlayerSendTextMessage(cid, 24, "You cant refine this item.")
        end
    end

    return true
end
 
Try this:
Lua:
local config = {
    blocked_ids = { 7878, 2454, 7772, 7863, 7753, 7406, 7857, 7872, 7766, 7747, 7415, 7756, 7881, 7881, 7775, 8905,
        8909, 8908, 8906, 8907, 2342, 2343, 8854, 8851, 10313, 2397, 7385, 8209, 5924, 10316, 9735 },
}

function getItemDodgePercent(itemuid)
    return getItemAttribute(itemuid, "dodgePercent") or 0
end

function setItemDodgePercent(uid, percent)
    doItemSetAttribute(uid, "description", "[Dodge: " .. percent .. "%]")
    doItemSetAttribute(uid, "dodgePercent", percent)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    level = 0
    local upgrade = {
        [1] = { min = 1, max = 5, chance = 100 },
        [2] = { min = 5, max = 10, chance = 80 },
        [3] = { min = 10, max = 20, chance = 60 },
        [4] = { min = 20, max = 40, chance = 40 },
        [5] = { min = 40, max = 50, chance = 20 }
    }

    if not isInArray(config.blocked_ids, itemEx.itemid) then
        local getItemInfo = getItemInfo(itemEx.itemid)
        if ((getItemInfo.attack > 0) or (getItemInfo.defense > 0) or (getItemInfo.armor > 0)) then
            local name = getItemName(itemEx.uid)
            local atual = math.floor(getItemDodgePercent(itemEx.uid) * 10) / 10
            for i = 1, #upgrade do
                if string.find(tostring(name), "+" .. i .. "") then
                    level = i
                end
            end
            if level >= #upgrade then
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                    "Your item is already on max level, you can't upgrade it any further.")
                return true
            end
            if math.random(0, 100) <= upgrade[level + 1].chance then
                doRemoveItem(item.uid, 1)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                    "You leveled your " .. getItemNameById(itemEx.itemid) .. " to " .. level + 1 .. ".")
                setItemDodgePercent(itemEx.uid,
                    atual + (math.random(upgrade[level + 1].min, upgrade[level + 1].max)) / 10)
                doItemSetAttribute(itemEx.uid, 'name', getItemNameById(itemEx.itemid) .. ' +' .. (level + 1))
                doSendMagicEffect(toPosition, math.random(28, 30))
            else
                doRemoveItem(itemEx.uid, 1)
                doRemoveItem(item.uid, 1)
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                    "Your " ..
                    getItemNameById(item.itemid) ..
                    " has failed and destroyed your " .. getItemNameById(itemEx.itemid) .. " in the process")
                doSendMagicEffect(toPosition, 4)
            end
        else
            doPlayerSendTextMessage(cid, 24, "You cant refine this item.")
        end
    end

    return true
end
unfortunately the message still does not appear
 
The message "You can't refine this item." will only appear if the item has no attack, no defense, or if it has no armor.
If the item has one of these properties, the message will not appear.

Try changing this part:
Lua:
local getItemInfo = getItemInfo(itemEx.itemid)
for
Lua:
local getItemInfo = getItemInfo(itemEx.uid)
Not sure if it will work.
Post automatically merged:

There is another way to solve it, it is very simple, instead of using "blocked_ids", we can use "allowed_ids", however, if the amount of allowed items is too large, it will be a lot of work for you.
Post automatically merged:

Here is a version with "allowed_ids".
Lua:
local config = {
    allowed_ids = { 7878, 2454, 7772, 7863, 7753, 7406, 7857, 7872, 7766, 7747, 7415, 7756, 7881, 7881, 7775, 8905,
        8909, 8908, 8906, 8907, 2342, 2343, 8854, 8851, 10313, 2397, 7385, 8209, 5924, 10316, 9735 },
}

function getItemDodgePercent(itemuid)
    return getItemAttribute(itemuid, "dodgePercent") or 0
end

function setItemDodgePercent(uid, percent)
    doItemSetAttribute(uid, "description", "[Dodge: " .. percent .. "%]")
    doItemSetAttribute(uid, "dodgePercent", percent)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    level = 0
    local upgrade = {
        [1] = { min = 1, max = 5, chance = 100 },
        [2] = { min = 5, max = 10, chance = 80 },
        [3] = { min = 10, max = 20, chance = 60 },
        [4] = { min = 20, max = 40, chance = 40 },
        [5] = { min = 40, max = 50, chance = 20 }
    }

    if isInArray(config.allowed_ids, itemEx.itemid) then
        local name = getItemName(itemEx.uid)
        local atual = math.floor(getItemDodgePercent(itemEx.uid) * 10) / 10
        for i = 1, #upgrade do
            if string.find(tostring(name), "+" .. i .. "") then
                level = i
            end
        end
        if level >= #upgrade then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                "Your item is already on max level, you can't upgrade it any further.")
            return true
        end
        if math.random(0, 100) <= upgrade[level + 1].chance then
            doRemoveItem(item.uid, 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                "You leveled your " .. getItemNameById(itemEx.itemid) .. " to " .. level + 1 .. ".")
            setItemDodgePercent(itemEx.uid,
                atual + (math.random(upgrade[level + 1].min, upgrade[level + 1].max)) / 10)
            doItemSetAttribute(itemEx.uid, 'name', getItemNameById(itemEx.itemid) .. ' +' .. (level + 1))
            doSendMagicEffect(toPosition, math.random(28, 30))
        else
            doRemoveItem(itemEx.uid, 1)
            doRemoveItem(item.uid, 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                "Your " ..
                getItemNameById(item.itemid) ..
                " has failed and destroyed your " .. getItemNameById(itemEx.itemid) .. " in the process")
            doSendMagicEffect(toPosition, 4)
        end
    else
        doPlayerSendTextMessage(cid, 24, "You cant refine this item.")
    end

    return true
end
 
Last edited:
The message "You can't refine this item." will only appear if the item has no attack, no defense, or if it has no armor.
If the item has one of these properties, the message will not appear.

Try changing this part:
Lua:
local getItemInfo = getItemInfo(itemEx.itemid)
for
Lua:
local getItemInfo = getItemInfo(itemEx.uid)
Not sure if it will work.
Post automatically merged:

There is another way to solve it, it is very simple, instead of using "blocked_ids", we can use "allowed_ids", however, if the amount of allowed items is too large, it will be a lot of work for you.
Post automatically merged:

Here is a version with "allowed_ids".
Lua:
local config = {
    allowed_ids = { 7878, 2454, 7772, 7863, 7753, 7406, 7857, 7872, 7766, 7747, 7415, 7756, 7881, 7881, 7775, 8905,
        8909, 8908, 8906, 8907, 2342, 2343, 8854, 8851, 10313, 2397, 7385, 8209, 5924, 10316, 9735 },
}

function getItemDodgePercent(itemuid)
    return getItemAttribute(itemuid, "dodgePercent") or 0
end

function setItemDodgePercent(uid, percent)
    doItemSetAttribute(uid, "description", "[Dodge: " .. percent .. "%]")
    doItemSetAttribute(uid, "dodgePercent", percent)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    level = 0
    local upgrade = {
        [1] = { min = 1, max = 5, chance = 100 },
        [2] = { min = 5, max = 10, chance = 80 },
        [3] = { min = 10, max = 20, chance = 60 },
        [4] = { min = 20, max = 40, chance = 40 },
        [5] = { min = 40, max = 50, chance = 20 }
    }

    if isInArray(config.allowed_ids, itemEx.itemid) then
        local name = getItemName(itemEx.uid)
        local atual = math.floor(getItemDodgePercent(itemEx.uid) * 10) / 10
        for i = 1, #upgrade do
            if string.find(tostring(name), "+" .. i .. "") then
                level = i
            end
        end
        if level >= #upgrade then
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                "Your item is already on max level, you can't upgrade it any further.")
            return true
        end
        if math.random(0, 100) <= upgrade[level + 1].chance then
            doRemoveItem(item.uid, 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                "You leveled your " .. getItemNameById(itemEx.itemid) .. " to " .. level + 1 .. ".")
            setItemDodgePercent(itemEx.uid,
                atual + (math.random(upgrade[level + 1].min, upgrade[level + 1].max)) / 10)
            doItemSetAttribute(itemEx.uid, 'name', getItemNameById(itemEx.itemid) .. ' +' .. (level + 1))
            doSendMagicEffect(toPosition, math.random(28, 30))
        else
            doRemoveItem(itemEx.uid, 1)
            doRemoveItem(item.uid, 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE,
                "Your " ..
                getItemNameById(item.itemid) ..
                " has failed and destroyed your " .. getItemNameById(itemEx.itemid) .. " in the process")
            doSendMagicEffect(toPosition, 4)
        end
    else
        doPlayerSendTextMessage(cid, 24, "You cant refine this item.")
    end

    return true
end
the quantity is the same, I only increased 3 items
Muito obrigado.
so the allowed_ids are the items that can be refined, got it.
 
Last edited:
Back
Top