AddEventHandler('inventory:refresh', function()
local success, items = pcall(MySQL.query.await, 'SELECT * FROM av_items')
if success and items and next(items) then
local dump = {}
local resource = GetCurrentResourceName()
local path = GetResourcePath(resource)
for i = 1, #items do
local item = items[i]
if not QBItems[item.name] then
item.shouldClose = true
item.unique = false
item.useable = true
item.description = item.description
item.weight = item.weight or 100
item.type = 'item'
if item.image then
PerformHttpRequest(item.image, function(errorCode, resultData, resultHeaders)
if errorCode >= 200 and errorCode < 300 then
local image = assert(io.open(path .. '/html/images/' .. item.name .. '.png', "wb"))
image:write(resultData)
image:flush()
image:close()
else
print("Image URL not found for item " .. item.label)
end
end)
end
item.image = tostring(item.name .. '.png')
QBItems[item.name] = item
end
end
end
end)