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
+95 -1

No files matched your search

@@ -9,3 +9,13 @@ The function checks for inventory weight and available slots.
-- metadata: table or string (optional) -- metadata: table or string (optional)
exports.ox_inventory:CanCarryItem(inv, item, count, metadata) 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
```
@@ -9,3 +9,6 @@ Creates an inventory drop at the specified coords.
-- instance: ? (optional) -- instance: ? (optional)
exports.ox_inventory:CustomDrop(prefix, item, coords, slots, maxWeight, instance) 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) 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. 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
}
]]
```
@@ -5,3 +5,22 @@ Returns the specified slot data as a table.
-- slot: number -- slot: number
exports.ox_inventory:GetSlot(inv, slot) 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
}
]]
```
@@ -25,3 +25,7 @@ exports.ox_inventory:RegisterStash(id, label, slots, maxWeight, owner, groups, c
This function needs to be triggered before a player can open the stash. 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.
@@ -8,3 +8,9 @@ Removes the specified item from the specified inventory.
-- slot: number (optional) -- slot: number (optional)
exports.ox_inventory:RemoveItem(inv, item, count, metadata, slot) exports.ox_inventory:RemoveItem(inv, item, count, metadata, slot)
``` ```
**Example:**
```lua
-- Removes 1 water from the inventory
exports.ox_inventory:RemoveItem(source, 'water', 1)
```
@@ -8,3 +8,18 @@ Can be used for repairing weapons.
-- durability: number -- durability: number
exports.ox_inventory:SetDurability(inv, slot, durability) 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
```
@@ -6,3 +6,18 @@ Sets metadata on the specified slot.
-- metadata: table -- metadata: table
ox_inventory:SetMetadata(inv, slot, metadata) 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.