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

Lua Copy item attributes

Joined
Apr 15, 2014
Messages
75
Reaction score
18
I need to clone an item and it must be in a way that all these item's attributes get copied. Is there any way to do so? (even if its done with c++)

thanks
 
I don't know if you know, it's not possible to create two identical items ( sprite ); but you can create a copy of the special item , this it what do you want ???


I need to clone an item and it must be in a way that all these item's attributes get copied. Is there any way to do so? (even if its done with c++)

thanks
 
I don't know if you know, it's not possible to create two identical items ( sprite ); but you can create a copy of the special item , this it what do you want ???

No, I need to do it in game. Like copying a ring and copying its duration all along.

cant you just use item:clone() in tfs 1.x?
Im using tfs 0.4 and as far as I know there are no similar functions in this version... I will take a look at the one made for 1.x anyway to see if I can use something
 
Could you be more specific.

Lets supose a player have a ring with 86 seconds of duration and I want to make an exact copy of this ring. Which means I want to create another item with the same ID and the same duration attribute.
Or a player have an armor with an special description and I want to make an exact copy of this armor.

So what I want is a generic way to copy ALL attributes of an item so I can create another one with the same attributes.
 
Lets supose a player have a ring with 86 seconds of duration and I want to make an exact copy of this ring. Which means I want to create another item with the same ID and the same duration attribute.
Or a player have an armor with an special description and I want to make an exact copy of this armor.

So what I want is a generic way to copy ALL attributes of an item so I can create another one with the same attributes.
So basically you want to intentionally dupe items.
 
No there is no such function for 0.4, you could do it with lua but you would need all attributes in a table to iterate over them and set in the new item or you can just do a simple new function to clone it:

Code:
int32_t LuaScriptInterface::luaDoCreateItemEx(lua_State* L)
{
    //doCloneItem(uid)
    ScriptEnviroment* env = getEnv();
    Item* item = env->getItemByUID(popNumber(L));
    if(!item) {
        errorEx(getError(LUA_ERROR_ITEM_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
  
    Item* newItem = item->clone();
    if(!newItem) {
        errorEx(getError(LUA_ERROR_ITEM_NOT_FOUND));
        lua_pushboolean(L, false);
        return 1;
    }
  
    newItem->setParent(VirtualCylinder::virtualCylinder);
    env->addTempItem(env, newItem);
    lua_pushnumber(L, env->addThing(newItem));
    return 1;
}

That will create a cloned virtual item that you can then add it to the player with doPlayerAddItemEx
 
That's exacatly what I was looking for, Ill test it to see what happens :)

I thought about doing it by iterating a table but I didnt want to go through all attributes with an iteration
 
Back
Top