Class ITEM

Item Metatable The ITEM metatable is a bit weird, having some quirks. Typically, functions which relate to generating the items / setting data (New, SetDescription) are in UpperCamelCase. However, functions which relate to the operation of the item (canUse, onDrop), are in lowerCamelCase.

Class Overview

Hooks

ITEM.canUse(ply) Checks if a item can be used.
ITEM.canGive(ply, to, amt) Checks if a item can be given.
ITEM.canRemove(ply) Checks if a item can be removed.
ITEM.canDrop(ply, pos, amt) Checks if a item can be dropped.
ITEM.canDestroy(ply, amt) Checks if a item can be destroyed.
ITEM.canPickup(ply) Checks if a item can be picked up.
ITEM.canSell(ply, amt) Checks if a item can be sold up.
ITEM.canPlace(ply, pos, amt) Checks if a item can be placed.

Fields

ITEM.name Item Name.
ITEM.description Description of the item.
ITEM.size Item Size
ITEM.cost Item Cost
ITEM.model Model Path
ITEM.store Market Availability
ITEM.category Inventory / Market Category
ITEM.skin Skin used in the F1 menu.
ITEM.__index The lookup index for the item metatable.

Methods

ITEM:New(base, data) Create a new item.
ITEM:Clone() Clone an item.
ITEM:Merge(data) Merge a table of data into the item.
ITEM:SetData(name, value) Set a single key on the item.
ITEM:Register([id]) Register an item.
ITEM:AutoFunction(name, key) Creates an automatically named setter function.
ITEM:SetCost(cost) Sets the Market Cost.
ITEM:SetPrice(data) Alias of ITEM:SetCost
ITEM:SetDescription(data) Sets the Description of an item.
ITEM:SetDesc(data) Alias of ITEM:SetDescription
ITEM:SetCategory(data) Sets the category of an item.
ITEM:SetCat(data) Alias of ITEM:SetCategory
ITEM:SetTeam(data) Sets the team of an item.
ITEM:SetBatch(data) Sets the number of items created in a press of the manufacture button.
ITEM:SetMember(data) Sets the required membership level to use this item.
ITEM:SetREPs(data) Sets the required REP count to use this item.
ITEM:SetREP(data) Alias of ITEM:SetREPs
ITEM:SetCanUse(data) Sets the canUse function on this item.
ITEM:SetSize(data) Sets the inventory size of this item.
ITEM:SetName(name[, Plural=s]) Sets the name of an item.
ITEM:SetModel(model, skin[, Should]) Sets the model of the item.
ITEM:SetStoreModel(model, skin) Sets the store model of the item.
ITEM:SetStoreSkin(skin[, autoStore]) Sets the store skin of the item.
ITEM:SetPlural([name]) Sets the item's plural.
ITEM:SetStore(val) Set if the item is in store, and its batch amount.
ITEM:Replaced([by]) Sets if a item is replaced.
ITEM:Replacement(new, old) Create a simple replacement item.
ITEM:CanUse(func) Sets the canUse function for this item.
ITEM:OnUse(func) Sets the onUse function for this item.
ITEM:CanGive(func) Sets the canGive function for this item.
ITEM:OnGive(func) Sets the onGive function for this item.
ITEM:CanRemove(func) Sets the canRemove function for this item.
ITEM:OnRemove(func) Sets the onRemove function for this item.
ITEM:CanDrop(func) Sets the canDrop function for this item.
ITEM:OnDrop(func) Sets the onDrop function for this item.
ITEM:CanDestroy(func) Sets the canDestroy function for this item.
ITEM:OnDestroy(func) Sets the onDestroy function for this item.
ITEM:CanPickup(func) Sets the canPickup function for this item.
ITEM:OnPickup(func) Sets the onPickup function for this item.
ITEM:CanSell(func) Sets the canSell function for this item.
ITEM:OnSell(func) Sets the onSell function for this item.
ITEM:CanPlace(func) Sets the canPlace function for this item.
ITEM:onPlace(func) Sets the onPlace function for this item.

Hooks

ITEM.canUse(ply)
Checks if a item can be used.

Parameters:

  • ply Player Player using the item.
ITEM.canGive(ply, to, amt)
Checks if a item can be given.

Parameters:

  • ply Player Player giving the item.
  • to Player Player receiving the item.
  • amt int Number of items being given.
ITEM.canRemove(ply)
Checks if a item can be removed.

Parameters:

  • ply Player Player removing the item.
ITEM.canDrop(ply, pos, amt)
Checks if a item can be dropped.

Parameters:

  • ply Player Player dropping the item.
  • pos Vector Drop location.
  • amt int Number of items being dropped.
ITEM.canDestroy(ply, amt)
Checks if a item can be destroyed.

Parameters:

  • ply Player Player destroying the item.
  • amt int Number of items being destroyed.
ITEM.canPickup(ply)
Checks if a item can be picked up.

Parameters:

  • ply Player Player picking the items up.
ITEM.canSell(ply, amt)
Checks if a item can be sold up.

Parameters:

  • ply Player Player selling items.
  • amt int Number of items being sold.
ITEM.canPlace(ply, pos, amt)
Checks if a item can be placed.

Parameters:

  • ply Player Player placing items.
  • pos Vector Place location.
  • amt int Number of items being placed.

Fields

ITEM.name
Item Name.
  • name string The localised name, as shown in the F1 menu.
ITEM.description
Description of the item.
ITEM.size
Item Size
  • size number The inventory space used per item.
ITEM.cost
Item Cost
  • cost int The cost of the item as bought in the market. Also used for inventory valuations and refund sales.
ITEM.model
Model Path
  • model string Path of the model used in the F1 menu / dropped states.
ITEM.store
Market Availability
  • store bool
ITEM.category
Inventory / Market Category
ITEM.skin
Skin used in the F1 menu.
  • skin int
ITEM.__index
The lookup index for the item metatable.

Methods

ITEM:New(base, data)
Create a new item.

Parameters:

  • base string UniqueID of the baseclass.
  • data tab Optional data to fill into the item.

Returns:

    ITEM
ITEM:Clone()
Clone an item. Returns a new ITEM, with base set to the first item.

Returns:

    ITEM
ITEM:Merge(data)
Merge a table of data into the item.

Parameters:

  • data tab Key/Value pairs of data.

Returns:

    ITEM
ITEM:SetData(name, value)
Set a single key on the item.

Parameters:

  • name string Key to set.
  • value Value to set.

Returns:

    ITEM
ITEM:Register([id])
Register an item. This must be the last call in an item chain, as it does processing on the item.

Parameters:

  • id string UniqueID to set, not required if set prior. (optional)
ITEM:AutoFunction(name, key)
Creates an automatically named setter function. It also returns a single param function, which sets a default value and returns the item.

Parameters:

  • name string Function Key (Resolves to Set).
  • key string Internal key to set.

Returns:

    function

See also:

Usage:

    local setDefault = ITEM:AutoFunction("SpecialValue", "internal_flag")
    -- This creates a function, ITEM:SetSpecialValue().
    -- Calling this function sets a value on ITEM.internal_flag.
    -- Calling setDefault, sets the value now, returning the item. This is useful for chaining.
    ITEM:AutoFunction("SomeValue", "this_defaults_to_false")(false)
ITEM:SetCost(cost)
Sets the Market Cost.

Parameters:

  • cost int Cost.

Returns:

    ITEM
ITEM:SetPrice(data)
Alias of ITEM:SetCost

Parameters:

  • data int Cost.

Returns:

    ITEM

See also:

ITEM:SetDescription(data)
Sets the Description of an item.

Parameters:

Returns:

    ITEM
ITEM:SetDesc(data)
Alias of ITEM:SetDescription

Parameters:

Returns:

    ITEM

See also:

ITEM:SetCategory(data)
Sets the category of an item.

Parameters:

Returns:

    ITEM
ITEM:SetCat(data)
Alias of ITEM:SetCategory

Parameters:

Returns:

    ITEM

See also:

ITEM:SetTeam(data)
Sets the team of an item.

Parameters:

  • data int Team Index

Returns:

    ITEM
ITEM:SetBatch(data)
Sets the number of items created in a press of the manufacture button.

Parameters:

  • data int Batch

Returns:

    ITEM
ITEM:SetMember(data)
Sets the required membership level to use this item.

Parameters:

  • data int Membership Level

Returns:

    ITEM
ITEM:SetREPs(data)
Sets the required REP count to use this item.

Parameters:

  • data int REP Count

Returns:

    ITEM
ITEM:SetREP(data)
Alias of ITEM:SetREPs

Parameters:

Returns:

    ITEM

See also:

ITEM:SetCanUse(data)
Sets the canUse function on this item.

Parameters:

  • data func canUse function.

Returns:

    ITEM
ITEM:SetSize(data)
Sets the inventory size of this item.

Parameters:

  • data int Size

Returns:

    ITEM
ITEM:SetName(name[, Plural=s])
Sets the name of an item. If plural is undefined, defaults to "s" If plural is true, it's set to ""

Parameters:

ITEM:SetModel(model, skin[, Should])
Sets the model of the item. If model is true, the model and skin will be pulled from the store model. If autostore is true, model and skin will be pushed to the store model.

Parameters:

  • model string or true Model path.
  • skin int Skin index.
  • Should bool this also automatically set the store models. (optional)

Returns:

    ITEM
ITEM:SetStoreModel(model, skin)
Sets the store model of the item. If model is true, the model and skin will be pulled from the regular model.

Parameters:

  • model string or true Model path.
  • skin int Skin index.

Returns:

    ITEM
ITEM:SetStoreSkin(skin[, autoStore])
Sets the store skin of the item. If skin is true, it is pulled from the item skin.

Parameters:

  • skin int or true skin
  • autoStore bool If skin should be pushed to item skin. (optional)
ITEM:SetPlural([name])
Sets the item's plural. If nil/false, item's name + s is used. If true, item's name is used. Otherwise passed name is used.

Parameters:

  • name string or true (optional)

Returns:

    ITEM
ITEM:SetStore(val)
Set if the item is in store, and its batch amount. If boolean, store is directly set. If 0, store is set to false. Otherwise store is set true and the value

Parameters:

  • val bool or int Store Setting / Batch Amount

Returns:

    ITEM
ITEM:Replaced([by])
Sets if a item is replaced. If called with no args, replaced flag is cleared.

Parameters:

  • by string Unique ID of replaced item. (optional)

Returns:

    ITEM
ITEM:Replacement(new, old)
Create a simple replacement item. new's item must be registered before the replacement call.

Parameters:

  • new string Unique ID of the replacement.
  • old string Unique ID of the old item.
ITEM:CanUse(func)
Sets the canUse function for this item.

Parameters:

  • func func [opt=function() return true end] Function to set as the canUse function.

Returns:

    ITEM
ITEM:OnUse(func)
Sets the onUse function for this item.

Parameters:

  • func func Function to set as the onUse function.

Returns:

    ITEM
ITEM:CanGive(func)
Sets the canGive function for this item.

Parameters:

  • func func [opt=function() return true end] Function to set as the canGive function.

Returns:

    ITEM
ITEM:OnGive(func)
Sets the onGive function for this item.

Parameters:

  • func func Function to set as the onGive function.

Returns:

    ITEM
ITEM:CanRemove(func)
Sets the canRemove function for this item.

Parameters:

  • func func [opt=function() return true end] Function to set as the canRemove function.

Returns:

    ITEM
ITEM:OnRemove(func)
Sets the onRemove function for this item.

Parameters:

  • func func Function to set as the onRemove function.

Returns:

    ITEM
ITEM:CanDrop(func)
Sets the canDrop function for this item.

Parameters:

  • func func [opt=function() return true end] Function to set as the canDrop function.

Returns:

    ITEM
ITEM:OnDrop(func)
Sets the onDrop function for this item.

Parameters:

  • func func Function to set as the onDrop function.

Returns:

    ITEM
ITEM:CanDestroy(func)
Sets the canDestroy function for this item.

Parameters:

  • func func [opt=function() return true end] Function to set as the canDestroy function.

Returns:

    ITEM
ITEM:OnDestroy(func)
Sets the onDestroy function for this item.

Parameters:

  • func func Function to set as the onDestroy function.

Returns:

    ITEM
ITEM:CanPickup(func)
Sets the canPickup function for this item.

Parameters:

  • func func [opt=function() return true end] Function to set as the canPickup function.

Returns:

    ITEM
ITEM:OnPickup(func)
Sets the onPickup function for this item.

Parameters:

  • func func Function to set as the onPickup function.

Returns:

    ITEM
ITEM:CanSell(func)
Sets the canSell function for this item.

Parameters:

  • func func [opt=function() return true end] Function to set as the canSell function.

Returns:

    ITEM
ITEM:OnSell(func)
Sets the onSell function for this item.

Parameters:

  • func func Function to set as the onSell function.

Returns:

    ITEM
ITEM:CanPlace(func)
Sets the canPlace function for this item.

Parameters:

  • func func [opt=function() return true end] Function to set as the canPlace function.

Returns:

    ITEM
ITEM:onPlace(func)
Sets the onPlace function for this item.

Parameters:

  • func func Function to set as the onPlace function.

Returns:

    ITEM