Quasar Inventory

1) Copy/Paste this code in qs-inventory/server/custom/framework/esx.lua and save the file

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 ItemList[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()
						end
					end)
				end
				item.image = tostring(item.name..'.png')
				dump[i] = item
			end
		end
		if table.type(dump) ~= "empty" then
			local file = {string.strtrim(LoadResourceFile(resource, 'shared/items.lua'))}
			file[1] = file[1]:gsub('}$', '')

			local itemFormat = [[
				['%s'] = {
					name = '%s',
					label = '%s',
					weight = %s,
					type = 'item',
					image = '%s',
					unique = %s,
					useable = %s,
					shouldClose = %s,
					combinable = %s,
					description = %s
				},
			]]
			local fileSize = #file
			for _, item in pairs(dump) do
				local formatName = item.name:gsub("'", "\\'"):lower()
				if not ItemList[formatName] then
					fileSize += 1
					file[fileSize] = (itemFormat):format(formatName, item.name, item.label:gsub("'", "\\'"):lower(), item.weight, item.image, item.unique, item.useable, item.shouldClose, 'nil', item.description and ('"%s"'):format(item.description) or 'nil')
					ItemList[formatName] = item
				end
			end
			file[fileSize+1] = '}'
			SaveResourceFile(resource, 'shared/items.lua', table.concat(file), -1)
            ItemList = ItemList
		end
	end
end)

2) Open the config.lua from AV Restaurants and set Config.ESXInventory = 'qs-inventory' 3) Join my Discord if you need any help.

Last updated