BaseInventoryItemclass
Base for anything that can live in an `Sandbox.BaseInventoryComponent`. Handles the basics every item needs - a networked slot, editor metadata, and overridable equip/holster lifecycle - so deriving an item is almost no boilerplate. Usable as-is for a simple no-code pickup, or derive from it for weapons, tools, etc.
Constructors1
Showing 1 constructors
public BaseInventoryItem()
No results match this filter.
Methods12
Showing 12 methods
public bool CanPickup(Sandbox.BaseInventoryComponent inventory)
True when the given inventory is allowed to pick this item up (see `Sandbox.BaseInventoryItem.OnCanPickup(Sandbox.BaseInventoryComponent)`). Queryable by UI - a pure check, nothing happens.
| Parameter | Type | Description |
|---|---|---|
| inventory | BaseInventoryComponent | — |
bool—public bool CanSwitchTo()
True when the inventory is allowed to make this the active item (see `Sandbox.BaseInventoryItem.OnCanSwitchTo`). Queryable by UI - a pure check, nothing happens.
bool—protected virtual void OnAdded(Sandbox.BaseInventoryComponent inventory)
Called on the host when added to an inventory. Base does nothing.
| Parameter | Type | Description |
|---|---|---|
| inventory | BaseInventoryComponent | — |
void—protected virtual bool OnAdding(Sandbox.BaseInventoryComponent inventory)
About to be added to `inventory`. Return false to refuse - optionally consuming this item instead (a duplicate weapon donates its ammo, a stackable merges into its stack). Runs on the host for every add - pickups, loadouts, code. Base allows it.
| Parameter | Type | Description |
|---|---|---|
| inventory | BaseInventoryComponent | — |
bool—protected virtual bool OnCanPickup(Sandbox.BaseInventoryComponent inventory)
Can the given inventory pick this item up out of the world? Both the Use prompt and Touch pickup consult it, so a refused item shows no prompt - role-locked weapons, class restrictions, quest gates. Base allows it.
| Parameter | Type | Description |
|---|---|---|
| inventory | BaseInventoryComponent | — |
bool—protected virtual bool OnCanSwitchTo()
Return false to stop the inventory making this item active.
bool—protected virtual void OnControl()
Called each frame on the owning client while this is the active item - read input and drive the item's behaviour here (firing, reloading, aiming, etc). Pumped by the inventory; see `Sandbox.BaseInventoryComponent.Pump` and `Sandbox.BaseInventoryComponent.ManualPumping`. Base does nothing.
void—protected virtual bool OnDrop()
Places this item in the world after being dropped. The default unparents it (keeping its world position), enables it, drops network ownership, and gives it a small toss if it has a `Sandbox.Rigidbody`. Return false to refuse the drop (e.g. bound items). Override to customise placement or behaviour.
bool—protected virtual void OnEquipped()
Called on every peer when this becomes the active item. Base does nothing.
void—protected virtual void OnHolstered()
Called on every peer when this stops being the active item. Base does nothing.
void—protected virtual bool OnHolstering(Sandbox.BaseInventoryItem next)
The inventory is about to switch away from this (the active) item - to `next`, or to nothing when it's null. Return false to refuse and stay deployed (stash `next` to finish a put-down and re-issue the switch), or handle it here - e.g. cancel an in-progress reload - and return true to allow the switch. Not called on forced holsters (death, removal, dropping). Base allows it.
| Parameter | Type | Description |
|---|---|---|
| next | BaseInventoryItem | — |
bool—protected virtual void OnRemoved(Sandbox.BaseInventoryComponent inventory)
Called on the host when removed from an inventory. Base does nothing.
| Parameter | Type | Description |
|---|---|---|
| inventory | BaseInventoryComponent | — |
void—No results match this filter.
Properties9
Showing 9 properties
public Sandbox.Texture Sandbox.BaseInventoryItem.DisplayIcon { get; set; }
Icon shown in inventory UI.
public string Sandbox.BaseInventoryItem.DisplayName { get; set; }
Display name shown in inventory UI.
string—public Sandbox.BaseInventoryComponent Sandbox.BaseInventoryItem.Inventory { get; set; }
The inventory this item currently belongs to, or null if it isn't in one. Derived from the hierarchy so it's correct on every peer. The nearest ancestor, never this item's own GameObject - an item that is itself an inventory (a backpack) belongs to its holder.
public bool Sandbox.BaseInventoryItem.IsActive { get; set; }
True when this is the active (deployed) item in its inventory.
bool—public int Sandbox.BaseInventoryItem.PreferredSlot { get; set; }
The slot this item wants when added without an explicit one (GMod's SWEP.Slot). In a hotbar inventory it falls back to the first empty slot when taken, with -1 for no preference; in a buckets inventory the preference always wins.
int—public virtual bool Sandbox.BaseInventoryItem.ShouldAvoid { get; set; }
True when the inventory should avoid auto-switching to this item - e.g. a gun with nothing to fire. `Sandbox.BaseInventoryComponent.GetBestItem` falls back to avoided items only when there's nothing better.
bool—public int Sandbox.BaseInventoryItem.Slot { get; set; }
The slot this item occupies, or -1 if unassigned. Set by the inventory.
int—public int Sandbox.BaseInventoryItem.SlotOrder { get; set; }
Fixed sort position among items sharing a slot, lowest first (GMod's SWEP.SlotPos). Only matters in a buckets inventory - hotbar slots hold one item.
int—public int Sandbox.BaseInventoryItem.Value { get; set; }
Relative worth of this item. Used as the priority when the inventory has to pick a "best" item to fall back to (e.g. after the active item is removed). Higher wins.
int—No results match this filter.