core.metatables.sh_item

(no description)

Functions

CanAction(actionName, client, override, ...)

View source »

Hey! If you're here looking how how to make a player do something, see cityrp.item.Action

Parameters

  • client Player optional

  • override boolean optional

  • ... any optional

Returns

  • boolean

CanPlace()

View source »

Returns if the item can be Placed

Returns

  • boolean

    If the item can be placed

CanPlayerTransfer(client, invTo, client, invTo)

View source »

Returns if this item can be transfered by a player, this doesn't prevent the item from being moved by code. This uses the item base's canTransfer function if it has one.

Parameters

  • client

    Player to check if they can transfer this item

  • invTo

    inventory The inventory to transfer to

  • client

    Player to check if they can transfer this item

  • invTo

    inventory The inventory to transfer to

Returns

  • boolean

    If the item can be transfered

ContainsText(text)

View source »

Check if a certain text is contained within this item.

Parameters

  • text

DatabaseSerializeData()

View source »

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

Returns

Delete(permanent)

View source »

Delete the item

Parameters

  • permanent boolean

    If the item should be deleted permanently, otherwise it soft deletes to allow a chance at recovery.

Returns

  • boolean

    If the item was deleted

DisablePlayerTransfer(state)

View source »

Disable this item from being transfered by a player, this doesn't prevent the item from being moved by code. See locked for that. Useful for items that need to be "locked" to an inventory but can still be used This value will save to the item data and therefore to DB, you only need to set it once.

Parameters

  • state boolean

    If the item can be transfered

GetBase()

View source »

Returns the itemCore base of this item, this is the legacy item table.

Returns

  • table

    The base table of this item (legacy table)

GetBaseCost()

View source »

Returns the base cost of this item (for one item, not the stack)

Returns

  • number

    The cost of this item

GetCategory()

View source »

Returns the category of this item.

Returns

  • string

    The category of this item

GetCost()

View source »

Returns the cost of this item.

Returns

  • number

    The cost of this item

GetData(key)

View source »

Get data from an item, stored as JSON internally. This is also synced over the network.

Parameters

  • key string

    Key to get data from @[opt]string default Default value if data is invalid

Returns

  • string

    Data stored under the given key, nil if does not exist

GetDescription()

View source »

Returns the description of this item.

Returns

  • string

    The description of this item

GetEntity()

View source »

Returns the entity set to this item, nil if none.

Returns

  • optional

GetFreeStackSpace()

View source »

Returns how many items can fit into this stack before it is full, nil if not stackable

GetID()

View source »

Get the DB ID of this item instance.

Returns

  • number

    The DB ID of this item instance

GetInventory()

View source »

Return the inventory this item is in

Returns

  • inventory

    The inventory this item is in

  • any

    Inventory

GetInventoryID()

View source »

Return the inventory ID for this item

Returns

  • number

GetMaxStack()

View source »

Returns the maximum stack of this item, nil if not stackable

Returns

  • number or nil

    The stack of this item, nil if not stackable

GetModel()

View source »

Get the model of this item, if it has one. This is designed for dispalying items in the inventory. It will give the storemodel if exists, else it'll give the model.

Returns

  • string

    The model of this item

GetName()

View source »

Returns the name of this item.

Returns

  • string

    The name of this item

GetOwner()

View source »

Return the owner of this item (owner of inventory)

Returns

  • Player

    The owner of this item

  • any

    Player

GetSize()

View source »

Returns the size of this item. This will never return a negative number.

Returns

  • number

    The size of this item

GetStack()

View source »

Returns the stack of this item, will return nil if not stackable

Returns

  • number or nil

    The stack of this item, nil if not stackable

GetUniqueID()

View source »

Returns the uniqueID of this item.

Returns

  • string

    The uniqueID of this item

HandleDecrease(amount)

View source »

This will decrease the stack of the item by amount, and delete if the amount reaches 0 If the item isn't stackable, it'll just delete the item

Parameters

  • amount number

    The amount to remove from the stack

IsLocked()

View source »

Returns if an item is "locked", this means it can't be used or moved.

Returns

  • boolean

    If the item is disabled

IsPlaced()

View source »

Returns if an item is "placed", this means it can't be used or moved.

Returns

  • boolean

    If the item is placed

MergeInto(item, amount)

Internal

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

View source »

Merge this item with another item Must be the same uniqueID and stackable If the total amount is over maxStack, it'll only merge up to maxStack

Parameters

  • item Item

    to merge into

  • amount Amount

    to merge from this item into specified, if nil it'll merge the entire stack

Returns

  • item Item this merged into, false if failed

See Also

NetSerializeData()

View source »

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

Returns

PlayerAction(action)

Internal

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

View source »

Performs a generic action

Parameters

  • action string

    The action to perform

See Also

PlayerDrop(int)

Internal

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

View source »

Drop an item, this will call the item's onDrop function. This function contains a lot of jank code due to the legacy item system. It's a modified version of legacy cityrp.item.drop() function.

Parameters

  • int optional

    amount The quantity to drop, only used for stackable items

Returns

  • entity or boolean

    The dropped item if succeeded, otherwise false

See Also

PlayerGive(tClient, amount)

Internal

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

View source »

Give an item to a player, this will call the item's onGive function. This function contains a lot of jank code due to the legacy item system. It's a modified version of legacy cityrp.item.give() function.

Parameters

  • tClient player

    Player to give the item to

  • amount number optional

    Amount of the item to give, only used for stackable items

Returns

  • boolean

    If it succeeded

See Also

PlayerMerge(client, item)

Internal

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

View source »

Merge a players item into another, for stackable items

Parameters

  • client

  • item

Returns

  • boolean

    If the item was destroyed

See Also

PlayerPickup(client)

Internal

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

View source »

Called when a player attempts to pick up a placed item, requires the item to already be placed and owned by world

Parameters

  • client

    Player who is attempting to pick this item up

Returns

  • boolean

    If the item was picked up

See Also

PlayerPlace(vector, angle)

Internal

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

View source »

Called when a player attempts to "place" an item, this used to be drop for some items but now it's more of a "use" action

Parameters

  • vector

    Position to place the item

  • angle

    Angles to place the item

Returns

  • boolean

    If the item was placed

See Also

PlayerRemove(client)

Internal

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

Deprecated

This function is deprecated and may be removed in a future version.

View source »

"Remove" an item, this will call the item's onRemove function. This is actually just "take off", it's stupid I know. To remove an item from an inventory, see ???. To delete an item, see ???. This function contains a lot of jank code due to the legacy item system. It's a modified version of legacy cityrp.item.remove() function.

Parameters

  • client

Returns

  • boolean

    If it succeeded

See Also

PlayerSplit(amount)

Internal

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

View source »

Split a stackable item into two

Parameters

  • amount number optional

    Amount of the item to split into the new stack, defaults to 1

Returns

  • boolean

    If the item was destroyed

See Also

PlayerUse(client)

Internal

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

View source »

Use an item, this will call the item's onUse function. This function contains a lot of jank code due to the legacy item system. It's a modified version of legacy cityrp.item.use() function.

Parameters

  • client

Returns

  • boolean

    If it succeeded

See Also

Remove(amount)

View source »

Remove some amount of this item 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

  • amount

RequestAction(action, data)

View source »

Request for an action to be taken by the server The server will fully validate the request For data structure, see cityrp.item.Action This uses cityrp.item.Action on the server

Parameters

  • action string

    The action to perform

  • data table

    The data to send to the server

See Also

SetCrashProtect(sid)

View source »

Will return this item to a players inventory if belongs to the world but was last "used" by a player. This is used in the placed system for returning placed items, but can also be used for anything else as it is generic.

Parameters

  • sid string

    Crash protection ID, if this is set to a player's SID64 then crash protection is enabled. To disable, set to nil (non-string value)

SetData(key, data, receivers, dataType)

View source »

Set data for this item, 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 the receivers of this inventory

  • dataType integer optional

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

SetEntity(ent)

View source »

Sets the entity related to this item

Parameters

  • ent Entity optional

    Entity to set to this item, nil to remove

SetEquipped(state)

View source »

Toggle the equipped state of this item.

Parameters

  • state bool

    The state to set the item to

Returns

  • boolean

    If the item was equipped

SetStack(amount)

View source »

Set the stack to the specified amount. You probably want to use ITEM:Stack() instead, this is intended for initialising the stack on load. This will only work if the item is marked as stackable by ITEM.stackable

Parameters

  • amount number

    The amount to add/remove the stack by

Returns

  • boolean

    If the stack was changed

ShouldGlobalSync()

View source »

Returns if the item has global sync enabled

Returns

  • boolean

    If the item has global sync enabled

Split(amount, callback)

View source »

Split this item into two items, with the amount of the new stack specified.

Parameters

  • amount number

    Amount of the new stack

  • callback function optional

    Callback to call when the split is complete. Will have item passed to it

Returns

  • Item

    The new item

  • OR
  • false

    If the split failed

Stack(amount)

View source »

Add/remove the stack of this item.

Parameters

  • amount number

    The amount to add to the stack

Returns

  • boolean

    If the stack was changed

Stackable()

View source »

Returns if an item is stackable or not

Returns

  • boolean

    If the item is stackable or not

Transfer(tInv, amount, force, callback)

View source »

Transfer this item to another inventory

Parameters

  • tInv Inventory

    Inventory to transfer to

  • amount number optional

    Amount of the item to transfer, only used for stackable items. Defaults to full stack/entire item if not specified.

  • force boolean optional

    If the transfer should be forced, even if the inventory is full

  • callback function optional

    Callback to call when the transfer is complete. Will have item and inventory (new if applicable) passed to it

Returns

  • true

    If the no errors were raised (note: due to DB actions, this is unable to gurantee if it succeeded or not)

  • OR
  • false

    If the transfer failed

  • string

    Error message

See Also

__eq(item)

View source »

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

Parameters

  • item

Returns

  • bool

    Whether or not this item is equal to the given item

__tostring()

View source »

Returns a string representation of this item.

Returns

  • string

    String representation

Tables

Item

View source »
Incomplete

Documentation for this section is incomplete and needs expanding.

Fields

  • id integer

  • cost number

  • size integer

  • stack integer optional

  • maxStack integer optional

  • storeModel string optional

    The item object represents an item within an inventory. This is used for interacting with items in an inventory.
    This class is not meant to be used for creating new items, see itemCore for that.