elnelson
Lunaria World Dev
hello, otlanders. i have this system that gives durability like diablo to items. but it does not set an item description when i try it.
this is the script
this is the script
Lua:
local chance = 1
function getItemsBody(cid)
local items = {}
for i=1,8 do
if(isPlayer(cid) and getPlayerSlotItem(cid, i).uid ~= (nil or 0) and i ~= (3 and 2))then
table.insert(items, getPlayerSlotItem(cid, i))
end
end
return items
end
function getItemArmor(uid)
if type(uid) == 'number' then
return getItemAttribute(uid,'armor')
else
return getItemInfo(uid.itemid).armor
end
end
function isArmor(uid)
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)
uid = uid or 0
local f = getItemWeaponType(uid)
if f == 1 or f == 2 or f == 3 or f == 5 then
return true
end
return false
end
function onCombat(cid, target, item, words, param)
for i,v in pairs(getItemsBody(cid)) do
local z = getItemAttribute(v.uid, "Durability")
if isArmor(v) == true or isWeapon(v.uid) == true then
if z == nil then
doItemSetAttribute(v.uid, "Durability", "Durability: 10/10")
return true
else
if math.random(1,100) <= chance then
local c = string.match(z, "Durability: (.+)/10")
if (z == "Durability: 10/10") then
local c = 9
doItemSetAttribute(v.uid, "Durability", "Durability: "..c.."/10")
doSendMagicEffect(getCreaturePosition(cid), 34)
elseif (z == "Durability: 0/10")then
doItemSetAttribute(v.uid, "name", getItemNameById(v.itemid))
doTransformItem(v.uid,2256)
else
local c = c-1
doSendMagicEffect(getCreaturePosition(cid), 34)
doItemSetAttribute(v.uid, "Durability", "Durability: "..c.."/10")
local b = getItemAttribute(v.uid, "Durability")
local name = getItemNameById(v.itemid)
doItemSetAttribute(v.uid , "name", name.." ("..b..")")
end
end
end
end
end
return true
end
function onLogin(cid)
registerCreatureEvent(cid, "Durability")
return true
end