From c1d420aeaa45b37785238807495225ec2c727d9a Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 15 May 2022 22:27:07 +1000 Subject: [PATCH] add some inventory examples --- .../Functions/Client/openNearbyInventory.md | 4 +-- docs/ox_inventory/Functions/Client/useItem.md | 28 +++++++++++++++++-- .../Functions/Server/Inventory/CustomDrop.md | 21 +++++++++----- .../Functions/Server/Inventory/SetMetadata.md | 3 +- docs/ox_inventory/Guides/customDrop.md | 3 -- 5 files changed, 44 insertions(+), 15 deletions(-) delete mode 100644 docs/ox_inventory/Guides/customDrop.md diff --git a/docs/ox_inventory/Functions/Client/openNearbyInventory.md b/docs/ox_inventory/Functions/Client/openNearbyInventory.md index dc7a1caa..d6efd961 100644 --- a/docs/ox_inventory/Functions/Client/openNearbyInventory.md +++ b/docs/ox_inventory/Functions/Client/openNearbyInventory.md @@ -1,9 +1,9 @@ If possible opens the nearby player's inventory. -The player trying to open the invenotry must be able to open their own and +The player trying to open the inventory must be able to open their own and if the player does not have a police job, the target player must be fatally injured or playing one of the death anims. ```lua exports.ox_inventory:openNearbyInventory() -``` \ No newline at end of file +``` diff --git a/docs/ox_inventory/Functions/Client/useItem.md b/docs/ox_inventory/Functions/Client/useItem.md index 695acc4e..5b4e3122 100644 --- a/docs/ox_inventory/Functions/Client/useItem.md +++ b/docs/ox_inventory/Functions/Client/useItem.md @@ -1,7 +1,31 @@ -Uses the passed item, then triggers the callback function. +Uses the passed item, then triggers the callback function. +Should be calling during item callbacks to utilise the builtin methods (server checks, progress bar, etc.). ```lua -- data: table -- cb: function (optional) exports.ox_inventory:useItem(data, cb) -``` \ No newline at end of file +``` + +```lua +exports('bandage', function(data, slot) + local playerPed = PlayerPedId() + local maxHealth = GetEntityMaxHealth(playerPed) + local health = GetEntityHealth(playerPed) + + -- Does the ped need to heal? + if health < maxHealth then + -- Use the bandage + exports.ox_inventory:useItem(data, function(data) + -- The item has been used, so trigger the effects + if data then + SetEntityHealth(playerPed, math.min(maxHealth, math.floor(health + maxHealth / 16))) + exports.ox_inventory:notify({text = 'You feel better already'}) + end + end) + else + -- Don't use the item + exports.ox_inventory:notify({type = 'error', text = 'You don\'t need a bandage right now'}) + end +end) +``` diff --git a/docs/ox_inventory/Functions/Server/Inventory/CustomDrop.md b/docs/ox_inventory/Functions/Server/Inventory/CustomDrop.md index c0e7eec3..d6f0e4fb 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/CustomDrop.md +++ b/docs/ox_inventory/Functions/Server/Inventory/CustomDrop.md @@ -1,14 +1,21 @@ -Creates an inventory drop at the specified coords. +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 --- maxWeight: number --- instance: ? (optional) -exports.ox_inventory:CustomDrop(prefix, item, coords, slots, maxWeight, instance) +-- slots: number (optional) +-- maxWeight: number (optional) +-- instance: string | number (optional) +exports.ox_inventory:CustomDrop(prefix, items, coords, slots, maxWeight, instance) ``` -**Example:** -You can find and example showcasing this function into furher detail [here](../../../Guides/customDrop.md). \ No newline at end of file +```lua +exports.ox_inventory:CustomDrop('Carcass', { + {'meat', 5, { grade = 2, type = 'deer' }}, + {'hide', 5, { grade = 2, type = 'deer' }} +}, coords) +``` diff --git a/docs/ox_inventory/Functions/Server/Inventory/SetMetadata.md b/docs/ox_inventory/Functions/Server/Inventory/SetMetadata.md index fbdb55da..ff3c9315 100644 --- a/docs/ox_inventory/Functions/Server/Inventory/SetMetadata.md +++ b/docs/ox_inventory/Functions/Server/Inventory/SetMetadata.md @@ -16,8 +16,9 @@ for k, v in pairs(water) do print('\n______________'..'\n- index '..k) print(v.name, 'slot: '..v.slot, 'metadata: '..json.encode(v.metadata)) water = v + break end water.metadata.type = 'clean' ox_inventory:SetMetadata(source, water.slot, water.metadata) print(('modified %sx water in slot %s with new metadata'):format(water.count, water.slot)) -``` \ No newline at end of file +``` diff --git a/docs/ox_inventory/Guides/customDrop.md b/docs/ox_inventory/Guides/customDrop.md deleted file mode 100644 index 3252c7e1..00000000 --- a/docs/ox_inventory/Guides/customDrop.md +++ /dev/null @@ -1,3 +0,0 @@ ---- -title: Creating custom drops ---- \ No newline at end of file