core.metatables.sh_inventory

(no description)

Functions

AddItem(item, noSync, noSave)

Internal

This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.

View source »

Add an item to an inventory, this is also synced over the network unless specified otherwise. This is intended to load in items from DB into the inventory object, item must already exist as you pass the item object.

Parameters

  • item

  • noSync

  • noSave

AddReceiver(client)

View source »

Adds a player as a receiver on this Inventory Receivers are players who will be networked the items inside the inventory.

Calling this will not automatically sync it's current contents to the client. All future contents will be synced, but not anything that was not synced before this is called.

This function does not check the validity of client, therefore if client doesn't exist, it will error.

Parameters

  • client Player

    The player to add as a receiver.

AllowActions(bool)

View source »

This will let you use actions in ths inventory

Parameters

  • bool bool

    If true, actions will be allowed

AllowTransfers(bool)

View source »

This will enable player item transfers in or out of this inventory (players transferring via UI, not manual transfers which are always allowed) By default, this is disabled to prevent any exploits from inventories that don't have checks set up.

Parameters

  • bool bool

    If true, transfers will be allowed

CanAction(action, client, item)

View source »

This is designed to be overwritten to allow custom checks for inventory actions. By default, no item player actions (e.g player use) will be allowed from this inventory unless AllowActions is set or this function is overwritten. This is because most inventories will just be for transferring, and it'll be bad if there's an exploit where players can use items from inventories far away from them (e.g use items from their bank).

Parameters

  • action string

    The action to check

  • client Player

    The player to check

  • item Item

    The item to check

Returns

  • boolean

    If the action is allowed

CanFit(size)

View source »

Checks whether a given item size will fit in this inventory, useful for if the item isn't created yet and you need to make sure it'll fit.

Parameters

  • size number

    Size of item to check

Returns

  • bool

    Whether or not the item can fit

CanFitItem(item)

View source »

Checks whether a given item can fit into this inventory

Parameters

  • item

Returns

  • bool

    Whether or not the item can fit

CanTransfer(client, item)

View source »

Checks if a player has permission to transfer an item from or to this inventory

Parameters

  • client

  • item

Create(uniqueID, amount, force)

View source »

Create a new item and add it into this inventory If the item is stackable and it already exists, it'll just add to the stack as long as it won't reach the maximum stack. If the item reaches maximum stack, it'll add in as many existing items as possible before creating new ones. This is intended to be a replacement for cityrp.inventory.update for adding items

Parameters

  • uniqueID string

    Unique ID of the item to create

  • amount number

    Quantity of the item to create (adds to stack if stackable, creates amount if not). Default 1

  • force bool optional

    If true, will ignore the inventory's size limit

Returns

  • bool

    If the item was created successfully

  • OR
  • false

    If the item could not be created

  • string

    Error message

DatabaseSerializeData()

View source »

Serializes the data table for database persistence. Filters out DATA_TEMP entries that should not be saved.

Returns

GetCount()

View source »

Returns how many items are in this inventory (including stacked items).

Returns

  • number

    Amount of items in inventory

GetData(key, default)

View source »

Get data from an inventory, stored as JSON internally. This is synced.

Parameters

  • key string

    Key to get data from

  • default optional

    any Default value if data is invalid

Returns

  • any

    Data stored under the given key, or default if does not exist

GetFreeSpace()

View source »

Returns the amount of free space avaliabe in an inventory

Returns

  • integer

    Amount of free space in inventory

GetID()

View source »

Returns this inventory's database ID. An ID of 0 is the world inventory.

Returns

  • number

    Inventory ID

GetItem(uniqueID)

View source »

Returns the first item with the given unique ID (e.g "watermelon") if it exists in this inventory. This is recommended if you just need to quickly see if they have a certain item. This is probably the quickest way you can get an item from an inventory.

Parameters

  • uniqueID string

    uniqueID of the item to find

Returns

  • item

    First occurance of uniqueID specified

  • OR
  • bool

    False if no item with the uniqueID was found

GetItemByID(uniqueID, itemID)

View source »

Gets an item by it's uniqueID and itemID.

Parameters

  • uniqueID string

    Unique ID of the item to look for

  • itemID string

    Item ID of the item to look for

Returns

  • item

    Item with the given uniqueID and itemID

GetItemCount(uniqueID)

View source »

Returns how many items of a specific ID are in this inventory (including stacked items).

Parameters

  • uniqueID string

    uniqueID to look for

Returns

  • number

    Amount of items in inventory, nil if none

GetItems(uniqueID)

View source »

Returns all items, if uniqueID is specified it will return all items with that uniqueID

Parameters

  • uniqueID string

    of the item to find

Returns

  • table

    Either all items or all items matching uniqueID. The table isn't sequential, data structure is at shown at top of Inventory.

  • any

    table

GetItemsByCategory(category)

View source »

Returns items, either those part of a certain category or all items sorted into a table with category.

Parameters

  • category string

    The category of items to find

Returns

GetItemsSeq(uniqueID)

View source »

Returns all items in a sequential table.

Parameters

  • uniqueID string

    of the item to find

Returns

  • table

    Either all items or all items matching uniqueID.

GetMaxSize()

View source »

Returns this inventory's maximum size. A size of 0 is infinite.

Returns

  • number

    Inventory size

GetOwner()

View source »

Returns the player that owns this inventory.

GetOwnerSID64()

View source »

Returns the steamID64 of the player that owns this inventory, this is useful if they're not online.

GetReceivers()

View source »

Get all of the receivers this Inventory has. Receivers are players who will be networked the items inside the inventory.

This function will automatically sort out invalid players for you.

Returns

  • table

    result The players who are on the server and allowed to see this table.

GetSize()

View source »

Returns this inventory's current size.

Returns

  • number

    Inventory size

HasItem(uniqueID, dataKey, data)

View source »

Returns the sorted item with the given unique ID (e.g "watermelon") if it exists in this inventory. It will sort items as defined by the baseItem.sort method (if it exists) You can specify optional data to search for within it too, this will return first found matching the data and uniqueID instead.

Parameters

  • uniqueID string

    Unique ID of the item to look for

  • dataKey string optional

    Item data key to check for

  • data optional

    Item data to check for within that key (key required if doing this)

Returns

  • Item

    Item that belongs to this inventory with the given criteria

  • OR
  • false

    If no item was found

Example Usage

local item = inventory:HasItem("watermelon")

if (item) then
	-- do something with the item table
end

See Also

HasItems(uniqueID, dataKey, dataVal)

View source »

Returns all items that match the given unique ID (e.g "watermelon") if it exists in this inventory. This is returns a sequential table, unlike GetItems() It will sort items as defined by the baseItem.sort method (if it exists) You can specify optional data to search for within it too, this will only return things matching the data and uniqueID.

Parameters

  • uniqueID string

    Unique ID of the item to look for

  • dataKey string

    Item data key to check for

  • dataVal string

    data Item data to check for within that key (key required if doing this)

Returns

  • optional

    All Items that belongs to this inventory with the given criteria (sequential table) or nil if not found

See Also

IsInInventory(item)

View source »

Checks if the item passed belongs to this inventory

Parameters

  • item

Returns

  • bool

    Whether or not the item belongs to this inventory

NetSerializeData()

View source »

Serializes the data table for network transmission. Filters out DATA_SERVER entries and returns flat key=value pairs.

Returns

NetSync(enum, client)

View source »

Sync inventory to receivers over the network.

Parameters

  • enum INV_SYNC

    Enum to filter what to sync, defaults to all

  • client optional

    Client to sync to, will sync to all if nil

OnCheckAccess(client)

Internal

This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.

View source »

Checks whether a player has access to an inventory

Parameters

  • client Player

    Player to check access for

Returns

  • bool

    Whether or not the player has access to the inventory

PrintAll()

View source »

Prints the inventory contents, useful for debugging and development.

Remove(item, amount)

View source »

Remove some amount of an item from this inventory, this is basically removing it This is intended to be a replacement for cityrp.inventory.update for removing items Will delete the item if the stack 0, will just delete non-stackable items.

Parameters

  • item

  • amount

RemoveItem(item, noSync, noSave)

Internal

This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.

View source »

Remove an item from an inventory, this is also synced over the network unless specified otherwise. Removed items will be set to the inventory ID of 0, and will be removed from the inventory object. If you want to delete the item, use item:Delete() as it'll also call this function after actually deleting it.

Parameters

  • item

  • noSync

  • noSave

RemoveReceiver(client)

View source »

The opposite of AddReceiver. This function does not check the validity of client, therefore if client doesn't exist, it will error.

Parameters

  • client Player

    The player to remove from the receiver list.

SetData(key, data, receivers, dataType)

View source »

Set data for this inventory, stored as JSON internally. This is also synced over the network. Setting something to nil will remove it.

Parameters

  • key string

    Key to store data under

  • data any

    Data to store

  • receivers Player or table optional

    Receivers to send the data to, if nil it will send to all receivers of this inventory

  • dataType integer optional

    Data scope type (DATATEMP, DATAPLAYER, DATASERVER). Defaults to DATAPLAYER.

SetMaxSize(size)

View source »

Sets the maximum size of this inventory

Parameters

  • size number

    Size to set

SetOwner(Player)

View source »

Sets the player that owns this inventory.

Parameters

  • Player client or string

    or SteamID64 to set as owner

ShouldSave()

View source »

Gets whether or not an Inventory should save. Inventories that are marked to not save will not update in the Database, if the inventory is already saved,it will not be deleted when unloaded.

Transfer(item, tInv, amount, force)

View source »

Transfer an item from this inventory to a target inventory This is intended to be a replacement for cityrp.inventory.update for moving items to somewhere else If you need a callback, see item:Transfer

Parameters

  • item

  • tInv

  • amount

  • force

__eq(inventory)

View source »

Returns true if this inventory is equal to another inventory. Internally, this checks inventory IDs.

Parameters

  • inventory

Returns

  • bool

    Whether or not this inventory is equal to the given item > false

__tostring()

View source »

Returns a string representation of this inventory

Returns

  • string

    String representation > "inventory[1]"

Tables

Inventory

View source »
Incomplete

Documentation for this section is incomplete and needs expanding.

Fields

  • Class fun(self:

    ): Allocate Inventory Allocate a new uninitialized inventory instance

  • Class fun(self:

    ): Allocate Inventory Allocate a new uninitialized inventory instance