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

TFS 0.X durability system

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
583
Solutions
2
Reaction score
60
Location
México
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
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
 
i think you should use
Code:
function onLook(cid, thing, position, lookDistance)
with your
scripts ( keep knowing this function place is creaturescripts )
 
You mean, changing on combat to onlook?
If you did that the script will not work because combat is not for looking on item only as i see here is example script :
Lua:
function onLook(cid, thing, position, lookDistance)
local quests = {2272, 2263, 2307, 2264, 7425, 7959, 8980, 8926, 2350, 2538, 8927, 6531, 5927, 7735, 7443, 7439, 2357, 2127, 2131, 2299, 2122, 2283, 11113, 11387}
local completed = {}
    if isPlayer(thing.uid) then
        for i = 1, #quests do
            if getPlayerStorageValue(thing.uid, quests[i]) > 0 then
                table.insert(completed, 1)
            end
        end
        doPlayerSetSpecialDescription(thing.uid, (getPlayerSex(thing.uid) == 0 and ".\nShe" or ".\nHe") .. " has completed ".. #completed .. "/" .. #quests .. " quests")
        doPlayerSendTextMessage(cid, 27, getPlayerName(thing.uid) .. " has completed " .. #completed .. "/" .. #quests .. " quests.")
    end
return true
end
this script os onlook on player not item
You can do that same for items anyway
 
Back
Top