SlashCo Wiki

ITEM

ITEM

Description

Table structure used for SlashCo.RegisterItem.
An item file (lua/slashco/item/*.lua) builds a local ITEM table, sets fields/callbacks on it, then calls SlashCo.RegisterItem(ITEM, "Name").

Most callbacks below are looked up by name straight off the raw item table (SlashCoItems[item].CallbackName), not through a metatable, so only the exact names listed here are ever read by the framework.

ITEM.Screenspace, ITEM.PreDrawHalos, ITEM.Thirdperson, ITEM.OnFootstep, ITEM.CanBeSeen, ITEM.CanSeeFlashlights, ITEM.OnDie, ITEM.OnOwnerTakeDamage, ITEM.PreDropSecondary and ITEM.PrePickUpPrimary/ITEM.PrePickUpSecondary are all resolved through dispatch functions that check the player's active effects first - see EFFECT for the equivalent fields on an effect table, which take priority over an item's when both define the same one.

Parameters

string Model

Path to the item's world model.
Used as the default model for this item's own ViewModel/WorldModel/WorldModelHolstered tables, set on the physical pickup entity by sc_baseitem, shown in the item picker's preview panel, and readable off a secondary item via Player:ItemValue (e.g. by SlashCo.CreateItem calls made when a generator consumes a GasCan/Battery).

string Name

The item's display/registration name.
Used as the fallback identifier by SlashCo.RegisterItem when its name argument is omitted (name = name or table.Name).

string EntClass

Class name of the entity spawned when this item exists as a physical pickup in the world (via SlashCo.CreateItem).
Also used for the reverse lookup SlashCo.GetItemByEntity, and checked directly by some Slasher abilities via Player:ItemValue to detect a specific item (e.g. Princess/Sid checking for "sc_baby"/"sc_cookie").

number Price

How many Points the item costs in the lobby shop; deducted from the buyer's balance on purchase.

Items without this field are skipped entirely by the item picker's selection list (if not itemTbl.Price then continue end) - setting Price is what makes an item choosable at all, even a secondary item that is never actually bought (e.g. GasCan/Battery set Price = 0).

Also readable through Player:ItemValue as a generic "does this player have any priced item" check (used by Slasher Tyler's ability).

Vector CamPos

Camera offset used by the DModelPanel preview in the item picker UI (DModelPanel:SetCamPos).

boolean IsSpawnable (Optional)

If true, the item is added to SlashCo.SpawnableItems at load time, allowing it to spawn randomly in the world.

Default: false

boolean IsSecondary (Optional)

If true, the item occupies the secondary ("item2") slot instead of the primary ("item") one.
Affects which slot Player:SetItem assigns it to, which slot is dropped/checked first by SlashCo.DropItem/SlashCo.ItemPickUp, and the color/styling of its box in the survivor HUD.

Default: false

boolean Unbreakable (Optional)

If true, marks the item so it is skipped when SlashCo.DropItem is called with ignoreField = "Unbreakable".
"Unbreakable" isn't a hardcoded field name in SlashCo.DropItem itself, it's simply the string convention used by callers such as Slasher Tyler's ability (which drops/destroys whichever of a survivor's two items isn't marked this way) - only Battery currently sets it.

table ViewModel (Optional)

Render definition for the item as shown in the survivor's own hands (first person). If unset, nothing is rendered in the survivor's hands for this item.

string ViewModel.model

Model to render. Usually just ITEM.Model.

Vector ViewModel.pos

Position offset from the view bone (ValveBiped.Bip01_Spine4, forced by the framework), relative to the bone's own angle.

Angle ViewModel.angle

Angle offset applied on top of the bone's angle.

Vector ViewModel.size

Per-axis render scale, applied as a matrix.

Color ViewModel.color

Color modulation/blend applied while drawing the model.

string ViewModel.material

Material override; use "" to use the model's own materials.

number ViewModel.skin (Optional)

Skin index to set on the model.

Default: 0

table ViewModel.bodygroup (Optional)

Table of [bodygroupID] = value entries applied to the model.

boolean ViewModel.surpresslightning (Optional)

If true, engine lighting is suppressed while this model is drawn (sic - matches the field name used in code).

Default: false

table WorldModel (Optional)

Render definition for the item as shown on the survivor's body (world/third person) while it is the currently equipped/active item. If unset, nothing is rendered in-hand in third person for this item.

string WorldModel.holdtype

Hold type passed to SWEP:SetHoldType while this item is equipped (e.g. "normal", "slam", "duel", "passive").

string WorldModel.bone

Name of the bone on the survivor model to attach to (looked up via Player:LookupBone).

string WorldModel.model

Model to render. Usually just ITEM.Model.

Vector WorldModel.pos

Position offset from the bone, relative to the bone's own angle.

Angle WorldModel.angle

Angle offset applied on top of the bone's angle.

Vector WorldModel.size

Per-axis render scale, applied as a matrix.

Color WorldModel.color

Color modulation/blend applied while drawing the model.

string WorldModel.material

Material override; use "" to use the model's own materials.

number WorldModel.skin (Optional)

Skin index to set on the model.

Default: 0

table WorldModel.bodygroup (Optional)

Table of [bodygroupID] = value entries applied to the model.

boolean WorldModel.surpresslightning (Optional)

If true, engine lighting is suppressed while this model is drawn.

Default: false

table WorldModelHolstered (Optional)

Render definition for the item as shown holstered on the survivor's body while the other slot is the one currently equipped/active. If unset, nothing is rendered holstered for this item.

string WorldModelHolstered.bone

Name of the bone on the survivor model to attach to.

string WorldModelHolstered.model

Model to render. Usually just ITEM.Model.

Vector WorldModelHolstered.pos

Position offset from the bone, relative to the bone's own angle.

Angle WorldModelHolstered.angle

Angle offset applied on top of the bone's angle.

Vector WorldModelHolstered.size

Per-axis render scale, applied as a matrix.

Color WorldModelHolstered.color

Color modulation/blend applied while drawing the model.

string WorldModelHolstered.material

Material override; use "" to use the model's own materials.

number WorldModelHolstered.skin (Optional)

Skin index to set on the model.

Default: 0

table WorldModelHolstered.bodygroup (Optional)

Table of [bodygroupID] = value entries applied to the model.

boolean WorldModelHolstered.surpresslightning (Optional)

If true, engine lighting is suppressed while this model is drawn.

Default: false

string ToolTip (Optional)

Language key shown as an extra tooltip line under the item's name box in the survivor HUD, in addition to the normal use/drop hints.

function Precache (Optional)

function()
Called by SlashCo.PrecacheItem, in addition to the automatic precaching of ITEM.Model. Use it to precache any extra models/sounds/materials this item needs.

function MaxAllowed (Optional)

function() -> number
If defined, caps how many survivors may hold this item at once. Enforced both server-side when buying it in the lobby shop, and client-side in the item picker (which greys out selection once the cap is reached).

function EquipSound (Optional)

function() -> string
If defined, called by SlashCo.ChangeSurvivorItem to get a sound path to play in place of the default random equip sound whenever this item is equipped.

function OnBuy (Optional)

function()
Called server-side right after a survivor purchases and equips this item through the lobby shop.

function DisplayColor (Optional)

function(ply) -> r, g, b, a
Called by the survivor HUD to get the background color of the item's name box, called on the item itself (not affected by active effects). Falls back to a default color per slot if unset or if it returns nothing.

function ModifyRender (Optional)

function(model, renderTable)
Called client-side every render frame, right before the equipped item's ViewModel/WorldModel/WorldModelHolstered table is applied to the clientside model panel, letting the item tweak renderTable (or model directly) beforehand. Not currently used by any shipped item.

function OnSetModel (Optional)

function(model, renderTable)
Called client-side whenever the rendered clientside model panel's actual model changes to the one set by renderTable.model (e.g. to reset its sequence). Not currently used by any shipped item besides LabMeat.

function OnRenderHand (Optional)

function(ply, modelPanel)
Called client-side after this item's ViewModel has been rendered in the survivor's hands each frame. Not currently used by any shipped item.

function OnRenderWorld (Optional)

function(ply, modelPanel)
Called client-side after this item's WorldModel has been rendered each frame while it is the active/equipped item. Not currently used by any shipped item.

function OnRenderHolstered (Optional)

function(ply, modelPanel)
Called client-side after this item's WorldModelHolstered has been rendered each frame while it is holstered. Not currently used by any shipped item.

boolean IsFuel (Optional)

Marks a secondary item as valid fuel for sc_generator; checked via Player:ItemValue("IsFuel", false, true).

boolean IsBattery (Optional)

Marks a secondary item as a valid battery for sc_generator; checked via Player:ItemValue("IsBattery", false, true).

number FuelSpeed (Optional)

Multiplier for how fast a generator fuels while this item is held; divides the generator's DefaultTimeToFuel (checked via Player:ItemValue/Player:PerkValue).

Default: 1

function OnFuel (Optional)

function(ply, generator)
Dispatched via Player:SecondaryItemFunction (so an active effect's OnFuel would take priority) when this ITEM.IsFuel secondary item is poured into a sc_generator. Not currently used by any shipped item.

function OnBattery (Optional)

function(ply, generator)
Dispatched the same way as ITEM.OnFuel, when this ITEM.IsBattery secondary item is installed into a sc_generator. Not currently used by any shipped item.

function OnUse (Optional)

function(ply) -> doNotRemove
Called by SlashCo.UseItem when the survivor uses their held item (secondary slot takes priority). If it returns a truthy value the item stays equipped and an "item unusable" sound plays instead; otherwise the item is removed/consumed.

function OnPickUp (Optional)

function(ply)
Called directly on the item (not through the effect-checked dispatch) right when it becomes newly equipped via SlashCo.ChangeSurvivorItem, whether from a world pickup or a lobby purchase.

function OnSwitchFrom (Optional)

function(ply)
Called on an item right before its slot's value changes away from it - when it's dropped, replaced by picking up another item, or removed via SlashCo.RemoveItem.

function PreDrop (Optional)

function(ply) -> dontDrop
Called on the item about to be dropped (secondary slot takes priority) at the very start of SlashCo.DropItem. Returning a truthy value cancels the drop entirely.

function PreDropSecondary (Optional)

function(ply, secondaryItem) -> dontDrop
Declared on the primary item; dispatched via Player:ItemFunction (so an active EFFECT.PreDropSecondary takes priority) right before the secondary item is dropped, letting the primary item veto it. secondaryItem is the name of the item about to be dropped.

function OnDrop (Optional)

function(ply) -> height, dontDrop, dontPush
Called on the item after its slot has already been cleared, right before its dropped world entity is created.
height (number, optional, default 60): Z offset above the player to spawn the dropped entity at.
dontDrop (boolean, optional): if truthy, aborts creating the dropped entity (the slot has already been cleared by this point regardless).
dontPush (boolean, optional): if truthy, skips giving the dropped entity's physics object a push velocity/spin.

function ItemDropped (Optional)

function(ply, droppedEntity, phys)
Called on the item right after its dropped world entity has been created (and, unless dontPush was set, launched).

function PrePickUp (Optional)

function(ply, itemindex) -> dontPickup
Called on the item about to be picked up itself, via SlashCo.ItemPickUp. Returning a truthy value cancels the pickup.

function PrePickUpPrimary (Optional)

function(ply, item, itemindex) -> dontPickup
Declared on a secondary item; dispatched via Player:SecondaryItemFunction right before a new primary item is picked up, letting the currently-held secondary item veto it. item is the name of the item about to be picked up.

function PrePickUpSecondary (Optional)

function(ply, item, itemindex) -> dontPickup
Declared on a primary item; dispatched via Player:ItemFunction right before a new secondary item is picked up, letting the currently-held primary item veto it.

function CanBeSeen (Optional)

function(ply) -> visible
Dispatched via Player:ItemFunction (active effects take priority) to override whether the survivor holding this item can currently be seen. Return nil/nothing to not override.

function CanSeeFlashlights (Optional)

function(ply) -> canSee
Same dispatch as ITEM.CanBeSeen, but overrides whether the survivor holding this item can see other players' flashlights.

function OnFootstep (Optional)

function(ply) -> suppress
Dispatched via Player:ItemFunction. If it returns a truthy value, this survivor's footstep sound (and the "step notice" visual the Slasher would otherwise perceive) is suppressed.

function OnDie (Optional)

function(ply) -> dontTickLife
Dispatched via Player:ItemFunction when the survivor dies. Returning a truthy value skips the entire normal death sequence (dropping all items, losing a life, spawning a ragdoll, moving to spectator) so the item can implement custom handling instead, e.g. DeathWard reviving the survivor.

function OnOwnerTakeDamage (Optional)

function(ply, dmg) -> result
Dispatched via Player:ItemFunction whenever the survivor holding this item takes damage. Can mutate dmg in place (e.g. dmg:ScaleDamage(...)). If it returns a non-nil value, that value is returned from the gamemode's EntityTakeDamage hook (returning true blocks the damage entirely).

function Screenspace (Optional)

function()
Dispatched client-side via Player:ItemFunction every frame while the local survivor is alive, to draw custom post-processing/screen effects.

function PreDrawHalos (Optional)

function()
Dispatched client-side via Player:ItemFunction while halos are being drawn for the local survivor. Not currently used by any shipped item.

function Thirdperson (Optional)

function() -> useThirdperson
Dispatched via Player:ItemFunction from CalcView. If it returns a truthy value, the gamemode computes a custom third-person camera for the survivor; otherwise the default first-person view is used. Not currently used by any shipped item.