From 4dbd9dd4abe3cb2b301aea2cdc747aabda2990c0 Mon Sep 17 00:00:00 2001 From: Luke Date: Thu, 17 Nov 2022 11:59:10 +0100 Subject: [PATCH] update inventory server docs --- .../Functions/Server/Inventory/AddItem.md | 3 +- .../Server/Inventory/CanCarryAmount.md | 5 ++-- .../Server/Inventory/CanCarryItem.md | 12 ++++---- .../Functions/Server/Inventory/CanSwapItem.md | 12 ++++---- .../Server/Inventory/ClearInventory.md | 4 +-- .../Server/Inventory/ConfiscateInventory.md | 2 +- .../Server/Inventory/ConvertItems.md | 6 ++-- .../Functions/Server/Inventory/CustomDrop.md | 18 +++++------ .../Server/Inventory/GetCurrentWeapon.md | 1 + .../{Inventory.md => GetInventory.md} | 14 +++++---- .../Server/Inventory/GetInventoryItems.md | 12 ++++++++ .../Functions/Server/Inventory/GetItem.md | 11 +++---- .../Server/Inventory/GetItemSlots.md | 8 ++--- .../Functions/Server/Inventory/GetSlot.md | 7 +++-- .../Server/Inventory/RegisterStash.md | 30 +++++++++---------- .../Server/Inventory/ReturnInventory.md | 4 +-- .../Functions/Server/Inventory/Search.md | 11 +++---- .../Server/Inventory/SetDurability.md | 8 ++--- .../Functions/Server/Inventory/SetMetadata.md | 6 ++-- .../Functions/Server/Inventory/SwapSlots.md | 10 +++---- .../Functions/Server/setPlayerInventory.md | 19 ++++++------ 21 files changed, 112 insertions(+), 91 deletions(-) rename docs/ox_inventory/Functions/Server/Inventory/{Inventory.md => GetInventory.md} (59%) create mode 100644 docs/ox_inventory/Functions/Server/Inventory/GetInventoryItems.md diff --git a/docs/ox_inventory/Functions/Server/Inventory/AddItem.md b/docs/ox_inventory/Functions/Server/Inventory/AddItem.md index f7e1d199..a4011b9a 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/AddItem.md +++ b/docs/ox_inventory/Functions/Server/Inventory/AddItem.md @@ -5,7 +5,6 @@ Should be used alongside [CanCarryItem](./CanCarryItem.md) otherwise, the maximu ```lua exports.ox_inventory:AddItem(inv, item, count, metadata, slot, cb) ``` - - inv: `table` or `string` or `number` - The inventory's unique id, or a table with the id and owner. - playerId: `1` @@ -21,6 +20,8 @@ exports.ox_inventory:AddItem(inv, item, count, metadata, slot, cb) - A specific slot to add the item to. If the slot is invalid, the first available slot will be used instead. - cb?: function(success: `boolean`, response?: `string`) +If used for glovebox, trunk or stash you must first check the inventory is loaded with [GetInventory](./GetInventory.md) + Returns `success, response` if cb is undefined, otherwise they are used in the callback only. **Example:** diff --git a/docs/ox_inventory/Functions/Server/Inventory/CanCarryAmount.md b/docs/ox_inventory/Functions/Server/Inventory/CanCarryAmount.md index 42a0ce03..68a24664 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/CanCarryAmount.md +++ b/docs/ox_inventory/Functions/Server/Inventory/CanCarryAmount.md @@ -1,10 +1,11 @@ Returns the amount a player can hold based on available weight. ```lua ----@param inv string | number ----@param item table | string exports.ox_inventory:CanCarryAmount(inv, item) ``` +* inv: `string` or `number` +* item: `table` or `string` + * Can be array to check multiple items. Example: diff --git a/docs/ox_inventory/Functions/Server/Inventory/CanCarryItem.md b/docs/ox_inventory/Functions/Server/Inventory/CanCarryItem.md index 17fb761a..e1a5c88f 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/CanCarryItem.md +++ b/docs/ox_inventory/Functions/Server/Inventory/CanCarryItem.md @@ -3,12 +3,14 @@ Returns true or false depending if the inventory can carry the specified item. The function checks for inventory weight and available slots. ```lua --- inv: string or number --- item: table or string --- count: number --- metadata: table or string (optional) exports.ox_inventory:CanCarryItem(inv, item, count, metadata) ``` +* inv: `string` or `number` +* item `table` or `string` + * Can be array of items. +* count: `number` +* metadata?: `table` or `string` + * If metadata is passed as string then `metadata.type` will be checked. **Example:** ```lua @@ -18,4 +20,4 @@ if exports.ox_inventory:CanCarryItem(source, 'water', 3) then else -- Do stuff if can't carry end -``` \ No newline at end of file +``` diff --git a/docs/ox_inventory/Functions/Server/Inventory/CanSwapItem.md b/docs/ox_inventory/Functions/Server/Inventory/CanSwapItem.md index 59b9f775..b7e9c4ca 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/CanSwapItem.md +++ b/docs/ox_inventory/Functions/Server/Inventory/CanSwapItem.md @@ -1,10 +1,10 @@ Returns true if the item swap is possible based on inventory weight. ```lua --- inv: string or number --- firstItem: string --- firstItemCount: number --- testItem: string --- testItemCount: number exports.ox_inventory:CanSwapItem(inv, firstItem, firstItemCount, testItem, testItemCount) -``` \ No newline at end of file +``` +* inv: `string` or `number` +* firstItem: `string` +* firstItemCount: `number` +* testItem: `string` +* testItemCount: `number` diff --git a/docs/ox_inventory/Functions/Server/Inventory/ClearInventory.md b/docs/ox_inventory/Functions/Server/Inventory/ClearInventory.md index 78c1ac81..a60fa455 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/ClearInventory.md +++ b/docs/ox_inventory/Functions/Server/Inventory/ClearInventory.md @@ -1,7 +1,7 @@ Clears the specified inventory. The `keep` argument is either a string or an array of strings containing the name(s) of the item(s) to keep in the inventory after clearing. ```lua --- inv: string or number --- keep:? string or string[] exports.ox_inventory:ClearInventory(inv, keep) ``` +* inv: `string` or `number` +* keep?: `string` or `string[]` diff --git a/docs/ox_inventory/Functions/Server/Inventory/ConfiscateInventory.md b/docs/ox_inventory/Functions/Server/Inventory/ConfiscateInventory.md index 45f76aa3..f5fafa5f 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/ConfiscateInventory.md +++ b/docs/ox_inventory/Functions/Server/Inventory/ConfiscateInventory.md @@ -4,6 +4,6 @@ Use [ReturnInventory](./ReturnInventory.md) to return the confiscated inventory the player. ```lua --- source: number exports.ox_inventory:ConfiscateInventory(source) ``` +* source: `number` diff --git a/docs/ox_inventory/Functions/Server/Inventory/ConvertItems.md b/docs/ox_inventory/Functions/Server/Inventory/ConvertItems.md index efbfede6..fe5ce65f 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/ConvertItems.md +++ b/docs/ox_inventory/Functions/Server/Inventory/ConvertItems.md @@ -1,13 +1,13 @@ Takes traditional item data and updates it to support ox_inventory. ```lua --- playerId: number --- items: table exports.ox_inventory:ConvertItems(playerId, items) ``` +* playerId: `number` +* items: `table` Data conversion example: ``` Old: [{"cola":1, "bread":3}] New: [{"slot":1,"name":"cola","count":1}, {"slot":2,"name":"bread","count":3}] -``` \ No newline at end of file +``` diff --git a/docs/ox_inventory/Functions/Server/Inventory/CustomDrop.md b/docs/ox_inventory/Functions/Server/Inventory/CustomDrop.md index d6f0e4fb..f95e3474 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/CustomDrop.md +++ b/docs/ox_inventory/Functions/Server/Inventory/CustomDrop.md @@ -1,17 +1,17 @@ Drops can be created from other resources, containing a variety of items and utilising a custom label (instead of 'Drop 32648'). ```lua --- prefix: string --- items: table - -- name: string - -- count: number - -- metadata: table (optional) --- coords: vector3 --- slots: number (optional) --- maxWeight: number (optional) --- instance: string | number (optional) exports.ox_inventory:CustomDrop(prefix, items, coords, slots, maxWeight, instance) ``` +* prefix: `string` +* items: `table` + * name: `string` + * count: `number` + * metadata?: `table` +* coords: `vector3` +* slots?: `number` +* maxWeight?: `number` +* instance?: `string` or `number` ```lua exports.ox_inventory:CustomDrop('Carcass', { diff --git a/docs/ox_inventory/Functions/Server/Inventory/GetCurrentWeapon.md b/docs/ox_inventory/Functions/Server/Inventory/GetCurrentWeapon.md index 54fc5630..a8fdcc87 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/GetCurrentWeapon.md +++ b/docs/ox_inventory/Functions/Server/Inventory/GetCurrentWeapon.md @@ -4,3 +4,4 @@ Returns the player's currently equipped weapon as a table. -- inv: string or number exports.ox_inventory:GetCurrentWeapon(inv) ``` +* inv: `string` or `number` diff --git a/docs/ox_inventory/Functions/Server/Inventory/Inventory.md b/docs/ox_inventory/Functions/Server/Inventory/GetInventory.md similarity index 59% rename from docs/ox_inventory/Functions/Server/Inventory/Inventory.md rename to docs/ox_inventory/Functions/Server/Inventory/GetInventory.md index 2b849f09..88aac9fe 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/Inventory.md +++ b/docs/ox_inventory/Functions/Server/Inventory/GetInventory.md @@ -1,12 +1,14 @@ -Returns the inventory associated with the ID (and owner if defined). Otherwise returns null +Returns the inventory associated with the ID (and owner if defined). Otherwise returns null. + ```lua ----@param id number | table ----@param owner string | boolean (optional) -exports.ox_inventory:Inventory(id, owner) +exports.ox_inventory:GetInventory(inv, owner) ``` -Example: +* inv: `number` or `table` +* owner?: `string` or `boolean` + +**Example:** ```lua -local inventory = exports.ox_inventory:Inventory('example_stash', false) +local inventory = exports.ox_inventory:GetInventory('example_stash', false) print(json.encode(inventory, {indent = true})) --[[ { diff --git a/docs/ox_inventory/Functions/Server/Inventory/GetInventoryItems.md b/docs/ox_inventory/Functions/Server/Inventory/GetInventoryItems.md new file mode 100644 index 00000000..a0a96d84 --- /dev/null +++ b/docs/ox_inventory/Functions/Server/Inventory/GetInventoryItems.md @@ -0,0 +1,12 @@ +Returns all slots with items in a inventory. + +```lua +exports.ox_inventory:GetInventoryItems(inv, owner) +``` +* inv: `number` or `table` +* owner?: `string` or `boolean` + +**Example:** +```lua +local playerItems = exports.ox_inventory:GetInventoryItems(source) +``` diff --git a/docs/ox_inventory/Functions/Server/Inventory/GetItem.md b/docs/ox_inventory/Functions/Server/Inventory/GetItem.md index b19b67e0..23e1aefe 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/GetItem.md +++ b/docs/ox_inventory/Functions/Server/Inventory/GetItem.md @@ -1,12 +1,13 @@ Returns the item from the specified inventory. ```lua --- inv: string or number --- item: table or string --- metadata: any (optional) --- returnsCount: boolean (optional) exports.ox_inventory:GetItem(inv, item, metadata, returnsCount) ``` +* inv: `string` or `number` +* item: `table` or `string` + * Can be items array. +* metadata?: `any` +* returnsCount?: `boolean` If `returnsCount` is set to true, the returned value will be the `count` based on how many times the item was found. @@ -29,4 +30,4 @@ print(json.encode(item, {indent=true})) "close": true } ]] -``` \ No newline at end of file +``` diff --git a/docs/ox_inventory/Functions/Server/Inventory/GetItemSlots.md b/docs/ox_inventory/Functions/Server/Inventory/GetItemSlots.md index 507c6405..3f88d4ea 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/GetItemSlots.md +++ b/docs/ox_inventory/Functions/Server/Inventory/GetItemSlots.md @@ -1,8 +1,8 @@ Returns the number of slots the specified item is in, the item's total count and the remaining empty slots. ```lua --- inv: string or number --- item: table or string --- metadata: table (optional) exports.ox_inventory:GetItemSlots(inv, item, metadata) -``` \ No newline at end of file +``` +* inv: `string` or `number` +* item: `table` or `string` +* metadata?: `table` diff --git a/docs/ox_inventory/Functions/Server/Inventory/GetSlot.md b/docs/ox_inventory/Functions/Server/Inventory/GetSlot.md index e86452ed..2c8bb788 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/GetSlot.md +++ b/docs/ox_inventory/Functions/Server/Inventory/GetSlot.md @@ -1,10 +1,11 @@ Returns the specified slot data as a table. ```lua --- inv: string or number --- slot: number + exports.ox_inventory:GetSlot(inv, slot) ``` +* inv: `string` or `number` +* slot: `number` **Example:** ```lua @@ -23,4 +24,4 @@ print(json.encode(slot, {indent=true})) "count: 4 } ]] -``` \ No newline at end of file +``` diff --git a/docs/ox_inventory/Functions/Server/Inventory/RegisterStash.md b/docs/ox_inventory/Functions/Server/Inventory/RegisterStash.md index a0e30119..8c4c479d 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/RegisterStash.md +++ b/docs/ox_inventory/Functions/Server/Inventory/RegisterStash.md @@ -1,25 +1,23 @@ Creates a new custom stash. ```lua --- id: string or number --- label: string --- slots: number --- maxWeight: number --- owner: string or boolean or nil --- groups: table --- coords: vector3 exports.ox_inventory:RegisterStash(id, label, slots, maxWeight, owner, groups, coords) ``` - -* `id` - Stash identifier when loading from the database. -* `label` - Display name when inventory is open. -* `owner` - Defines stash permissions. - * `string`: Can only access the stash linked to the owner. - * `true`: Each player has a unique stash but can request other player's stashes. - * `nil`: Always shared. -* `groups` - Player groups (jobs) able to access the stash. +* id: `string` or `number` + * Stash identifier when loading from the database. +* label: `string` + * Display name when inventory is open. +* slots: `number` +* maxWeight: `number` +* owner: `string` or `boolean` or `nil` + * `string`: Can only access the stash linked to the owner. + * `true`: Each player has a unique stash but can request other player's stashes. + * `nil`: Always shared. +* groups: `table` + * Table of player groups (jobs) able to access the stash. * Table of group names where the numeric value is the minimum grade required. * `{['police'] = 0, ['ambulance'] = 2}` +* coords: `vector3` :::caution @@ -28,4 +26,4 @@ This function needs to be triggered before a player can open the stash. **Example:** -For a use case example on this function check out the written [Guide](../../../Guides/stashes.md) for it. \ No newline at end of file +For a use case example on this function check out the written [Guide](../../../Guides/stashes.md) for it. diff --git a/docs/ox_inventory/Functions/Server/Inventory/ReturnInventory.md b/docs/ox_inventory/Functions/Server/Inventory/ReturnInventory.md index 84ecdb05..ed9664ac 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/ReturnInventory.md +++ b/docs/ox_inventory/Functions/Server/Inventory/ReturnInventory.md @@ -3,6 +3,6 @@ Returns the confiscated inventory back to the player. Use it alongside [ConfiscateInventory](./ConfiscateInventory.md). ```lua --- source: number exports.ox_inventory:ReturnInventory(source) -``` \ No newline at end of file +``` +* source: `number` diff --git a/docs/ox_inventory/Functions/Server/Inventory/Search.md b/docs/ox_inventory/Functions/Server/Inventory/Search.md index 6a54753c..7050d762 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/Search.md +++ b/docs/ox_inventory/Functions/Server/Inventory/Search.md @@ -1,12 +1,13 @@ Searches an inventory for a specified item. ```lua --- inv: string or number --- search: string --- item: table or string --- metadata: table or string (optional) + exports.ox_inventory:Search(inv, search, item, metadata) ``` +* inv: `string` or `number` +* search: `string` +* item: `table` or `string` +* metadata?: `table` or `string` `search` can be either `'slots'` or `'count'`, where slots will return a table of data -and count will return the found amount of the specified item. \ No newline at end of file +and count will return the found amount of the specified item. diff --git a/docs/ox_inventory/Functions/Server/Inventory/SetDurability.md b/docs/ox_inventory/Functions/Server/Inventory/SetDurability.md index 59e5a158..8a5c3ec6 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/SetDurability.md +++ b/docs/ox_inventory/Functions/Server/Inventory/SetDurability.md @@ -3,11 +3,11 @@ Sets durability onto the specified slot. Can be used for repairing weapons. ```lua --- inv: string or number --- slot: number --- durability: number exports.ox_inventory:SetDurability(inv, slot, durability) ``` +* inv: `string` or `number` +* slot: `number` +* durability: `number` **Example:** ```lua @@ -22,4 +22,4 @@ local weapon = ox_inventory:GetCurrentWeapon(source) if weapon then ox_inventory:SetDurability(source, weapon.slot, 100) end -``` \ No newline at end of file +``` diff --git a/docs/ox_inventory/Functions/Server/Inventory/SetMetadata.md b/docs/ox_inventory/Functions/Server/Inventory/SetMetadata.md index ff3c9315..5e03221c 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/SetMetadata.md +++ b/docs/ox_inventory/Functions/Server/Inventory/SetMetadata.md @@ -1,11 +1,11 @@ Sets metadata on the specified slot. ```lua --- inv: string or number --- slot: number --- metadata: table ox_inventory:SetMetadata(inv, slot, metadata) ``` +* inv: `string` or `number` +* slot: `number` +* metadata: `table` **Example:** ```lua diff --git a/docs/ox_inventory/Functions/Server/Inventory/SwapSlots.md b/docs/ox_inventory/Functions/Server/Inventory/SwapSlots.md index 40f944b6..43e9ff37 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/SwapSlots.md +++ b/docs/ox_inventory/Functions/Server/Inventory/SwapSlots.md @@ -1,9 +1,9 @@ Swaps slots in specified inventories. ```lua --- fromInventory: any --- toInventory: any --- slot1: number --- slot2: number exports.ox_inventory:SwapSlots(fromInventory, toInventory, slot1, slot2) -``` \ No newline at end of file +``` +* fromInventory: `any` +* toInventory: `any` +* slot1: `number` +* slot2: `number` diff --git a/docs/ox_inventory/Functions/Server/setPlayerInventory.md b/docs/ox_inventory/Functions/Server/setPlayerInventory.md index 67955b53..6917ad21 100644 --- a/docs/ox_inventory/Functions/Server/setPlayerInventory.md +++ b/docs/ox_inventory/Functions/Server/setPlayerInventory.md @@ -1,13 +1,14 @@ Creates and sets the player's inventory. ```lua --- player: table - -- source: number - -- identifier: string - -- name: string - -- groups: table (optional) - -- sex: string (optional) - -- dateofbirth: string (optional) --- data: table exports.ox_inventory:setPlayerInventory(player, data) -``` \ No newline at end of file +``` +* player: `table` + * source: `number` + * identifier: `string` + * name: `string` + * groups?: `table` + * sex?: `string` + * dateofbirth?: `string` +* data?: `table` + * If not provided will load player's inventory data from the db.