Provide some examples in functions

This commit is contained in:
Luke committed 2022-03-11 16:30:39 +01:00
1 parent 881a1cfc13
commit 2d7f8b4f28
11 files changed
+97 -3

No files matched your search

@@ -8,4 +8,14 @@ The function checks for inventory weight and available slots.
-- count: number
-- metadata: table or string (optional)
exports.ox_inventory:CanCarryItem(inv, item, count, metadata)
```
**Example:**
```lua
-- Checks if the player calling the event can carry 3 water items
if exports.ox_inventory:CanCarryItem(source, 'water', 3) then
-- Do stuff if can carry
else
-- Do stuff if can't carry
end
```
@@ -8,4 +8,7 @@ Creates an inventory drop at the specified coords.
-- maxWeight: number
-- instance: ? (optional)
exports.ox_inventory:CustomDrop(prefix, item, coords, slots, maxWeight, instance)
```
```
**Example:**
You can find and example showcasing this function into furher detail [here](../../../../Guides/customDrop.md).
@@ -8,6 +8,25 @@ Returns the item from the specified inventory.
exports.ox_inventory:GetItem(inv, item, metadata, returnsCount)
```
If `returnsCount` is set to true, the returned value will include `count` based on
If `returnsCount` is set to true, the returned value will be the `count` based on
how many times the item was found.
Otherwise returns the data related to the item _and_ it's total count found in the inventory.
**Example**:
```lua
local item = ox_inventory:GetItem(source, 'water', nil, false)
print(json.encode(item, {indent=true}))
--[[
{
"consume": 1,
"count": 15,
"stack": true,
"name": "water",
"weight": 500,
"label": "Water",
"close": true
}
]]
```
@@ -4,4 +4,23 @@ Returns the specified slot data as a table.
-- inv: string or number
-- slot: number
exports.ox_inventory:GetSlot(inv, slot)
```
**Example:**
```lua
local slot = exports.ox_inventory:GetSlot(source, 1)
print(json.encode(slot, {indent=true}))
--[[
{
"weight": 2000,
"name": "water",
"metadata": [],
"slot": 1,
"label": "Water",
"close": true,
"stack": true,
"count: 4
}
]]
```
@@ -24,4 +24,8 @@ exports.ox_inventory:RegisterStash(id, label, slots, maxWeight, owner, groups, c
:::caution
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.
@@ -7,4 +7,10 @@ Removes the specified item from the specified inventory.
-- metadata: table or string (optional)
-- slot: number (optional)
exports.ox_inventory:RemoveItem(inv, item, count, metadata, slot)
```
**Example:**
```lua
-- Removes 1 water from the inventory
exports.ox_inventory:RemoveItem(source, 'water', 1)
```
@@ -7,4 +7,19 @@ Can be used for repairing weapons.
-- slot: number
-- durability: number
exports.ox_inventory:SetDurability(inv, slot, durability)
```
**Example:**
```lua
local ox_inventory = exports.ox_inventory
-- Set the durability of the item in slot 3 of source player's inventory to 100
ox_inventory:SetDurability(source, 3, 100)
-- Set the durability of the source player's current weapon to 100
local weapon = ox_inventory:GetCurrentWeapon(source)
if weapon then
ox_inventory:SetDurability(source, weapon.slot, 100)
end
```
@@ -5,4 +5,19 @@ Sets metadata on the specified slot.
-- slot: number
-- metadata: table
ox_inventory:SetMetadata(inv, slot, metadata)
```
**Example:**
```lua
local ox_inventory = exports.ox_inventory
local water = ox_inventory:Search(source, 1, 'water')
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
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
@@ -0,0 +1,3 @@
---
title: Creating custom drops
---
Whitespace-only changes.
Whitespace-only changes.