• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Feature Durability System

tetra20

DD
Joined
Jan 17, 2009
Messages
1,315
Solutions
4
Reaction score
323
Location
Egypt
Hi.I Am New to C++ and learned few basics and started to go in programming in open tibia.i want to release my first system that i made it.

How It Work
You Add This Code in items.xml
Code:
<attribute key="durability" value="100"/>
Durability Can't Be Higher Than 100
And Use the Lua Script Here

Warning:If You are Using 0.3.6 add all this except the one with * And Then Add This
http://otland.net/threads/durability-system.202358/#post-1945197
-----
Open items.h

Find
Code:
int32_t attack, criticalHitChance, extraAttack, defense, extraDefense, armor, breakChance, hitChance, maxHitChance, runeLevel, runeMagLevel, lightLevel, lightColor, decayTo, rotateTo, alwaysOnTopOrder;

Replace
Code:
int32_t attack, criticalHitChance, extraAttack, defense, extraDefense, armor, breakChance, hitChance, maxHitChance, runeLevel, runeMagLevel, lightLevel, lightColor, decayTo, rotateTo, alwaysOnTopOrder, durability;

Open item.h
find:

Code:
ATTR_SCRIPTPROTECTED = 42,

Add After It(Don't Forget The Comma)

Code:
ATTR_DURABILITY = 43

Find
Code:
int32_t getAttack() const;

Add After It


Code:
int32_t getDurability() const;

Find
Code:
inline int32_t Item::getExtraAttack() const
{
    bool ok;
    int32_t v = getIntegerAttribute("extraattack", ok);
    if(ok)
        return v;

    return items[id].extraAttack;
}

Add After It
*******
If You are Using 0.3.6 Don't Add This

Code:
inline int32_t Item::getDurability() const
{
  bool ok;
   int32_t v = getIntegerAttribute("durability", ok);
   if(ok)
     return v;

  return items[id].durability;
}

Open Item.cpp

Find
Code:
case ATTR_EXTRAATTACK:
     {
       int32_t attack;
       if(!propStream.getLong((uint32_t&)attack))
         return ATTR_READ_ERROR;

       setAttribute("extraattack", attack);
       break;
     }

Add After It
******
If You are Using 0.3.6 Don't Add This

Code:
case ATTR_DURABILITY:
      {
       int32_t durability;
       if(!propStream.getLong((uint32_t&)durability))
         return ATTR_READ_ERROR;

        setAttribute("durability", durability);
        break;
      }

Find
Code:
  if(it.defense || it.extraDefense || (item && (item->getDefense() || item->getExtraDefense())))
       {
         if(begin)
         {
           begin = false;
           s << " (";
         }
         else
           s << ", ";

         s << "Def:" << int32_t(item ? item->getDefense() : it.defense);
         if(it.extraDefense || (item && item->getExtraDefense()))
           s << " " << std::showpos << int32_t(item ? item->getExtraDefense() : it.extraDefense) << std::noshowpos;
       }
     }

Add After It

Code:
if(it.durability || (item && item->getDurability()))
{
if(begin)
{
begin = false;
s << " (";
}
else
s << ", ";

s << "Durability:" << int32_t(item ? item->getDurability() : it.durability) << "/100"<< std::noshowpos;
}
Open items.cpp

Find
Code:
Armor = 0;
Add After It
Code:
    durability = 0;

Find
Code:
else if(tmpStrValue == "weight")
        {
            if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.weight = intValue / 100.f;
        }

Add After It

Code:
else if(tmpStrValue == "durability")
        {
            if(readXMLInteger(itemAttributesNode, "value", intValue))
                it.durability = intValue;
        }

Luascript.cpp
Find
Code:
int32_t LuaInterface::luaDoCleanHouse(lua_State* L)
{
    //doCleanHouse(houseId)
    uint32_t houseId = popNumber(L);
    if(House* house = Houses::getInstance()->getHouse(houseId))
    {
        house->clean();
        lua_pushboolean(L, true);
    }
    else
        lua_pushboolean(L, false);

    return 1;
}

Add This After It
*******
If You are Using 0.3.6 Don't Add This

Code:
int32_t LuaInterface::luaGetItemDurability(lua_State* L)
    {
    ScriptEnviroment* env = getEnv();
    Item* item = env->getItemByUID(popNumber(L));
    if(!item)
        {
            lua_pushboolean(L, false);
            errorEx(getError(LUA_ERROR_ITEM_NOT_FOUND));
            return 1;
        }
        lua_pushnumber(L, item->getDurability());
        return 1;
    }

Find
Code:
//getTownId(townName)
   lua_register(m_luaState, "getTownId", LuaInterface::luaGetTownId);

add This After It
********
If You are Using 0.3.6 Don't Add This
Code:
//getItemDurability(uid, durability)
   lua_register(m_luaState, "getItemDurability", LuaInterface::luaGetItemDurability);

luascript.h

Find

Code:
static int32_t luaDoCreatureSetSpeakType(lua_State* L);

Add This After It

Code:
static int32_t luaGetItemDurability(lua_State* L);

ScreenShot:
ffJJaj.png



Compile and Done.Tested on 0.3.7 if you are using 0.4 you will have to change few things

Next System will be Price:x$
 
Last edited:
A simple Lua Scripts. if anyone can edit it :
Code:
function onStatsChange(cid, target, type, combat, value)

if getPlayerSlotItem(cid,1).itemid == 0 or getPlayerSlotItem(cid,4).itemid == 0 or getPlayerSlotItem(cid,5).itemid == 0 or getPlayerSlotItem(cid,6).itemid == 0 or getPlayerSlotItem(cid,7).itemid == 0 or getPlayerSlotItem(cid,8).itemid == 0 then
return true
end

if not getItemAttribute(getPlayerSlotItem(cid, 1).uid, 'durability') then
return true
end

if not getItemAttribute(getPlayerSlotItem(cid, 4).uid, 'durability') then
return true
end

if not getItemAttribute(getPlayerSlotItem(cid, 5).uid, 'durability') then
return true
end

if not getItemAttribute(getPlayerSlotItem(cid, 6).uid, 'durability') then
return true
end

if not getItemAttribute(getPlayerSlotItem(cid, 7).uid, 'durability') then
return true
end

if not getItemAttribute(getPlayerSlotItem(cid, 8).uid, 'durability') then
return true
end

if getItemDurability(getPlayerSlotItem(cid, 1).uid) == 0 and type == 1 then
doRemoveItem(getPlayerSlotItem(cid, 1).uid, 1)
elseif getItemDurability(getPlayerSlotItem(cid, 1).uid) <= 2 and type == 1 then
    doPlayerSendTextMessage(cid, 27,"Please Go Repair Your Equipment")
    doItemSetAttribute(getPlayerSlotItem(cid, 1).uid, 'durability', getItemDurability(getPlayerSlotItem(cid, 1).uid) - 1)
    doPlayerSendTextMessage(cid, 27,"Your Helmet Durability Have Decreased To "..getItemDurability(getPlayerSlotItem(cid, 1).uid).."")
elseif 0.1 >= math.random(0,100) and type == 1 then
    doItemSetAttribute(getPlayerSlotItem(cid, 1).uid, 'durability', getItemDurability(getPlayerSlotItem(cid, 1).uid) - 1)
doPlayerSendTextMessage(cid, 27,"Your Helmet Durability Have Decreased To "..getItemDurability(getPlayerSlotItem(cid, 1).uid).."")
    return true
    end

    if getItemDurability(getPlayerSlotItem(cid, 4).uid) == 0 and type == 1 then
doRemoveItem(getPlayerSlotItem(cid, 4).uid, 1)
elseif getItemDurability(getPlayerSlotItem(cid, 4).uid) <= 2 and type == 1 then
    doPlayerSendTextMessage(cid, 27,"Please Go Repair Your Equipment")
        doItemSetAttribute(getPlayerSlotItem(cid, 4).uid, 'durability', getItemDurability(getPlayerSlotItem(cid, 4).uid) - 1)
        doPlayerSendTextMessage(cid, 27,"Your Armor Durability Have Decreased To "..getItemDurability(getPlayerSlotItem(cid, 4).uid).."")
elseif 0.1 >= math.random(0,100) and type == 1 then
    doItemSetAttribute(getPlayerSlotItem(cid, 4).uid, 'durability', getItemDurability(getPlayerSlotItem(cid, 4).uid) - 1)
doPlayerSendTextMessage(cid, 27,"Your Armor Durability Have Decreased To "..getItemDurability(getPlayerSlotItem(cid, 4).uid).."")
    return true
    end
 
        if getItemDurability(getPlayerSlotItem(cid, 5).uid) == 0 and type == 1 then
doRemoveItem(getPlayerSlotItem(cid, 5).uid, 1)
elseif getItemDurability(getPlayerSlotItem(cid,5).uid) <= 2 and type == 1 then
    doPlayerSendTextMessage(cid, 27,"Please Go Repair Your Equipment")
        doItemSetAttribute(getPlayerSlotItem(cid, 5).uid, 'durability', getItemDurability(getPlayerSlotItem(cid, 5).uid) - 1)
doPlayerSendTextMessage(cid, 27,"Your Shield Durability Have Decreased To "..getItemDurability(getPlayerSlotItem(cid, 5).uid).."")
elseif 0.1 >= math.random(0,100) and type == 1 then
    doItemSetAttribute(getPlayerSlotItem(cid, 5).uid, 'durability', getItemDurability(getPlayerSlotItem(cid, 5).uid) - 1)
doPlayerSendTextMessage(cid, 27,"Your Shield Durability Have Decreased To "..getItemDurability(getPlayerSlotItem(cid, 5).uid).."")
    return true
    end
 
    if getItemDurability(getPlayerSlotItem(cid, 6).uid) == 0 and type == 1 then
doRemoveItem(getPlayerSlotItem(cid, 6).uid, 1)
elseif getItemDurability(getPlayerSlotItem(cid, 6).uid) <= 2 and type == 1 then
    doPlayerSendTextMessage(cid, 27,"Please Go Repair Your Equipment")
        doItemSetAttribute(getPlayerSlotItem(cid, 6).uid, 'durability', getItemDurability(getPlayerSlotItem(cid, 6).uid) - 1)
doPlayerSendTextMessage(cid, 27,"Your Sword Durability Have Decreased To "..getItemDurability(getPlayerSlotItem(cid, 6).uid).."")
elseif 0.1 >= math.random(0,100) and type == 1 then
    doItemSetAttribute(getPlayerSlotItem(cid, 6).uid, 'durability', getItemDurability(getPlayerSlotItem(cid, 6).uid) - 1)
doPlayerSendTextMessage(cid, 27,"Your Sword Durability Have Decreased To "..getItemDurability(getPlayerSlotItem(cid, 6).uid).."")
    return true
    end
 
if getItemDurability(getPlayerSlotItem(cid, 7).uid) == 0 and type == 1 then
doRemoveItem(getPlayerSlotItem(cid, 7).uid, 1)
elseif getItemDurability(getPlayerSlotItem(cid, 1).uid) <= 2 and type == 1 then
    doPlayerSendTextMessage(cid, 27,"Please Go Repair Your Equipment")
        doItemSetAttribute(getPlayerSlotItem(cid, 7).uid, 'durability', getItemDurability(getPlayerSlotItem(cid, 7).uid) - 1)
doPlayerSendTextMessage(cid, 27,"Your  Legs Have Decreased To "..getItemDurability(getPlayerSlotItem(cid, 7).uid).."")
elseif 0.1 >= math.random(0,100) and type == 1 then
    doItemSetAttribute(getPlayerSlotItem(cid, 7).uid, 'durability', getItemDurability(getPlayerSlotItem(cid, 7).uid) - 1)
doPlayerSendTextMessage(cid, 27,"Your  Legs Have Decreased To "..getItemDurability(getPlayerSlotItem(cid, 7).uid).."")
    return true
    end
 
    if getItemDurability(getPlayerSlotItem(cid, 8).uid) == 0 and type == 1 then
doRemoveItem(getPlayerSlotItem(cid, 8).uid, 1)
elseif getItemDurability(getPlayerSlotItem(cid, 8).uid) <= 2 and type == 1 then
    doPlayerSendTextMessage(cid, 27,"Please Go Repair Your Equipment")
        doItemSetAttribute(getPlayerSlotItem(cid, 8).uid, 'durability', getItemDurability(getPlayerSlotItem(cid, 8).uid) - 1)
doPlayerSendTextMessage(cid, 27,"Your Boots Durability Have Decreased To "..getItemDurability(getPlayerSlotItem(cid, 8).uid).."")
elseif 0.1 >= math.random(0,100) and type == 1 then
    doItemSetAttribute(getPlayerSlotItem(cid, 8).uid, 'durability', getItemDurability(getPlayerSlotItem(cid, 8).uid) - 1)
doPlayerSendTextMessage(cid, 27,"Your Boots Durability Have Decreased To "..getItemDurability(getPlayerSlotItem(cid, 8).uid).."")
    end
    return true
    end
 
Last edited:
Warning:
Don't Add This unless you added what is in the first Thread

For 0.3.6
Open item.cpp
Find
Code:
case ATTR_EXTRAATTACK:
    {
      int32_t attack;
      if(!propStream.GET_ULONG((uint32_t&)attack))
        return ATTR_READ_ERROR;

      setAttribute("extraattack", attack);
      break;
    }

Add This After It
Code:
case ATTR_DURABILITY:
      {
      int32_t durability;
      if(!propStream.GET_ULONG((uint32_t&)durability))
        return ATTR_READ_ERROR;

        setAttribute("durability", durability);
        break;
      }

Open item.h

Find
Code:
inline int32_t Item::getExtraAttack() const
{
   const int32_t* v = getIntegerAttribute("extraattack");
   if(v)
     return *v;

   return items[id].extraAttack;
}

Add This After It

Code:
inline int32_t Item::getDurability() const
{
  const int32_t* v = getIntegerAttribute("durability");
  if(v)
    return *v;

  return items[id].durability;
}

Open LuaScripts.cpp

and Change
Code:
int32_t LuaInterface::luaGetItemDurability(lua_State* L)
To
Code:
int32_t LuaScriptInterface::luaGetItemDurability(lua_State* L)
And
Code:
 lua_register(m_luaState, "getItemDurability", LuaInterface::luaGetItemDurability);
To
Code:
 lua_register(m_luaState, "getItemDurability", LuaScriptInterface::luaGetItemDurability);

And Done
 
Last edited:
F:\Source arton\item.h In member function `int32_t Item::getDurability() const':
F:\Source arton\item.h 'const class ItemType' has no member named 'durability'

Error.
 
you are trying to compile for 0.3.6 or 0.4?

and did you add this?
Code:
int32_t getDurability() const;
Please try adding the code again
 
Very very nice!
Thanks for the release..

One question tho, on the lua script, is that going to be for creaturescripts or movements?
 
creaturescript
To Fix Attribute of A Set:
A Talkaction:(Not Tested)
Code:
function onSay(cid, words, param)
local slots = {1,4,5,6,7}
if exhaustion.check(cid, 4029) then
doPlayerSendCancel(cid, "You Need To Wait "..exhaustion.get(cid,4029).." To Reuse This Action")
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
return true
end

for i = 1, #slots do
doItemSetAttribute(getPlayerSlotItem(cid, i).uid, 'durability', 100)
exhaustion.set(cid,4029,30)
end
return true
end
 
Last edited:
Back
Top