local config = {
[9808] = { -- Common Rusty Armor
[1] = {id = 2464, chance = 6994}, -- Chain Armor
[2] = {id = 2483, chance = 3952}, -- Scale Armor
[3] = {id = 2465, chance = 1502}, -- Brass Armor
[4] = {id = 2463, chance = 197} -- Plate Armor
},
[9809] = { -- Semi-rare Rusty Armor
[1] = {id = 2483, chance = 6437}, -- Scale Armor
[2] = {id = 2464, chance = 4606}, -- Chain Armor
[3] = {id = 2465, chance = 3029}, -- Brass Armor
[4] = {id = 2463, chance = 1559}, -- Plate Armor
[5] = {id = 2476, chance = 595}, -- Knight Armor
[6] = {id = 8891, chance = 283}, -- Paladin Armor
[7] = {id = 2487, chance = 49} -- Crown Armor
},
[9810] = { -- Rare Rusty Armor
[1] = {id = 2465, chance = 6681}, -- Brass Armor
[2] = {id = 2463, chance = 3767}, -- Plate Armor
[3] = {id = 2476, chance = 1832}, -- Knight Armor
[4] = {id = 2487, chance = 177}, -- Crown Armor
[5] = {id = 8891, chance = 31}, -- Paladin Armor
[6] = {id = 2466, chance = 10} -- Golden Armor
},
[9811] = { -- Common Rusty Legs
[1] = {id = 2648, chance = 6949}, -- Chain Legs
[2] = {id = 2468, chance = 3692}, -- Studded Legs
[3] = {id = 2478, chance = 1307}, -- Brass Legs
[4] = {id = 2647, chance = 133} -- Plate Legs
},
[9812] = { -- Semi-Rare Rusty Legs
[1] = {id = 2468, chance = 5962}, -- Studded Legs
[2] = {id = 2648, chance = 4037}, -- Chain Legs
[3] = {id = 2478, chance = 2174}, -- Brass Legs
[4] = {id = 2647, chance = 1242}, -- Plate Legs
[5] = {id = 2477, chance = 186}, -- Knight Legs
},
[9813] = { -- Rare Rusty Legs
[1] = {id = 2478, chance = 6500}, -- Brass Legs
[2] = {id = 2647, chance = 3800}, -- Plate Legs
[3] = {id = 2477, chance = 200}, -- Knight Legs
[4] = {id = 2488, chance = 52}, -- Crown Legs
[5] = {id = 2470, chance = 30} -- Golden Legs
},
[9814] = { -- Heavily Rusted Shield
},
[9815] = { -- Rusted Shield
},
[9816] = { -- Slightly Rusted Shield
[1] = {id = 2510, chance = 3137}, -- Plate Shield
[2] = {id = 2532, chance = 2887}, -- Ancient Shield
[3] = {id = 7460, chance = 929}, -- Norse Shield
[4] = {id = 2519, chance = 23}, -- Crown Shield
[5] = {id = 2534, chance = 10} -- Vampire Shield
},
[9820] = { -- Heavily Rusted Helmet
},
[9821] = { -- Rusted Helmet
[1] = {id = 2460, chance = 2200}, -- Brass Helmet
[2] = {id = 2482, chance = 1870}, -- Studded Helmet
[3] = {id = 2459, chance = 1490}, -- Iron Helmet
[4] = {id = 2457, chance = 1010}, -- Steel Helmet
[5] = {id = 2491, chance = 190}, -- Crown Helmet
[6] = {id = 2497, chance = 10} -- Crusader Helmet
},
[9822] = { -- Slightly Rusted Helmet
[1] = {id = 2459, chance = 3156}, -- Iron Helmet
[2] = {id = 2457, chance = 2976}, -- Steel Helmet
[3] = {id = 2491, chance = 963}, -- Crown Helmet
[4] = {id = 2497, chance = 210}, -- Crusader Helmet
[5] = {id = 2498, chance = 7} -- Royal Helmet
},
[9817] = { -- Heavily Rusted Boots
},
[9818] = { -- Rusted Boots
},
[9819] = { -- Slightly Rusted Boots
},
}
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
local targetItem = config[target.itemid]
if not targetItem then
return true
end
local randChance = math.random(10000)
local index = false
if targetItem[1].chance >= randChance then -- implying first item in the table index always has the highest chance.
while not index do
randomIndex = math.random(#targetItem)
if targetItem[randomIndex].chance >= randChance then
index = randomIndex
end
end
end
if not index then
if isInArray({9808, 9809, 9810}, target.itemid) then msg = "The armor was already damaged so badly that it broke when you tried to clean it." end
if isInArray({9811, 9812, 9813}, target.itemid) then msg = "The legs were already damaged so badly that they broke when you tried to clean them." end
if isInArray({9814, 9815, 9816}, target.itemid) then msg = "The shield was already damaged so badly that it broke when you tried to clean it." end
if isInArray({9817, 9818, 9819}, target.itemid) then msg = "The boots were already damaged so badly that they broke when you tried to clean them." end
if isInArray({9820, 9821, 9822}, target.itemid) then msg = "The helmet was already damaged so badly that it broke when you tried to clean it." end
doCreatureSay(cid, msg, TALKTYPE_ORANGE_1)
doSendMagicEffect(fromPosition, CONST_ME_BLOCKHIT)
doPlayerRemoveItem(cid, target.itemid, 1)
else
doTransformItem(target.uid, targetItem[index].id, ...)
doSendMagicEffect(fromPosition, CONST_ME_MAGIC_GREEN)
end
return doPlayerRemoveItem(cid, item.itemid, 1)
end