From 93820b147fe0c2c5dd4b6d09556463b042399659 Mon Sep 17 00:00:00 2001 From: Luke Date: Wed, 2 Mar 2022 18:42:11 +0100 Subject: [PATCH] Inventory external server functions --- .../Client/{Items/index.md => Items.md} | 4 --- .../External/Server/Inventory/AddItem.md | 24 +++++++++++++++++ .../External/Server/Inventory/CanCarryItem.md | 11 ++++++++ .../External/Server/Inventory/CanSwapItem.md | 10 +++++++ .../Server/Inventory/ClearInventory.md | 11 ++++++++ .../Server/Inventory/ConfiscateInventory.md | 9 +++++++ .../External/Server/Inventory/ConvertItems.md | 13 +++++++++ .../External/Server/Inventory/CustomDrop.md | 11 ++++++++ .../Server/Inventory/GetCurrentWeapon.md | 6 +++++ .../External/Server/Inventory/GetItem.md | 13 +++++++++ .../External/Server/Inventory/GetItemSlots.md | 8 ++++++ .../External/Server/Inventory/GetSlot.md | 7 +++++ .../Server/Inventory/RegisterStash.md | 27 +++++++++++++++++++ .../External/Server/Inventory/RemoveItem.md | 10 +++++++ .../Server/Inventory/ReturnInventory.md | 8 ++++++ .../External/Server/Inventory/Search.md | 12 +++++++++ .../Server/Inventory/SetDurability.md | 10 +++++++ .../External/Server/Inventory/SetMetadata.md | 8 ++++++ .../External/Server/Inventory/SwapSlots.md | 9 +++++++ .../Functions/External/Server/Items.md | 5 ++++ .../Functions/External/Server/placeholder.md | 3 --- .../External/Server/setPlayerInventory.md | 13 +++++++++ 22 files changed, 225 insertions(+), 7 deletions(-) rename docs/ox_inventory/Functions/External/Client/{Items/index.md => Items.md} (78%) create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/AddItem.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/CanCarryItem.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/CanSwapItem.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/ClearInventory.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/ConfiscateInventory.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/ConvertItems.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/CustomDrop.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/GetCurrentWeapon.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/GetItem.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/GetItemSlots.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/GetSlot.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/RegisterStash.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/RemoveItem.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/ReturnInventory.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/Search.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/SetDurability.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/SetMetadata.md create mode 100644 docs/ox_inventory/Functions/External/Server/Inventory/SwapSlots.md create mode 100644 docs/ox_inventory/Functions/External/Server/Items.md delete mode 100644 docs/ox_inventory/Functions/External/Server/placeholder.md create mode 100644 docs/ox_inventory/Functions/External/Server/setPlayerInventory.md diff --git a/docs/ox_inventory/Functions/External/Client/Items/index.md b/docs/ox_inventory/Functions/External/Client/Items.md similarity index 78% rename from docs/ox_inventory/Functions/External/Client/Items/index.md rename to docs/ox_inventory/Functions/External/Client/Items.md index 014d5014..794ed622 100644 --- a/docs/ox_inventory/Functions/External/Client/Items/index.md +++ b/docs/ox_inventory/Functions/External/Client/Items.md @@ -1,7 +1,3 @@ ---- -title: Items ---- - Returns a table of all registered items. ```lua diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/AddItem.md b/docs/ox_inventory/Functions/External/Server/Inventory/AddItem.md new file mode 100644 index 00000000..618b31da --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/AddItem.md @@ -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) +``` \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/CanCarryItem.md b/docs/ox_inventory/Functions/External/Server/Inventory/CanCarryItem.md new file mode 100644 index 00000000..97553d8f --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/CanCarryItem.md @@ -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) +``` \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/CanSwapItem.md b/docs/ox_inventory/Functions/External/Server/Inventory/CanSwapItem.md new file mode 100644 index 00000000..59b9f775 --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/CanSwapItem.md @@ -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) +``` \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/ClearInventory.md b/docs/ox_inventory/Functions/External/Server/Inventory/ClearInventory.md new file mode 100644 index 00000000..312ff72b --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/ClearInventory.md @@ -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. +::: \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/ConfiscateInventory.md b/docs/ox_inventory/Functions/External/Server/Inventory/ConfiscateInventory.md new file mode 100644 index 00000000..45f76aa3 --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/ConfiscateInventory.md @@ -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) +``` diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/ConvertItems.md b/docs/ox_inventory/Functions/External/Server/Inventory/ConvertItems.md new file mode 100644 index 00000000..efbfede6 --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/ConvertItems.md @@ -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}] +``` \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/CustomDrop.md b/docs/ox_inventory/Functions/External/Server/Inventory/CustomDrop.md new file mode 100644 index 00000000..790088b3 --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/CustomDrop.md @@ -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) +``` \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/GetCurrentWeapon.md b/docs/ox_inventory/Functions/External/Server/Inventory/GetCurrentWeapon.md new file mode 100644 index 00000000..54fc5630 --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/GetCurrentWeapon.md @@ -0,0 +1,6 @@ +Returns the player's currently equipped weapon as a table. + +```lua +-- inv: string or number +exports.ox_inventory:GetCurrentWeapon(inv) +``` diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/GetItem.md b/docs/ox_inventory/Functions/External/Server/Inventory/GetItem.md new file mode 100644 index 00000000..49cfd5c6 --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/GetItem.md @@ -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. + diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/GetItemSlots.md b/docs/ox_inventory/Functions/External/Server/Inventory/GetItemSlots.md new file mode 100644 index 00000000..507c6405 --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/GetItemSlots.md @@ -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) +``` \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/GetSlot.md b/docs/ox_inventory/Functions/External/Server/Inventory/GetSlot.md new file mode 100644 index 00000000..ea9a1abd --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/GetSlot.md @@ -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) +``` \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/RegisterStash.md b/docs/ox_inventory/Functions/External/Server/Inventory/RegisterStash.md new file mode 100644 index 00000000..9b454d84 --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/RegisterStash.md @@ -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. +::: \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/RemoveItem.md b/docs/ox_inventory/Functions/External/Server/Inventory/RemoveItem.md new file mode 100644 index 00000000..0abc040a --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/RemoveItem.md @@ -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) +``` \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/ReturnInventory.md b/docs/ox_inventory/Functions/External/Server/Inventory/ReturnInventory.md new file mode 100644 index 00000000..84ecdb05 --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/ReturnInventory.md @@ -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) +``` \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/Search.md b/docs/ox_inventory/Functions/External/Server/Inventory/Search.md new file mode 100644 index 00000000..6a54753c --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/Search.md @@ -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. \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/SetDurability.md b/docs/ox_inventory/Functions/External/Server/Inventory/SetDurability.md new file mode 100644 index 00000000..ef2f7b4f --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/SetDurability.md @@ -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) +``` \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/SetMetadata.md b/docs/ox_inventory/Functions/External/Server/Inventory/SetMetadata.md new file mode 100644 index 00000000..8b6a9da0 --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/SetMetadata.md @@ -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) +``` \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Inventory/SwapSlots.md b/docs/ox_inventory/Functions/External/Server/Inventory/SwapSlots.md new file mode 100644 index 00000000..40f944b6 --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Inventory/SwapSlots.md @@ -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) +``` \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/Items.md b/docs/ox_inventory/Functions/External/Server/Items.md new file mode 100644 index 00000000..794ed622 --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/Items.md @@ -0,0 +1,5 @@ +Returns a table of all registered items. + +```lua +exports.ox_inventory:Items() +``` \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/placeholder.md b/docs/ox_inventory/Functions/External/Server/placeholder.md deleted file mode 100644 index 458256c8..00000000 --- a/docs/ox_inventory/Functions/External/Server/placeholder.md +++ /dev/null @@ -1,3 +0,0 @@ ---- -title: Placeholder ---- \ No newline at end of file diff --git a/docs/ox_inventory/Functions/External/Server/setPlayerInventory.md b/docs/ox_inventory/Functions/External/Server/setPlayerInventory.md new file mode 100644 index 00000000..67955b53 --- /dev/null +++ b/docs/ox_inventory/Functions/External/Server/setPlayerInventory.md @@ -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) +``` \ No newline at end of file