Tgiann Inventory

  • Go to tgiann-inventory/bridge/ and create a new file av_business.lua

  • Edit the file and paste the following code inside:

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('inventory_images')
		for i = 1, #items do
			local item = items[i]
			if not itemsData[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, _)
						if errorCode >= 200 and errorCode < 300 then
							local image = assert(io.open(path..'/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, 'items/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,
        description = %s
    },
]]
			local fileSize = #file
			for _, item in pairs(dump) do
				local formatName = item.name:gsub("'", "\\'"):lower()
				if not itemsData[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, item.description and ('"%s"'):format(item.description) or 'nil')
					itemsData[formatName] = item
				end
			end
			file[fileSize+1] = '}'
			SaveResourceFile(resource, 'items/items.lua', table.concat(file), -1)
            itemsData = itemsData
		end
	end
end)

Last updated