mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-02 06:28:54 +00:00
Remove internal functions and move external ones
This commit is contained in:
1 parent
82518e769b
commit
49d5315d52
76 files changed
-3
No files matched your search
@@ -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)
|
||||
```
|
||||
@@ -0,0 +1,21 @@
|
||||
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)
|
||||
```
|
||||
|
||||
**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
|
||||
```
|
||||
@@ -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)
|
||||
```
|
||||
@@ -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.
|
||||
:::
|
||||
@@ -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)
|
||||
```
|
||||
@@ -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}]
|
||||
```
|
||||
@@ -0,0 +1,14 @@
|
||||
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)
|
||||
```
|
||||
|
||||
**Example:**
|
||||
You can find and example showcasing this function into furher detail [here](../../../../Guides/customDrop.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)
|
||||
```
|
||||
@@ -0,0 +1,32 @@
|
||||
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 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
|
||||
}
|
||||
]]
|
||||
```
|
||||
@@ -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)
|
||||
```
|
||||
@@ -0,0 +1,26 @@
|
||||
Returns the specified slot data as a table.
|
||||
|
||||
```lua
|
||||
-- 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
|
||||
}
|
||||
]]
|
||||
```
|
||||
@@ -0,0 +1,31 @@
|
||||
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.
|
||||
:::
|
||||
|
||||
**Example:**
|
||||
|
||||
For a use case example on this function check out the written [Guide](../../../../Guides/stashes.md) for it.
|
||||
@@ -0,0 +1,16 @@
|
||||
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)
|
||||
```
|
||||
|
||||
**Example:**
|
||||
```lua
|
||||
-- Removes 1 water from the inventory
|
||||
exports.ox_inventory:RemoveItem(source, 'water', 1)
|
||||
```
|
||||
@@ -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)
|
||||
```
|
||||
@@ -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.
|
||||
@@ -0,0 +1,25 @@
|
||||
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)
|
||||
```
|
||||
|
||||
**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
|
||||
```
|
||||
@@ -0,0 +1,23 @@
|
||||
Sets metadata on the specified slot.
|
||||
|
||||
```lua
|
||||
-- inv: string or number
|
||||
-- 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))
|
||||
```
|
||||
@@ -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)
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
Returns a table of all registered items.
|
||||
|
||||
```lua
|
||||
exports.ox_inventory:Items()
|
||||
```
|
||||
@@ -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)
|
||||
```
|
||||
Reference in new issue
Block a user