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

add an item to a container on the map

RigBy

Member
Joined
Jun 9, 2015
Messages
44
Solutions
1
Reaction score
6
Does anyone know how I can get the first container in a specific position and add an item inside it?
Can you give me an example?
TFs 1.3
 
Solution
What the guy shows in the previous comment is fine, but he can just do it like this:
Lua:
local position = Position(100, 100, 7)
local tile = Tile(position) -- or Tile(x, y, z)
if tile then
    local backpack = tile:getItemById(backpackId)
    if backpack then
        backpack:addItem(itemId, count)
    end
end
Lua:
local backpack = Game.createItem(backpackId, 1, position)
if backpack then
    backpack:addItem(itemId, count)
end
I can be talking nonsense, but that way he creates the bau!, I wanted a script that would take a container that already exists on the map and add the item inside it.
 
I don't know if it will work and also if it's the best way to do it.

Lua:
local position = XXXX -- Position where container is supposed to be
local tile = Tile(position)
local item
local itemId = XXXX -- Container
local id = XXXX -- Item added to container
if tile then
  if tile:getItemCountById(itemId) == 0 then
    print("Container not found")
  end
  if tile:getItemCountById(itemId) == 1 then
    item = tile:getItemById(itemId)
  end
  if item then
    item:addItem(id, 1)
  end
end
 
What the guy shows in the previous comment is fine, but he can just do it like this:
Lua:
local position = Position(100, 100, 7)
local tile = Tile(position) -- or Tile(x, y, z)
if tile then
    local backpack = tile:getItemById(backpackId)
    if backpack then
        backpack:addItem(itemId, count)
    end
end
 
Solution
What the guy shows in the previous comment is fine, but he can just do it like this:
Lua:
local position = Position(100, 100, 7)
local tile = Tile(position) -- or Tile(x, y, z)
if tile then
    local backpack = tile:getItemById(backpackId)
    if backpack then
        backpack:addItem(itemId, count)
    end
end

I was here adding, can you tell me why you're creating the item inside but you're not writing the text?

Lua:
    local position = Position(32103, 32194, 7)
    local tile = Tile(position) -- or Tile(x, y, z)
    if tile then
        local case = tile:getItemById(books[1].bookCaseId)
        if case then
            book = case:addItem(books[1].id, 1)
            doSetItemText(book, "hi")
        end
    end
Post automatically merged:

get, if someone has the same problem, it's like this:

Lua:
    local position = Position(32103, 32194, 7)
    local tile = Tile(position) -- or Tile(x, y, z)
    if tile then
        local case = tile:getItemById(books[1].bookCaseId)
        if case then
            book = case:addItem(1950, 1)
            book:setAttribute(ITEM_ATTRIBUTE_TEXT, books[1].texto)
        end
    end
 
Last edited:
Back
Top