for i=1, #inventory.items, 1 do
local item = inventory.items[i]
if item.count > 0 then
table.insert(elements, {
label = item.label .. ' x' .. item.count, --- Line 580
type = 'item_standard',
value = item.name
})
end
end
This is what i have on my esx_property, i cant withdraw items.
I addition i would like to say that if i store meth on property for first time i cant withdraw it until a new server restart, is like i cant withdraw items unless i have stored them atleast 1 time.
I believe this might be a issue with “item.label” as removing that will resolve it for all cases where you have to use “esx_addoninventory” to withdraw items (eg. police armory, other jobs with specific stashes etc.) so that is your best bet. I have been looking for a fix but can’t find one other than just replacing “items.label” with “items.name” which will mean that you can at least open the menu, but it will not be shown with the label but instead the name will be shown. So if you have an item called “waterbottle” and the label is “Water Bottle” then it will show up in the menu as “waterbottle” which can be confusing but it’s just temporary till we can find out how to fix this.
the error is very simple, check your database in the addon_inventory_items table, there must be the label column, if not, you must create it and put their respective names.
Your code assumes, that your item object variable contains count, label and name.
for i=1, #inventory.items, 1 do
local item = inventory.items[i]
if item.count > 0 then -- we assume count prop exists
table.insert(elements, {
label = item.label .. ' x' .. item.count, -- we assume label prop exists
type = 'item_standard',
value = item.name -- we assume name prop exists
})
end
end
@scode correctly mentioned that there is a possibility, that your database lacks label column. The only problem is that this should be checked by the code anyways. We cannot rely on the data source (database in this scenario).
Also, I think it’s not a problem with the lack of the whole column, because it was probably created during the installation process of the script. I believe the problem lies with the item itself - when you added it, you forgot to add label to the database.
Solution
This solution is absolutely bulletproof, some may say an overkill. But when you are not aware of the importance of the database and the fields you have to fill out, this should work just fine for you.
Also it’s a bit optimized now, since the initialization of the variable item was put outside of the loop.
local item -- variable outside of the loop, so it's initialized only once
for i=1, #inventory.items, 1 do
if inventory.items[i] then -- checking if the item exists
item = inventory.items[i]
if item.count and item.label and item.name then
if item.count > 0 then
table.insert(elements, {
label = item.label .. ' x' .. item.count,
type = 'item_standard',
value = item.name
})
end
else
-- this else statement is optional
-- do something when the item lacks any of the properties
print('[esx_property] An item is missing some properties. Check the database!')
end
end
end
This really is confusing as I have item names and labels in the db for every item. This is happening for every menu based inventory script that i use. Changing item.label to item.name fixes the issue but no reason that label shouldnt work.