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

How getName from item after container:getItems()

lord vortexx

New Member
Joined
Dec 14, 2008
Messages
92
Reaction score
3
Because when I execute this code:
for j, item in pairs(container:getItems()) do
print(item:getName())
end

getName return null all time?

Tank you
 
local container = player:getSlotItem(CONST_SLOT_xxxxxxx)
if container then
local item = container:getItem(4) // < 4 means the four slot into the container
print(item:getName())
 
But I need it to return all the names of all items in a container, getName () does not return anything in that context I passed, complete code:

for i, container in pairs(g_game.getContainers()) do
for j, item in pairs(container:getItems()) do
if item:getName() == name and item:isContainer() then
item.container = container
return item
end
end
end
 
Code:
function Container.getItems(self, ret)
    ret = ret or {}
    for index = self:getSize()-1, 0, -1 do
        local item = self:getItem(index)
        if ItemType(item:getId()):isContainer() then
            ret[#ret+1] = item
            item:getItems(ret)
        else
            ret[#ret+1] = item
        end
    end
    return ret
end
put this in container.lua in your lib

Code:
local items = container:getItems()
for i = 1, #items do
    print(items[i]:getName())
end
 
Code:
function Container.getItems(self, ret)
  ret = ret or {}
  for index = self:getSize()-1, 0, -1 do
    local item = self:getItem(index)
    if item:isContainer() == true then
      ret[#ret+1] = item
    else
      ret[#ret+1] = item
    end
  end
  return ret
end

function Container.GetByName(name)
  for _,container in pairs(g_game.getContainers()) do
    local items = container:getItems()
    for i = 1, #items do
      print( items[i]:getName() )
      if items[i]:getName() == name then
        return items[i]
      end
    end
  end
  return false
end

I'm trying this way, but on all the items that are passed in FOR returns null in the name ... I just get the ID, have any way to get the Name by the Item ID?
 
But I need it to return all the names of all items in a container, getName () does not return anything in that context I passed, complete code:

for i, container in pairs(g_game.getContainers()) do
for j, item in pairs(container:getItems()) do
if item:getName() == name and item:isContainer() then
item.container = container
return item
end
end
end

local container = player:getSlotItem(CONST_SLOT_xxxxxxx)
if container then
local item = container:getItem(1) // < 1 means the first slot into the container
local item2 = container:getItem(2) //
local item3 = container:getItem(3) //
print(item:getName())
print(item2:getName())
print(item3:getName())
 
local container = player:getSlotItem(CONST_SLOT_xxxxxxx)
if container then
local item = container:getItem(1) // < 1 means the first slot into the container
local item2 = container:getItem(2) //
local item3 = container:getItem(3) //
print(item:getName())
print(item2:getName())
print(item3:getName())


Code:
  for _,container in pairs(g_game.getContainers()) do
    print( container:getItem(1):getName() )
  end

I'm trying to get all the open containers in the player, so the loop, but it still does not return anything in getName()
 
This happens because the item name does not stay on the client
 
The item name is not in .dat file, it's impossible get it
 
Back
Top