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

TFS [1.2] GetFullDescription

Homeslice

-anoyn/Rage the Mage
Joined
May 9, 2010
Messages
112
Solutions
2
Reaction score
66
Location
Canada
I couldn't find an easy way to get an item's full description using Lua. For example:

You see knight legs (Arm:8).
It can only be wielded properly by knights and paladins.
It weighs 70.00 oz.

In my case i added this functionality to see item stats in a Lua crafting system.

This requires source changes to do, so you will need to compile your own TFS exe.

In luascript.cpp Change:
C++:
registerMethod("ItemType", "getDescription", LuaScriptInterface::luaItemTypeGetDescription);
To:
C++:
registerMethod("ItemType", "getDescription", LuaScriptInterface::luaItemTypeGetDescription);
   registerMethod("ItemType", "getFullDescription", LuaScriptInterface::luaItemTypeGetFullDescription);

Above:
C++:
int LuaScriptInterface::luaItemTypeGetDescription(lua_State* L)
Add the following:
C++:
int LuaScriptInterface::luaItemTypeGetFullDescription(lua_State* L)
{
    // itemType:getFullDescription()
    const ItemType* itemType = getUserdata<const ItemType>(L, 1);
    if (itemType) {
        pushString(L, Item::getDescription(*itemType, 1, nullptr, -1, false));
    }
    else {
        lua_pushnil(L);
    }
    return 1;
}

In luascript.h
Change:
C++:
static int luaItemTypeGetDescription(lua_State* L);
To:
C++:
        static int luaItemTypeGetDescription(lua_State* L);
        static int luaItemTypeGetFullDescription(lua_State* L);

Now in your Lua scripts you can use: ItemType:getFullDescription()
 
This doesn't work?
C++:
int LuaScriptInterface::luaItemGetDescription(lua_State* L)
{
    // item:getDescription(distance)
    Item* item = getUserdata<Item>(L, 1);
    if (item) {
        int32_t distance = getNumber<int32_t>(L, 2);
        pushString(L, item->getDescription(distance));
    } else {
        lua_pushnil(L);
    }
    return 1;
}
 
Back
Top