• 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 TFS 0.3.7 - Move item into container.. how?

  • Thread starter Thread starter Xikini
  • Start date Start date
X

Xikini

Guest
Using a script only, how do I move this magic lightwand into that bag?

sY9ek4s.png


I've looked around for about 2 hours and haven't found a way to move an item into a container.

Thanks in advance.

:p
 
Solution
oh right, it has to be a virtual cylinder, not an existing one
aka you have to use doCreateItemEx then use that virtual uid to add to container
not sure anymore if you can actually do this, unless you copy the item and remove it
Looked through the source. Only finding some functions like Game :: playerMoveItem which depends on a player moving it.

Looks like all it does is remove and add tho. You can try to retrieve item unique id (not itemid), add it as a param for additem function and see if that moves the current item.
 
hmm, so I've tried this..
LUA:
local pos1 = {x = 147, y = 72, z = 8, stackpos = 1}
local pos2 = {x = 148, y = 72, z = 8, stackpos = 1}

function onUse(cid, item, fromPosition, itemEx, toPosition)
   print(1)
   local target = getThingFromPos(pos1).uid
   local container = getThingFromPos(pos2).uid
   print(target, container)
   doAddContainerItemEx(container, target)
   print(2)
   return true
end
Code:
1
103565
103566
2

1
103592
103593
2

Nothing appears in the bag.
No errors in console.

I also looked for some function to 'copy' the item, then add that virtual item into the container, but a quick search through the source didn't find any lua function like that.

Any other idea's?
Or suggestions to change my code?

Can I teleport the item into the container? xD
 
had the wrong function, try this? doAddContainerItemEx(uid, virtuid)
use print(doAddContainerItemEx(uid, virtuid)) to show what the return of the function is (true/false)
 
had the wrong function, try this? doAddContainerItemEx(uid, virtuid)
use print(doAddContainerItemEx(uid, virtuid)) to show what the return of the function is (true/false)

I hope this is what you meant?
LUA:
local pos1 = {x = 147, y = 72, z = 8, stackpos = 1}
local pos2 = {x = 148, y = 72, z = 8, stackpos = 1}

function onUse(cid, item, fromPosition, itemEx, toPosition)
   print(1)
   local target = getThingFromPos(pos1).uid
   local container = getThingFromPos(pos2).uid
   print(target, container)
   doAddContainerItemEx(container, target)
   print(doAddContainerItemEx(container, target))
   print(2)
   return true
end
Code:
1
113464
113465
false
2
Code:
int32_t LuaInterface::luaDoAddContainerItemEx(lua_State* L)
{
   //doAddContainerItemEx(uid, virtuid)
   uint32_t virtuid = popNumber(L);
   ScriptEnviroment* env = getEnv();
   if(Container* container = env->getContainerByUID(popNumber(L)))
   {
       Item* item = env->getItemByUID(virtuid);
       if(!item)
       {
           errorEx(getError(LUA_ERROR_ITEM_NOT_FOUND));
           lua_pushboolean(L, false);
           return 1;
       }

       if(item->getParent() != VirtualCylinder::virtualCylinder)
       {
           lua_pushboolean(L, false);
           return 1;
       }

       ReturnValue ret = g_game.internalAddItem(NULL, container, item);
       if(ret == RET_NOERROR)
           env->removeTempItem(env, item);

       lua_pushnumber(L, ret);
       return 1;
   }
   else
   {
       errorEx(getError(LUA_ERROR_CONTAINER_NOT_FOUND));
       lua_pushboolean(L, false);
       return 1;
   }
}
 
oh right, it has to be a virtual cylinder, not an existing one
aka you have to use doCreateItemEx then use that virtual uid to add to container
not sure anymore if you can actually do this, unless you copy the item and remove it
 
Solution
I also looked for some function to 'copy' the item, then add that virtual item into the container, but a quick search through the source didn't find any lua function like that.
Mm, I thought of that too, but I couldn't find any 'copy item' function.
clone/copy/mirror/duplicate

Not sure what else I can look for.
 
Last edited by a moderator:
is there not doCopyItem in 0.3.7?

cvQlBOy.png


LUA:
function doCopyItem(item, attributes)
   local attributes = ((type(attributes) == 'table') and attributes or { "aid" })

   local ret = doCreateItemEx(item.itemid, item.type)
   for _, key in ipairs(attributes) do
       local value = getItemAttribute(item.uid, key)
       if(value ~= nil) then
           doItemSetAttribute(ret, key, value)
       end
   end

   if(isContainer(item.uid)) then
       for i = (getContainerSize(item.uid) - 1), 0, -1 do
           local tmp = getContainerItem(item.uid, i)
           if(tmp.itemid > 0) then
               doAddContainerItemEx(ret, doCopyItem(tmp, true).uid)
           end
       end
   end

   return getThing(ret)
end

I found above in 050-function.lua

but upon experimenting with it, I haven't been able to get anything to work properly.

Using below script, I was able to copy items, but just the item..
So it makes me think that I need to find an 'attribute list' somewhere to create a table to interate through.

LUA:
local pos1 = {x = 147, y = 72, z = 8, stackpos = 1}
local pos2 = {x = 148, y = 72, z = 8, stackpos = 1}
function onUse(cid, item, fromPosition, itemEx, toPosition)
   print(1)
   local target = getThingFromPos(pos1)
   local container = getThingFromPos(pos2)
   print(target.uid, container.uid)
   
   local attributes = ((type(attributes) == 'table') and attributes or { "aid" })
   
   local ret = doCreateItemEx(target.itemid, target.type)
   for _, key in ipairs(attributes) do
       local value = getItemAttribute(target.uid, key)
       if(value ~= nil) then
           doItemSetAttribute(ret, key, value)
       end
   end
   
   doAddContainerItemEx(container.uid, ret)
   print(2)
   return true
end

in itemloader.h
I found these, but I'm not sure how to utilize them.. and it doesn't appear to be a full list of attributes.. soo eh
Code:
enum itemattrib_t
{
   ITEM_ATTR_FIRST = 0x10,
   ITEM_ATTR_SERVERID = ITEM_ATTR_FIRST,
   ITEM_ATTR_CLIENTID,
   ITEM_ATTR_NAME,
   ITEM_ATTR_DESCR,
   ITEM_ATTR_SPEED,
   ITEM_ATTR_SLOT,
   ITEM_ATTR_MAXITEMS,
   ITEM_ATTR_WEIGHT,
   ITEM_ATTR_WEAPON,
   ITEM_ATTR_AMU,
   ITEM_ATTR_ARMOR,
   ITEM_ATTR_MAGLEVEL,
   ITEM_ATTR_MAGFIELDTYPE,
   ITEM_ATTR_WRITEABLE,
   ITEM_ATTR_ROTATETO,
   ITEM_ATTR_DECAY,
   ITEM_ATTR_SPRITEHASH,
   ITEM_ATTR_MINIMAPCOLOR,
   ITEM_ATTR_07,
   ITEM_ATTR_08,
   ITEM_ATTR_LIGHT,
   ITEM_ATTR_DECAY2,
   ITEM_ATTR_WEAPON2,
   ITEM_ATTR_AMU2,
   ITEM_ATTR_ARMOR2,
   ITEM_ATTR_WRITEABLE2,
   ITEM_ATTR_LIGHT2,
   ITEM_ATTR_TOPORDER,
   ITEM_ATTR_WRITEABLE3,
   ITEM_ATTR_WAREID,
   ITEM_ATTR_LAST
};
 
Last edited by a moderator:

Similar threads

Back
Top