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

Transform Item Function

manolete66

New Member
Joined
Jul 9, 2018
Messages
24
Reaction score
4
Im starting programming scripts and idk where could i find this function for a item class. I searched in item.h, items.h and a lot of other class defined into.
Some ideas?
 
Solution
CODE:
--------------------------------------------------------------------------------
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if player:getName() == "Prueba" then
item:transform(2160) <-- Im asking for where is the function "transform" in the code (i suppose that is in a cpp file)
return true
end
return false
end
--------------------------------------------------------------------------------

Im just starting with scripting in lua for tibia and idk so much from this librarys or where the functions are called.
Again, luascript.cpp.

C++:
registerMethod("Item", "transform", LuaScriptInterface::luaItemTransform);
// ...
int...
I didnt explain me good. I created a lua script in which i invoke "function onUse(player, item, ....)". I suppose that this argument item is a "Item class" defined into item.cpp. Then if i use the method "item:transform(2160)" supposing this item argument contents 100 gold coins, it works and convert the item into 100 crystal coins. The question is, where is the definition of this method or function "transform"?
 
CODE:
--------------------------------------------------------------------------------
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if player:getName() == "Prueba" then
item:transform(2160) <-- Im asking for where is the function "transform" in the code (i suppose that is in a cpp file)
return true
end
return false
end
--------------------------------------------------------------------------------

Im just starting with scripting in lua for tibia and idk so much from this librarys or where the functions are called.
 
CODE:
--------------------------------------------------------------------------------
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if player:getName() == "Prueba" then
item:transform(2160) <-- Im asking for where is the function "transform" in the code (i suppose that is in a cpp file)
return true
end
return false
end
--------------------------------------------------------------------------------

Im just starting with scripting in lua for tibia and idk so much from this librarys or where the functions are called.
Again, luascript.cpp.

C++:
registerMethod("Item", "transform", LuaScriptInterface::luaItemTransform);
// ...
int LuaScriptInterface::luaItemTransform(lua_State* L)
{
    // item:transform(itemId[, count/subType = -1])
    Item** itemPtr = getRawUserdata<Item>(L, 1);
    if (!itemPtr) {
        lua_pushnil(L);
        return 1;
    }

    Item*& item = *itemPtr;
    if (!item) {
        lua_pushnil(L);
        return 1;
    }

    uint16_t itemId;
    if (isNumber(L, 2)) {
        itemId = getNumber<uint16_t>(L, 2);
    } else {
        itemId = Item::items.getItemIdByName(getString(L, 2));
        if (itemId == 0) {
            lua_pushnil(L);
            return 1;
        }
    }

    int32_t subType = getNumber<int32_t>(L, 3, -1);
    if (item->getID() == itemId && (subType == -1 || subType == item->getSubType())) {
        pushBoolean(L, true);
        return 1;
    }

    const ItemType& it = Item::items[itemId];
    if (it.stackable) {
        subType = std::min<int32_t>(subType, 100);
    }

    ScriptEnvironment* env = getScriptEnv();
    uint32_t uid = env->addThing(item);

    Item* newItem = g_game.transformItem(item, itemId, subType);
    if (item->isRemoved()) {
        env->removeItemByUID(uid);
    }

    if (newItem && newItem != item) {
        env->insertItem(uid, newItem);
    }

    item = newItem;
    pushBoolean(L, true);
    return 1;
}
 
Solution

Similar threads

Back
Top