### Server Export: Search and Query Inventory (Lua) Source: https://context7.com/esx-framework/ox_inventory/llms.txt Provides examples of using server exports to search and query player inventory data. Functions include getting the entire inventory, item counts, searching for specific items, finding all slots with an item, getting items in a specific slot, checking equipped weapons, and verifying carry capacity. ```lua local Inventory = exports.ox_inventory -- Get player inventory object local playerInv = Inventory:Inventory(playerId) -- Get item count local burgerCount = Inventory:GetItemCount(playerId, 'burger') print('Player has ' .. burgerCount .. ' burgers') -- Search for item (returns first match) local item = Inventory:Search(playerInv, 'burger') if item then print('Found burger in slot ' .. item.slot .. ' with count ' .. item.count) end -- Get all slots containing an item local itemSlots = Inventory:GetItemSlots(playerId, 'ammo-9') for slot, item in pairs(itemSlots) do print('Slot ' .. slot .. ' has ' .. item.count .. ' 9mm ammo') end -- Get item in specific slot local slotItem = Inventory:GetSlot(playerInv, 5) if slotItem then print('Slot 5 contains ' .. slotItem.count .. 'x ' .. slotItem.name) end -- Get current equipped weapon local weapon = Inventory:GetCurrentWeapon(playerInv) if weapon then print('Player has ' .. weapon.name .. ' equipped with ' .. weapon.metadata.ammo .. ' rounds') end -- Check if player can carry weight if Inventory:CanCarryWeight(playerId, 5000) then print('Can carry additional 5kg') end -- Get empty slot local emptySlot = Inventory:GetEmptySlot(playerInv) if emptySlot then print('First empty slot is: ' .. emptySlot) end ``` -------------------------------- ### Server Export: Add Items to Inventory (Lua) Source: https://context7.com/esx-framework/ox_inventory/llms.txt Demonstrates how to add items to a player's inventory using the `AddItem` server export. Supports basic items, items with metadata, weapons with attachments, and adding to specific slots. Includes examples of checking carry capacity before adding. ```lua local Inventory = exports.ox_inventory -- Add 5 burgers to player inventory local success, response = Inventory:AddItem(playerId, 'burger', 5) -- Add item with metadata (unique properties) Inventory:AddItem(playerId, 'id_card', 1, { name = 'John Doe', dob = '1990-01-15', serial = 'ID' .. math.random(100000, 999999) }) -- Add weapon with attachments Inventory:AddItem(playerId, 'WEAPON_PISTOL', 1, { ammo = 50, durability = 100, serial = 'WSN' .. math.random(100000, 999999), components = {'COMPONENT_PISTOL_CLIP_02', 'COMPONENT_AT_PI_FLSH'} }) -- Add to specific slot with callback Inventory:AddItem(playerId, 'lockpick', 3, nil, 5, function(success, slot) if success then print('Added lockpick to slot ' .. slot) else print('Failed to add item: inventory full or too heavy') end end) -- Check if can carry before adding if Inventory:CanCarryItem(playerId, 'water_bottle', 10) then Inventory:AddItem(playerId, 'water_bottle', 10) TriggerClientEvent('chat:addMessage', playerId, { args = {'System', 'Received 10 water bottles'} }) else TriggerClientEvent('chat:addMessage', playerId, { args = {'System', 'Inventory full!'} }) end ``` -------------------------------- ### Configure ox_inventory Server Settings (Bash) Source: https://context7.com/esx-framework/ox_inventory/llms.txt Sets various server-side configuration options for ox_inventory via convars in server.cfg. This includes framework selection, inventory capacity, UI preferences, gameplay features, and job configurations. Dependencies include the server environment and the convars system. ```bash # Framework selection set inventory:framework "esx" # Options: esx, qbx, nd, ox # Inventory capacity set inventory:slots 50 set inventory:weight 30000 # Max weight in grams (30kg) # UI and interaction set inventory:target 0 # 0 = markers, 1 = ox_target set inventory:screenblur 1 set inventory:itemnotify 1 set inventory:weaponnotify 1 # Gameplay features set inventory:autoreload 0 set inventory:weaponanims 1 set inventory:aimedfiring 0 set inventory:giveplayerlist 0 # World interaction set inventory:dropprops 0 set inventory:suppresspickups 1 set inventory:randomloot 1 set inventory:networkdumpsters 0 # Job configuration set inventory:police '["police", "sheriff"]' set inventory:evidencegrade 2 # System settings set inventory:loglevel 1 set inventory:versioncheck true set inventory:bulkstashsave 1 set inventory:trimplate 1 # Hotkeys (JSON array) set inventory:keys '["F2", "K", "TAB"]' # Shop settings set inventory:randomprices 0 # Weapon settings set inventory:disableweapons 0 # Ensure required dependencies ensure oxmysql ensure ox_lib ensure ox_inventory ``` -------------------------------- ### Define Crafting Benches and Recipes (Lua) Source: https://context7.com/esx-framework/ox_inventory/llms.txt Configures crafting benches with their associated items, required ingredients, crafting duration, and output count. Also defines spawn points and blip information for these benches in the game world. Dependencies include the Lua environment. ```lua return { { name = 'debug_crafting', items = { { name = 'lockpick', ingredients = { scrapmetal = 5, -- Requires 5 scrap metal WEAPON_HAMMER = 0.05 -- Uses 5% hammer durability }, duration = 5000, -- Takes 5 seconds count = 2 -- Crafts 2 lockpicks }, { name = 'armor', ingredients = { fabric = 20, plastic = 10 }, duration = 15000, count = 1 } }, points = { vec3(-1147.083008, -2002.662109, 13.180260), vec3(-345.374969, -130.687088, 39.009613) }, zones = { { coords = vec3(-1146.2, -2002.05, 13.2), size = vec3(3.8, 1.05, 0.15), distance = 1.5, rotation = 315.0 } }, blip = { id = 566, colour = 31, scale = 0.8 } }, { name = 'cooking_station', items = { { name = 'burger', ingredients = { bread = 1, meat_raw = 1, lettuce = 1 }, duration = 10000, count = 1 }, { name = 'sandwich', ingredients = { bread = 2, cheese = 1 }, duration = 5000, count = 1 } }, points = { vec3(216.0, -800.0, 30.0) } } } ``` -------------------------------- ### Open Inventory UI with ox_inventory Client Exports (Lua) Source: https://context7.com/esx-framework/ox_inventory/llms.txt Provides client-side functions to open the inventory UI in various modes, including the player's own inventory, vehicle storage (trunk, glovebox), stashes, drops, and nearby inventories. Also includes functions to close the inventory. ```lua -- Open player's own inventory exports.ox_inventory:openInventory('player') -- Open vehicle trunk local vehicle = GetVehiclePedIsIn(PlayerPedId(), false) if vehicle ~= 0 then exports.ox_inventory:openInventory('trunk', { netid = NetworkGetNetworkIdFromEntity(vehicle), entityid = vehicle, door = 5 }) end -- Open vehicle glovebox exports.ox_inventory:openInventory('glovebox', { netid = NetworkGetNetworkIdFromEntity(vehicle), entityid = vehicle }) -- Open stash by name exports.ox_inventory:openInventory('stash', 'policelocker') -- Open player inventory with shop exports.ox_inventory:openInventory('player', { shop = 'General' }) -- Open drop (ground items) exports.ox_inventory:openInventory('drop', dropId) -- Close any open inventory exports.ox_inventory:closeInventory() -- Open nearby inventory (automatically finds closest accessible) exports.ox_inventory:openNearbyInventory() ``` -------------------------------- ### Configure Shops: Define Inventory and Locations (Lua) Source: https://context7.com/esx-framework/ox_inventory/llms.txt Defines shop configurations including names, blip details, inventory items with prices, and geographical locations. Supports multiple shop types like 'General', 'PoliceArmory', and 'BlackMarket'. ```lua return { General = { name = 'Shop', blip = { id = 59, colour = 69, scale = 0.8 }, inventory = { {name = 'burger', price = 10}, {name = 'water', price = 10}, {name = 'cola', price = 10}, {name = 'bandage', price = 50} }, locations = { vec3(25.7, -1347.3, 29.49), vec3(-3038.71, 585.9, 7.9), vec3(373.55, 325.56, 103.56) }, targets = { { loc = vec3(25.06, -1347.32, 29.5), length = 0.7, width = 0.5, heading = 0.0, minZ = 29.5, maxZ = 29.9, distance = 1.5 } } }, PoliceArmory = { name = 'Police Armory', groups = { ['police'] = 0, ['sheriff'] = 0 }, inventory = { {name = 'WEAPON_NIGHTSTICK', price = 100}, {name = 'WEAPON_PISTOL', price = 500, grade = 1}, {name = 'WEAPON_CARBINERIFLE', price = 2000, grade = 3}, {name = 'ammo-9', price = 5}, {name = 'bodycam', price = 150, license = 'weapon'} }, locations = { vec3(452.6, -980.0, 30.7) } }, BlackMarket = { name = 'Black Market', inventory = { {name = 'lockpick', price = 500, currency = 'black_money'}, {name = 'drill', price = 2000, currency = 'black_money'} }, locations = { vec3(-1150.0, -2000.0, 13.0) } } } ``` -------------------------------- ### Item Definition Structure in data/items.lua Source: https://context7.com/esx-framework/ox_inventory/llms.txt Defines the structure for creating items within the `data/items.lua` file. This includes setting basic properties like label, weight, and stackability, as well as detailed client-side effects such as status changes, animations, props, and custom exports. Server-side actions can also be defined. ```lua return { ['burger'] = { label = 'Burger', weight = 220, degrade = 60, -- Degrades over 60 minutes stack = true, close = true, description = 'A delicious burger', client = { image = 'burger_chicken.png', status = {hunger = 200000}, -- Restores hunger anim = 'eating', -- Uses eating animation preset prop = 'burger', -- Uses burger prop preset usetime = 2500, -- Takes 2.5 seconds to consume notification = 'You ate a delicious burger', export = 'myresource.useBurger' -- Custom callback }, consume = 0.3 -- Consumes 30% durability per use }, ['bandage'] = { label = 'Bandage', weight = 115, stack = true, close = true, client = { anim = { dict = 'missheistdockssetup1clipboard@idle_a', clip = 'idle_a', flag = 49 }, prop = { model = `prop_rolled_sock_02`, pos = vec3(-0.14, -0.14, -0.08), rot = vec3(-50.0, -50.0, 0.0) }, disable = { move = true, car = true, combat = true }, usetime = 2500 }, server = { export = 'hospital.useBandage' } }, ['water'] = { label = 'Water', weight = 500, stack = true, close = true, client = { status = {thirst = 200000}, anim = {dict = 'mp_player_intdrink', clip = 'loop_bottle'}, prop = { model = `prop_ld_flow_bottle`, pos = vec3(0.03, 0.03, 0.02), rot = vec3(0.0, 0.0, -1.5) }, usetime = 2500 } }, ['lockpick'] = { label = 'Lockpick', weight = 160, stack = true, close = false, description = 'Used to pick locks', client = { image = 'lockpick.png', export = 'lockpicking.startLockpick' } }, ['id_card'] = { label = 'ID Card', weight = 10, stack = false, -- Each ID is unique close = false, description = 'Government issued identification' }, ['backpack'] = { label = 'Backpack', weight = 2200, stack = false, consume = 0, client = { export = 'ox_inventory.openBackpack' } } } ``` -------------------------------- ### Client Item Usage Functions in ox_inventory Source: https://context7.com/esx-framework/ox_inventory/llms.txt Provides functions for interacting with items in the player's inventory on the client-side. These include using items by name or slot, checking weapon status, giving items to targets, opening the weapon wheel, setting stash targets, searching the inventory, retrieving all items, checking player weight, and finding slots containing specific items. ```lua -- Use item by name exports.ox_inventory:useItem('burger') -- Use item in specific slot exports.ox_inventory:useSlot(5) -- Get current weapon local weapon = exports.ox_inventory:getCurrentWeapon() if weapon then print('Current weapon: ' .. weapon.name .. ' with ' .. weapon.metadata.ammo .. ' ammo') end -- Give item to nearby player exports.ox_inventory:giveItemToTarget(5) -- Give 5 of current item -- Display weapon wheel exports.ox_inventory:weaponWheel() -- Set stash target for ox_target exports.ox_inventory:setStashTarget('mystash', 'player:12345') -- Search client inventory local items = exports.ox_inventory:Search('count', 'burger') print('You have ' .. (items or 0) .. ' burgers') -- Get all player items local allItems = exports.ox_inventory:GetPlayerItems() for slot, item in pairs(allItems) do print('Slot ' .. slot .. ': ' .. item.count .. 'x ' .. item.name) end -- Get player weight local weight = exports.ox_inventory:GetPlayerWeight() local maxWeight = exports.ox_inventory:GetPlayerMaxWeight() print('Carrying ' .. weight .. 'g / ' .. maxWeight .. 'g') -- Get item count local lockpickCount = exports.ox_inventory:GetItemCount('lockpick') -- Get slots with item local waterSlots = exports.ox_inventory:GetSlotsWithItem('water') ``` -------------------------------- ### Register Custom Shops with ox_inventory (Lua) Source: https://context7.com/esx-framework/ox_inventory/llms.txt Registers custom shops with specified inventory items, locations, and access restrictions. Supports basic items, group/rank restrictions, and multiple currency types. ```lua local Inventory = exports.ox_inventory -- Register basic shop Inventory:RegisterShop('MyCustomShop', { name = 'Custom Store', inventory = { {name = 'burger', price = 15}, {name = 'water', price = 10}, {name = 'bandage', price = 50} }, locations = { vector3(100.0, 200.0, 30.0), vector3(500.0, 600.0, 25.0) }, blip = { id = 52, colour = 2, scale = 0.8 } }) -- Register police-only shop with rank restrictions Inventory:RegisterShop('PoliceArmory', { name = 'Police Armory', groups = { ['police'] = 0, ['sheriff'] = 2 -- Sheriff rank 2+ only }, inventory = { {name = 'WEAPON_NIGHTSTICK', price = 100, grade = 0}, {name = 'WEAPON_PISTOL', price = 500, grade = 1}, {name = 'WEAPON_CARBINERIFLE', price = 2000, grade = 3}, {name = 'ammo-9', price = 5}, {name = 'bodycam', price = 150, license = 'weapon'} }, locations = { vector3(452.6, -980.0, 30.7) } }) -- Shop with multiple currencies Inventory:RegisterShop('BlackMarket', { name = 'Black Market', inventory = { {name = 'lockpick', price = 500, currency = 'black_money'}, {name = 'drill', price = 2000, currency = 'black_money'}, {name = 'weapon_pistol', price = 50, currency = 'poker_chips'} }, locations = { vector3(-1500.0, 200.0, 50.0) } }) ``` -------------------------------- ### Server Export: Search and Query Inventory Source: https://context7.com/esx-framework/ox_inventory/llms.txt Provides functions to inspect inventory contents, check item counts, search for specific items, retrieve slot information, check carrying capacity, and find empty slots. ```APIDOC ## Server Export: Search and Query Inventory ### Description Searches for items in inventory and retrieves detailed item information, counts, and slot data. ### Method `exports.ox_inventory:Inventory(target)` `exports.ox_inventory:GetItemCount(target, item_name)` `exports.ox_inventory:Search(inventory_table, item_name)` `exports.ox_inventory:GetItemSlots(target, item_name)` `exports.ox_inventory:GetSlotIdsWithItem(target, item_name)` `exports.ox_inventory:GetSlot(inventory_table_or_target, slot_id)` `exports.ox_inventory:GetCurrentWeapon(inventory_table)` `exports.ox_inventory:CanCarryWeight(target, weight)` `exports.ox_inventory:GetEmptySlot(inventory_table)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **target** (playerId | containerId) - Required for functions that operate on a specific inventory. - **item_name** (string) - Required for count and search functions. - **inventory_table** (table) - Required for functions that operate on an inventory table directly (e.g., returned by `Inventory()`). - **slot_id** (number) - Required for `GetSlot()`. - **weight** (number) - Required for `CanCarryWeight()`. ### Request Example ```lua local Inventory = exports.ox_inventory -- Get player inventory object local playerInv = Inventory:Inventory(playerId) -- Get item count local burgerCount = Inventory:GetItemCount(playerId, 'burger') print('Player has ' .. burgerCount .. ' burgers') -- Search for item (returns first match) local item = Inventory:Search(playerInv, 'burger') if item then print('Found burger in slot ' .. item.slot .. ' with count ' .. item.count) end -- Get all slots containing an item local itemSlots = Inventory:GetItemSlots(playerId, 'ammo-9') for slot, item in pairs(itemSlots) do print('Slot ' .. slot .. ' has ' .. item.count .. ' 9mm ammo') end -- Get item in specific slot local slotItem = Inventory:GetSlot(playerInv, 5) if slotItem then print('Slot 5 contains ' .. slotItem.count .. 'x ' .. slotItem.name) end -- Get current equipped weapon local weapon = Inventory:GetCurrentWeapon(playerInv) if weapon then print('Player has ' .. weapon.name .. ' equipped with ' .. weapon.metadata.ammo .. ' rounds') end -- Check if player can carry weight if Inventory:CanCarryWeight(playerId, 5000) then print('Can carry additional 5kg') end -- Get empty slot local emptySlot = Inventory:GetEmptySlot(playerInv) if emptySlot then print('First empty slot is: ' .. emptySlot) end ``` ### Response #### Success Response (200) - **Inventory()**: Returns the player's inventory table. - **GetItemCount()**: Returns the count (number) of the specified item. - **Search()**: Returns the first item table found, or `nil`. - **GetItemSlots()**: Returns a table of item tables for all slots containing the item. - **GetSlotIdsWithItem()**: Returns a list of slot IDs (numbers) containing the item. - **GetSlot()**: Returns the item table for the specified slot, or `nil`. - **GetCurrentWeapon()**: Returns the equipped weapon's item table, or `nil`. - **CanCarryWeight()**: Returns a boolean indicating if the target can carry the specified weight. - **GetEmptySlot()**: Returns the ID (number) of the first empty slot, or `nil`. #### Response Example ```lua -- Example output from GetItemCount: -- Player has 10 burgers -- Example output from Search: -- Found burger in slot 3 with count 5 -- Example output from GetSlot: -- Slot 5 contains 1x lockpick -- Example output from CanCarryWeight: -- Can carry additional 5kg ``` ``` -------------------------------- ### Perform Inventory Management Operations Source: https://context7.com/esx-framework/ox_inventory/llms.txt Programmatically create, remove, clear, and manage inventories. This includes retrieving inventory details, clearing entire inventories or specific items, confiscating and returning player inventories, removing inventories from the system, updating vehicle plates associated with inventories, and creating item drops. Dependencies: ox_inventory. ```lua local Inventory = exports.ox_inventory -- Get inventory by ID local stashInv = Inventory:GetInventory('stash_police_evidence') if stashInv then print('Stash weight: ' .. stashInv.weight .. '/' .. stashInv.maxWeight) end -- Clear entire inventory Inventory:ClearInventory(playerId) -- Clear inventory but keep specific items Inventory:ClearInventory(playerId, { keep = {'id_card', 'phone', 'radio'} }) -- Confiscate player inventory (stores for later return) Inventory:ConfiscateInventory(playerId) -- Return confiscated inventory Inventory:ReturnInventory(playerId) -- Remove inventory from system Inventory:RemoveInventory('stash_temp_123') -- Update vehicle plate (when vehicle plate changes) Inventory:UpdateVehicle('ABC 123', 'XYZ 789') -- Create drop from player inventory local dropId = Inventory:CreateDropFromPlayer(playerId) print('Created drop with ID: ' .. dropId) -- Create custom drop at coordinates Inventory:CustomDrop('loot', { {name = 'burger', count = 3}, {name = 'water', count = 2}, {name = 'money', count = 500} }, vector3(100.0, 200.0, 30.0), 10, 5000, nil, 'prop_paper_bag_small') ``` -------------------------------- ### Configure Stashes: Define Locations and Access Control (Lua) Source: https://context7.com/esx-framework/ox_inventory/llms.txt Defines permanent stash configurations, including coordinates, interaction targets, ownership settings (per-player or shared), slots, weight, and group access permissions. Used for personal lockers and gang storage. ```lua return { { coords = vec3(452.3, -991.4, 30.7), target = { loc = vec3(451.25, -994.28, 30.69), length = 1.2, width = 5.6, heading = 0, minZ = 29.49, maxZ = 32.09, label = 'Open personal locker' }, name = 'policelocker', label = 'Personal Locker', owner = true, -- Creates per-player instance slots = 70, weight = 70000, groups = {['police'] = 0, ['sheriff'] = 0} }, { coords = vec3(301.3, -600.23, 43.28), target = { loc = vec3(301.82, -600.99, 43.29), length = 0.6, width = 1.8, heading = 340, minZ = 43.34, maxZ = 44.74, label = 'Open personal locker' }, name = 'emslocker', label = 'EMS Locker', owner = true, slots = 70, weight = 70000, groups = {['ambulance'] = 0} }, { coords = vec3(100.0, 200.0, 30.0), name = 'gang_stash', label = 'Gang Storage', owner = false, -- Shared stash slots = 150, weight = 500000, groups = {['gang1'] = 0, ['gang2'] = 0} } } ``` -------------------------------- ### Manage Item Metadata and Slots Source: https://context7.com/esx-framework/ox_inventory/llms.txt Dynamically modify item properties, metadata, and slot configurations. This includes setting custom metadata, updating durability, directly setting item counts, and swapping items between slots or inventories. It also covers changing inventory capacity and checking swap feasibility. Dependencies: ox_inventory. ```lua local Inventory = exports.ox_inventory -- Set custom metadata on item in slot Inventory:SetMetadata(playerId, 3, { quality = 85, craftedBy = 'John Doe', craftedAt = os.time(), customData = 'Special Edition' }) -- Update weapon durability Inventory:SetDurability(playerId, 1, 75) -- Get slot and modify metadata local item = Inventory:GetSlot(playerId, 2) if item and item.name == 'radio' then item.metadata.frequency = 101.5 Inventory:SetMetadata(playerId, 2, item.metadata) end -- Set item count in slot directly Inventory:SetItem(playerId, 'money', 5000) -- Swap items between slots Inventory:SwapSlots(playerId, playerId, 1, 5) -- Swap between different inventories Inventory:SwapSlots(playerId, 'stash_police', 3, 2) -- Change inventory capacity Inventory:SetSlotCount(playerId, 60) -- Increase to 60 slots Inventory:SetMaxWeight(playerId, 50000) -- Increase max weight to 50kg -- Check if swap is possible if Inventory:CanSwapItem(playerId, 'water', 10, 'burger', 5) then print('Can swap items without exceeding capacity') end ``` -------------------------------- ### Server Export: Add Items to Inventory Source: https://context7.com/esx-framework/ox_inventory/llms.txt This function allows you to add items to a player's inventory or a specified container. You can specify the quantity, metadata for unique item properties, target slot, and a callback function to execute upon completion. It also includes a check for carrying capacity before adding. ```APIDOC ## Server Export: Add Items to Inventory ### Description Adds items to a player or container inventory with optional metadata and specific slot targeting. ### Method `exports.ox_inventory:AddItem(target, item_name, count, metadata, slot, callback)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **target** (playerId | containerId) - Required - The identifier of the player or container to add items to. - **item_name** (string) - Required - The internal name of the item to add. - **count** (number) - Optional (defaults to 1) - The number of items to add. - **metadata** (table) - Optional - A table containing custom metadata for the item (e.g., serial numbers, durability, components for weapons). - **slot** (number) - Optional - The specific inventory slot to place the item in. If `nil`, the system will find the first available slot. - **callback** (function) - Optional - A function to be called after the item is added. It receives `success` (boolean) and `slot` (number) as arguments. ### Request Example ```lua local Inventory = exports.ox_inventory -- Add 5 burgers to player inventory Inventory:AddItem(playerId, 'burger', 5) -- Add item with metadata Inventory:AddItem(playerId, 'id_card', 1, { name = 'John Doe', dob = '1990-01-15', serial = 'ID' .. math.random(100000, 999999) }) -- Add weapon with attachments to a specific slot with callback Inventory:AddItem(playerId, 'WEAPON_PISTOL', 1, { ammo = 50, durability = 100, serial = 'WSN' .. math.random(100000, 999999), components = {'COMPONENT_PISTOL_CLIP_02', 'COMPONENT_AT_PI_FLSH'} }, 5, function(success, slot) if success then print('Added weapon to slot ' .. slot) else print('Failed to add weapon') end end) -- Check if can carry before adding if Inventory:CanCarryItem(playerId, 'water_bottle', 10) then Inventory:AddItem(playerId, 'water_bottle', 10) else TriggerClientEvent('chat:addMessage', playerId, { args = {'System', 'Inventory full!'} }) end ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the item was successfully added. - **response** (string | number | table) - Varies depending on the operation. For `AddItem`, if a callback is provided, this might be the return value of the callback or `nil`. If no callback, it might indicate the slot number or a success message. #### Response Example (This is typically handled by the callback function or client-side events) ```lua -- Example within a callback: function(success, slot) if success then print('Item added to slot: ' .. slot) else print('Failed to add item.') end end ``` ``` -------------------------------- ### Register Stashes with Restrictions Source: https://context7.com/esx-framework/ox_inventory/llms.txt Register permanent or temporary stashes with configurable properties such as label, slots, weight limits, group restrictions, and ownership. This allows for structured storage solutions like armories or personal lockers. Dependencies: ox_inventory. ```lua local Inventory = exports.ox_inventory -- Register simple stash Inventory:RegisterStash('mystash', 'My Storage', 50, 100000) -- Register group-restricted stash Inventory:RegisterStash('police_armory', 'Police Armory', 100, 200000, false, { ['police'] = 0, ['sheriff'] = 0 }) -- Register personal stash (per-player instances) Inventory:RegisterStash('personallocker', 'Personal Locker', 70, 70000, true) -- Register stash with coordinates Inventory:RegisterStash('gunshop_storage', 'Gun Shop Storage', 50, 150000, false, { ['gunshop'] = 0 }, vector3(842.3, -1035.2, 28.2)) -- Create temporary stash (not saved to database) local tempStash = Inventory:CreateTemporaryStash({ label = 'Temporary Container', slots = 20, maxWeight = 25000, items = { {name = 'burger', count = 5}, {name = 'water', count = 3} } }) print('Temp stash ID: ' .. tempStash.id) ``` -------------------------------- ### Server Export: Remove Items from Inventory (Lua) Source: https://context7.com/esx-framework/ox_inventory/llms.txt Illustrates how to remove items from a player's inventory using the `RemoveItem` server export. Supports removing by item name, with specific metadata, from a particular slot, and strict removal requiring exact metadata matches. Also shows how to decrease item durability. ```lua local Inventory = exports.ox_inventory -- Remove 2 burgers from player local success, response = Inventory:RemoveItem(playerId, 'burger', 2) -- Remove item with specific metadata Inventory:RemoveItem(playerId, 'id_card', 1, { serial = 'ID123456' }) -- Remove from specific slot Inventory:RemoveItem(playerId, 'lockpick', 1, nil, 3) -- Strict removal (exact metadata match required) local removed = Inventory:RemoveItem(playerId, 'weapon_pistol', 1, { serial = 'WSN745821' }, nil, nil, true) if removed then print('Weapon confiscated successfully') else print('Weapon with matching serial not found') end -- Remove durability from item local item = Inventory:GetSlot(playerId, 1) if item and item.metadata.durability then Inventory:SetDurability(playerId, 1, item.metadata.durability - 10) end ``` -------------------------------- ### Register Server Hooks for Inventory Operations (Lua) Source: https://context7.com/esx-framework/ox_inventory/llms.txt Registers server-side hooks to intercept and modify inventory operations like item removal, addition, creation, purchases, swaps, and crafting. Hooks can return false to cancel an operation or modify payload data. ```lua local Inventory = exports.ox_inventory -- Prevent specific item removal Inventory:registerHook('removeItem', function(payload) if payload.item.name == 'evidence_locker_key' then return false -- Prevent removal end return true end) -- Log all item additions Inventory:registerHook('addItem', function(payload) print(string.format( 'Added %dx %s to %s (slot %d)', payload.count, payload.item.name, payload.inventoryId, payload.slot )) return true end) -- Modify metadata on item creation Inventory:registerHook('createItem', function(payload) payload.metadata.created = os.time() payload.metadata.creator = payload.inventoryId return payload.metadata end) -- Track shop purchases Inventory:registerHook('buyItem', function(payload) local player = payload.inventoryId local item = payload.item.name local count = payload.count local totalCost = payload.price * count print(string.format('Player %d bought %dx %s for $%d', player, count, item, totalCost)) -- Could log to database here MySQL.insert('INSERT INTO purchase_logs (player, item, count, price) VALUES (?, ?, ?, ?)', { player, item, count, totalCost }) return true end, { print = false -- Disable debug output }) -- Filter hook by specific item Inventory:registerHook('swapItems', function(payload) print('Swapped ' .. payload.fromSlot.name .. ' with ' .. payload.toSlot.name) return true end, { itemFilter = {'weapon_pistol', 'weapon_knife'} }) -- Hook for crafting with performance tracking Inventory:registerHook('craftItem', function(payload) TriggerClientEvent('chat:addMessage', payload.inventoryId, { args = {'Crafting', 'Successfully crafted ' .. payload.item.label} }) return true end, { print = true -- Enable performance tracking }) ``` -------------------------------- ### Server Export: Remove Items from Inventory Source: https://context7.com/esx-framework/ox_inventory/llms.txt This function allows for the removal of items from inventories. It supports removing by item name and count, with options to match specific metadata or remove from a particular slot. A strict removal option ensures metadata exactness. ```APIDOC ## Server Export: Remove Items from Inventory ### Description Removes items from inventory with support for metadata matching and strict counting. ### Method `exports.ox_inventory:RemoveItem(target, item_name, count, metadata, slot, callback, skip_weight, strict_metadata)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **target** (playerId | containerId) - Required - The identifier of the player or container to remove items from. - **item_name** (string) - Required - The internal name of the item to remove. - **count** (number) - Optional (defaults to 1) - The number of items to remove. - **metadata** (table) - Optional - A table containing metadata to match for removal. If provided, only items with matching metadata will be removed. - **slot** (number) - Optional - The specific inventory slot to remove the item from. If `nil`, the system will find the first available item matching the criteria. - **callback** (function) - Optional - A function to be called after the item is removed. It receives `success` (boolean) and `response` (details about removal) as arguments. - **skip_weight** (boolean) - Optional (defaults to false) - If true, weight is not considered during removal. - **strict_metadata** (boolean) - Optional (defaults to false) - If true, requires an exact match of all provided metadata fields. ### Request Example ```lua local Inventory = exports.ox_inventory -- Remove 2 burgers from player local success, response = Inventory:RemoveItem(playerId, 'burger', 2) -- Remove item with specific metadata Inventory:RemoveItem(playerId, 'id_card', 1, { serial = 'ID123456' }) -- Remove from specific slot Inventory:RemoveItem(playerId, 'lockpick', 1, nil, 3) -- Strict removal (exact metadata match required) local removed = Inventory:RemoveItem(playerId, 'weapon_pistol', 1, { serial = 'WSN745821' }, nil, nil, true) if removed then print('Weapon confiscated successfully') else print('Weapon with matching serial not found') end -- Example of setting durability (related to item state) local item = Inventory:GetSlot(playerId, 1) if item and item.metadata.durability then Inventory:SetDurability(playerId, 1, item.metadata.durability - 10) end ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the item was successfully removed. - **response** (any) - Varies depending on the operation. Can be a boolean indicating strict removal success, or details from the callback. #### Response Example ```lua -- Example callback result for strict removal: if removed then print('Weapon confiscated successfully') else print('Weapon with matching serial not found') end ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.