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

tfs1.0 copy backpack (+insides!)?

Zyntax

*WannaBe Scripter*
Joined
Jan 27, 2010
Messages
533
Reaction score
40
Location
Lua & XML Section
update:
I'm as far as scanning for every BPs UID.
How to know which backpack belongs where and how to stack them backwards?

Code:
local function scanBp(uid, t)
local con = Container(uid)
print("scanbp "..#t.." size: "..con:getSize().." uid = "..uid)
   for i = (con:getSize()-1),0, -1 do
     local it = Item(con:getItem(i):getUniqueId())
     if it ~= nil then
       local type = ItemType(it:getId())
       if type:isContainer() then
         local uid = con:getItem(i):getUniqueId()
         table.insert(t, uid)
         scanBp(uid, t)
       end
     end
   end
end
  

function onUse(cid, item, fromPosition, itemEx, toPosition)
local p = Player(cid)
local bp = p:getSlotItem(3):getUniqueId()
local t = {}
scanBp(bp,t)

--[[
   local p = Player(cid)
   local dp = {}
   local old = Item(p:getSlotItem(3):getUniqueId())
   local oldc = Container(p:getSlotItem(3):getUniqueId())
   local i = 0
   local new = Game.createItem(old:getId(),1)
   local newc = Container(new:getUniqueId())
   while i < oldc:getSize() do
   local it = Item(oldc:getItem(i):getUniqueId())
   local type = ItemType(it:getId())
     if it ~= nil then
       newc:addItem(it:getId(), it:getCount())
     end
   i = i+1
   end
   p:addItemEx(newc)
   --]]
return true
end
24zd3m9.jpg



I guess this is too challenging... :)
 
Last edited:
Check my market script. I already rewrote doCopyItem function

Do a function which does same function if finds container.
Can't write it for you now, I'm posting via phone.
 
okay, function:
Code:
  function doCopyItem_extended(item)
     local ret = doCreateItemEx(item.itemid, item.type)

     if(item.actionid > 0) then
       doSetItemActionId(ret, item.actionid)
     end
     
     if Item(item.uid):getAttribute(8) ~= "" then
       doSetItemText(ret, Item(item.uid):getAttribute(8))
       Item(ret):setAttribute(16, Item(item.uid):getAttribute(16))
       Item(ret):setAttribute(32, Item(item.uid):getAttribute(32))
     end
     
     if Item(item.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) ~= "" then
       doSetItemSpecialDescription(ret, Item(item.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION))
     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_extended(tmp).uid)
         end
       end
     end

     return getThing(ret)
   end

example:
doPlayerAddItemEx(cid, doCopyItem_extended(getTileItemById({x = 268, y = 251, z = 7}, 1989)).uid)
 
Update to the latest 1.0 and simply do this.
Code:
local player = Player(cid)
player:addItemEx(item:clone())
 
Thanks for the response guys!
@zbizu I solved it with @Limos help, he reminded me of the "doCopyItem()" function.
It worked perfectly that way!

@Dalkon I can't seem to get the correct syntax... i am at tfs1.0

I'm trying:
local p = Player(cid)
local d = Container(corpse)

local i = Item(p:getSlotItem(3):getUniqueId()))
d:addItemEx(i:clone())
report = item already has a parent (not sure what that means :( )

then
local i = Item(p:getSlotItem(3):getId()))
report = i = nil

Im kinda lost here xD
 
WAAAA! those metamethods drive me crazy!!!!
I can't get this damn thing to work...

Code:
local p = Player(cid)
local d = Container(corpse)
local z = Item(p:getSlotItem(3):getUniqueId())
d:addItemEx(z:clone())
Error: item already has a parent
WTF is a PARENT xD
 
Aight, Ill compile the new one later, thanks for the hint @zbizu

One thing though, i tried like 10000 combinations until now and I noticed, if i do

local z = Item(p:getSlotItem(3)):getUniqueId()
d:addItemEx(z)

then it tells me that "z" may be a "nil" value, BUT it copies the whole BP like it should do without using "clone()"

I guess that's just a bug?

-------
I'll leave that thread as "solved" because the OLD and NICE normal functions work properly.
Screw metamethods! Stay OldSchool! :D
 
Why do you do "Item(p:getSlotItem(3):getUniqueId())" it's the same as writing "p:getSlotItem(3)".
If you want to clone your backpack into your backpack you would do this.
Code:
local player = Player(cid)
local backpack = player:getSlotItem(CONST_SLOT_BACKPACK)
if backpack then
  player:addItemEx(backpack:clone())
end
 
Back
Top