Inventory external server functions

This commit is contained in:
Luke committed 2022-03-02 18:42:11 +01:00
1 parent 489d8c867d
commit 93820b147f
22 files changed
+225 -7

No files matched your search

@@ -1,7 +1,3 @@
---
title: Items
---
Returns a table of all registered items.
```lua
@@ -0,0 +1,24 @@
Adds an item into the specified inventory.
Should be used alongside [CanCarryItem](./CanCarryItem.md).
```lua
-- inv: string or number
-- item: table or string
-- count: number
-- metadata: table or string (optional)
-- slot: number (optional)
-- cb: function (optional)
exports.ox_inventory:AddItem(inv, item, count, metadata, slot, cb)
```
**Example:**
```lua
exports.ox_inventory:AddItem(1, 'bread', 4, nil, nil, function(success, reason)
if not success then
if reason == 'overburdened' then
TriggerClientEvent('ox_inventory:notify', source, {type = 'error', text = shared.locale('cannot_carry', count, data.label), duration = 2500})
end
end
end)
```
@@ -0,0 +1,11 @@
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)
```
@@ -0,0 +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)
```
@@ -0,0 +1,11 @@
Clears the specified inventory.
```lua
-- inv: string or number
-- keep: nil
exports.ox_inventory:ClearInventory(inv, keep)
```
:::caution
The `keep` argument is still unsupported and won't do anyting.
:::
@@ -0,0 +1,9 @@
Clears a player's inventory and saves it to a stash.
Use [ReturnInventory](./ReturnInventory.md) to return the confiscated inventory back to
the player.
```lua
-- source: number
exports.ox_inventory:ConfiscateInventory(source)
```
@@ -0,0 +1,13 @@
Takes traditional item data and updates it to support ox_inventory.
```lua
-- playerId: number
-- items: table
exports.ox_inventory:ConvertItems(playerId, items)
```
Data conversion example:
```
Old: [{"cola":1, "bread":3}]
New: [{"slot":1,"name":"cola","count":1}, {"slot":2,"name":"bread","count":3}]
```
@@ -0,0 +1,11 @@
Creates an inventory drop at the specified coords.
```lua
-- prefix: string
-- items: table
-- coords: vector3
-- slots: number
-- maxWeight: number
-- instance: ? (optional)
exports.ox_inventory:CustomDrop(prefix, item, coords, slots, maxWeight, instance)
```
@@ -0,0 +1,6 @@
Returns the player's currently equipped weapon as a table.
```lua
-- inv: string or number
exports.ox_inventory:GetCurrentWeapon(inv)
```
@@ -0,0 +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)
```
If `returnsCount` is set to true, the returned value will include `count` based on
how many times the item was found.
@@ -0,0 +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)
```
@@ -0,0 +1,7 @@
Returns the specified slot data as a table.
```lua
-- inv: string or number
-- slot: number
exports.ox_inventory:GetSlot(inv, slot)
```
@@ -0,0 +1,27 @@
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.
* Table of group names where the numeric value is the minimum grade required.
* `{['police'] = 0, ['ambulance'] = 2}`
:::caution
This function needs to be triggered before a player can open the stash.
:::
@@ -0,0 +1,10 @@
Removes the specified item from the specified inventory.
```lua
-- inv: string or table
-- item: table or string
-- count: number
-- metadata: table or string (optional)
-- slot: number (optional)
exports.ox_inventory:RemoveItem(inv, item, count, metadata, slot)
```
@@ -0,0 +1,8 @@
Returns the confiscated inventory back to the player.
Use it alongside [ConfiscateInventory](./ConfiscateInventory.md).
```lua
-- source: number
exports.ox_inventory:ReturnInventory(source)
```
@@ -0,0 +1,12 @@
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)
```
`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.
@@ -0,0 +1,10 @@
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)
```
@@ -0,0 +1,8 @@
Sets metadata on the specified slot.
```lua
-- inv: string or number
-- slot: number
-- metadata: table
ox_inventory:SetMetadata(inv, slot, metadata)
```
@@ -0,0 +1,9 @@
Swaps slots in specified inventories.
```lua
-- fromInventory: any
-- toInventory: any
-- slot1: number
-- slot2: number
exports.ox_inventory:SwapSlots(fromInventory, toInventory, slot1, slot2)
```
+5
View File
@@ -0,0 +1,5 @@
Returns a table of all registered items.
```lua
exports.ox_inventory:Items()
```
@@ -1,3 +0,0 @@
---
title: Placeholder
---
@@ -0,0 +1,13 @@
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)
```