OX Inventory

Go to ox_inventory/modules/items/server.lua and paste the following code just before the last line return Items

local consumeTypes = {
	['drink'] = 1,
	['food'] = 1,
	['alcohol'] = 1,
	['joint'] = 1,
}

AddEventHandler('inventory:refresh',function()
	local success, items = pcall(MySQL.query.await, 'SELECT * FROM av_items')
	if success and items and next(items) then
		local resource = GetCurrentResourceName()
		local path = GetResourcePath(resource)
		local dump = {}
		for i = 1, #items do
			local item = items[i]
			if not ItemList[item.name] then
				item.close = item.closeonuse == nil and true or item.closeonuse
				item.stack = item.stackable == nil and true or item.stackable
				item.description = item.description
				item.weight = item.weight or 1000
				item.consume = consumeTypes[item.type] or 1
				dump[i] = 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..'/web/images/'..item.name..'.png', "wb"))
							image:write(resultData)
							image:flush()
							image:close()
						end
					end)
				end
			end
		end
		if table.type(dump) ~= "empty" then
			local file = {string.strtrim(LoadResourceFile(shared.resource, 'data/items.lua'))}
			file[1] = file[1]:gsub('}$', '')
			local itemFormat = [[
	['%s'] = {
		label = '%s',
		weight = %s,
		consume = %s,
		stack = %s,
		close = %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.label:gsub("'", "\\'"), item.weight, item.consume, item.stack, item.close, item.description and ('"%s"'):format(item.description) or 'nil')
					ItemList[formatName] = item
				end
			end
			file[fileSize+1] = '}'
			SaveResourceFile(shared.resource, 'data/items.lua', table.concat(file), -1)
		end
	end
end)
  • Should look something like this:

Item Consumption

  • ox_inventory supports item durability and has the ability to remove a % from this durability every time the item is used, when durability reaches 0 it removes the item.

  • If you wanna take advantage from this feature while using av_business, you need to modify the consumeTypes table from the previous code and define a default consume value for every item type you have in av_business, example:

local consumeTypes = {
	['drink'] = 0.5, -- Removes 50% of durability per use
	['food'] = 0.5,  -- Removes 50% of durability per use
	['alcohol'] = 1,  -- Removes 100% of durability per use
	['joint'] = 0.25, -- Removes 25% of durability per use
}
  • Modify the values based on how much durability u wanna remove from item on use, 1 = 100% meaning item will be removed on first use / 0 will make the item permanent.

The following guide is only for people who have been using av_business before this consumption update (Oct 22nd), ignore it if you are just installing av_business for the first time.

Updating existing items

This little guide is to apply the consume field to your existing items created by av_business before this update.

  1. Make sure you remove the old code snippet from your ox_inventory/modules/items/server.lua and replace it with the one at the top of this page.

  2. Delete all the items created by av_business in your ox_inventory/data/items.lua. Please be careful, as deleting the wrong lines can break your ox_inventory.

  3. Restart your server, wait 1 minute and restart it again, use the script and items as usual.

Last updated