• 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 1.X+ Get item absorbPercent of element

Sajgon

Advanced OT User
Joined
Mar 10, 2017
Messages
282
Solutions
3
Reaction score
237
Location
Sweden
Hello, I want to get the value of absorbPercentPhysical for an item, is this possible?

TFS 1.2+


Exampleitem might ring.

HTML:
  <item id="2164" article="a" name="might ring">
        <attribute key="slotType" value="ring" />
        <attribute key="charges" value="20" />
        <attribute key="showcharges" value="1" />
        <attribute key="absorbPercentPhysical" value="20" />
        <attribute key="absorbPercentMagic" value="20" />
        <attribute key="showattributes" value="1" />
    </item>

I want to reach the value 20.

I have tried this method
Code:
 item:getAttribute(key)
but it's not working for absorbPercent attributes it seems. What can I try?

Kind regards,
Sajgon
 
Last edited:
Solution
Hello
1:
In luascript.h, before
C++:
static int luaItemTypeGetElementType(lua_State* L);
add this
C++:
static int luaItemTypeGetAbsorbPercent(lua_State* L);

2.1:
Now go to luascript.cpp, before
C++:
registerMethod("ItemType", "getElementType", LuaScriptInterface::luaItemTypeGetElementType);
add this
C++:
registerMethod("ItemType", "getAbsorbPercent", LuaScriptInterface::luaItemTypeGetAbsorbPercent);

2.2:
In luascript.cpp, before function
C++:
int LuaScriptInterface::luaItemTypeGetElementType(lua_State* L)
add this
C++:
int LuaScriptInterface::luaItemTypeGetAbsorbPercent(lua_State* L)
{
    // itemType:getAbsorbPercent()
    const ItemType* itemType = getUserdata<const ItemType>(L, 1);
    if (!itemType) {
        lua_pushnil(L)...
Item.getAttribute(key)
Code:
ITEM_ATTRIBUTE_NONE     
         ITEM_ATTRIBUTE_ACTIONID     
         ITEM_ATTRIBUTE_UNIQUEID     
         ITEM_ATTRIBUTE_DESCRIPTION     
         ITEM_ATTRIBUTE_TEXT     
         ITEM_ATTRIBUTE_DATE     
         ITEM_ATTRIBUTE_WRITER     
         ITEM_ATTRIBUTE_NAME     
         ITEM_ATTRIBUTE_ARTICLE     
         ITEM_ATTRIBUTE_PLURALNAME     
         ITEM_ATTRIBUTE_WEIGHT     
         ITEM_ATTRIBUTE_ATTACK     
         ITEM_ATTRIBUTE_DEFENSE     
         ITEM_ATTRIBUTE_EXTRADEFENSE     
         ITEM_ATTRIBUTE_ARMOR     
         ITEM_ATTRIBUTE_HITCHANCE     
         ITEM_ATTRIBUTE_SHOOTRANGE     
         ITEM_ATTRIBUTE_OWNER     
         ITEM_ATTRIBUTE_DURATION     
         ITEM_ATTRIBUTE_DECAYSTATE     
         ITEM_ATTRIBUTE_CORPSEOWNER     
         ITEM_ATTRIBUTE_CHARGES     
         ITEM_ATTRIBUTE_FLUIDTYPE     
         ITEM_ATTRIBUTE_DOORID
only those attributes you can get with this function.
 
Hello
1:
In luascript.h, before
C++:
static int luaItemTypeGetElementType(lua_State* L);
add this
C++:
static int luaItemTypeGetAbsorbPercent(lua_State* L);

2.1:
Now go to luascript.cpp, before
C++:
registerMethod("ItemType", "getElementType", LuaScriptInterface::luaItemTypeGetElementType);
add this
C++:
registerMethod("ItemType", "getAbsorbPercent", LuaScriptInterface::luaItemTypeGetAbsorbPercent);

2.2:
In luascript.cpp, before function
C++:
int LuaScriptInterface::luaItemTypeGetElementType(lua_State* L)
add this
C++:
int LuaScriptInterface::luaItemTypeGetAbsorbPercent(lua_State* L)
{
    // itemType:getAbsorbPercent()
    const ItemType* itemType = getUserdata<const ItemType>(L, 1);
    if (!itemType) {
        lua_pushnil(L);
        return 1;
    }

    auto& abilities = itemType->abilities;
    if (abilities) {
        lua_createtable(L, COMBAT_COUNT, 0);
        int index = 0;

        for (size_t i = 0; i < COMBAT_COUNT; ++i) {
            if (abilities->absorbPercent[i] == 0) {
                continue;
            }
            lua_createtable(L, 0, 3);
            setField(L, "combattype", indexToCombatType(i));
            setField(L, "combatname", getCombatName(indexToCombatType(i)));
            setField(L, "absorbpercent", abilities->absorbPercent[i]);
            lua_rawseti(L, -2, ++index);
        }
    } else {
        lua_pushnil(L);
    }
    return 1;   
}

3:
to use in lua file:
Lua:
    for i, v in    pairs(item:getType():getAbsorbPercent()) do
        print(i .. " - " .. v.combatname .. " - " .. v.combattype .. " - " .. v.absorbpercent)       
    end

output:
Code:
1 - energy - 2.0 - -3.0
2 - ice - 512.0 - 3.0
 
Solution
This script show how many protectionall my char have?
Exemple:
I use Helmet (+7% protection all) and Armor (+8 protection all), when i use commands show like : You have +15% protection all

Its like that?
 
Back
Top