add some inventory examples

This commit is contained in:
Linden committed 2022-05-15 22:27:07 +10:00
1 parent 7380341246
commit c1d420aeaa
5 files changed
+44 -15

No files matched your search

@@ -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()
```
```
+26 -2
View File
@@ -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)
```
```
```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)
```
@@ -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).
```lua
exports.ox_inventory:CustomDrop('Carcass', {
{'meat', 5, { grade = 2, type = 'deer' }},
{'hide', 5, { grade = 2, type = 'deer' }}
}, coords)
```
@@ -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))
```
```
-3
View File
@@ -1,3 +0,0 @@
---
title: Creating custom drops
---