Containerinstallableitem
Overview
This component allows an entity to be "installed" into specific containers or inventory slots. It provides a framework for defining custom validation logic for target containers and custom callback functions that execute when the item is installed into or uninstalled from a container. It also handles various scenarios where an item enters or leaves a container, such as being placed in inventory, dropped, or swapped.
Dependencies & Tags
This component implicitly relies on the inventoryitem component to determine if an item is held by an owner.
No specific tags are added or removed by this component.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | self | A reference to the entity this component is attached to. |
ismastersim | boolean | true | Indicates if the component is running on the master simulation. |
validcontainerfn | function | nil | An optional callback function (inst, containerinst) used to determine if a container is valid for installation. |
oninstalledfn | function | nil | An optional callback function (inst, target) to execute when the item is installed into a target. |
onuninstalledfn | function | nil | An optional callback function (inst, target) to execute when the item is uninstalled from a target. |
_owner | Entity | nil | The entity that currently "owns" or contains this item (e.g., a container or inventory). |
usedeferreduninstall | boolean | nil | If true, the exitlimbo event handler is disabled, deferring uninstall logic. |
ignoreuninstall | boolean | nil | If true, temporarily disables the uninstall logic from triggering. |
Main Functions
SetValidContainerFn(fn)
- Description: Sets a custom function to validate if a given container is suitable for this item.
- Parameters:
fn: A function(inst, containerinst)that should returntrueifcontainerinstis a valid container forinst, orfalseotherwise. Ifnil, any container is considered valid.
IsValidContainer(containerinst)
- Description: Checks if a given container entity is considered valid for this item, either by the custom
validcontainerfnor by default if no custom function is set. - Parameters:
containerinst: The container entity to validate.
GetValidOpenContainer(doer)
- Description: Searches for an open container within the
doer's inventory that is also a valid container for this item according toIsValidContainer. - Parameters:
doer: The entity whose inventory should be checked for open containers.
SetInstalledFn(fn)
- Description: Sets the callback function to be invoked when this item is installed into a container.
- Parameters:
fn: A function(inst, target)to call when the item is installed.instis the item itself,targetis the container it's installed into.
SetUninstalledFn(fn)
- Description: Sets the callback function to be invoked when this item is uninstalled from a container.
- Parameters:
fn: A function(inst, target)to call when the item is uninstalled.instis the item itself,targetis the container it was uninstalled from.
SetUseDeferredUninstall(enable)
- Description: Controls whether the
exitlimboevent listener is enabled. Enabling this defers uninstall logic, which can be useful when swapping items. - Parameters:
enable: A boolean. Iftrue, theexitlimbolistener is removed. Iffalse, it is added back.
OnInstalled(target)
- Description: Triggers the installation logic, calling the
oninstalledfnif set, and pushing thecontainerinstalleditemevent. - Parameters:
target: The entity (container) that this item is being installed into.
OnUninstalled(target)
- Description: Triggers the uninstallation logic, calling the
onuninstalledfnif set, and pushing thecontaineruninstalleditemevent. - Parameters:
target: The entity (container) that this item is being uninstalled from.
Events & Listeners
- Listens for:
"onputininventory": Triggered when the item is placed into any inventory slot. Callstopocketto handle installation logic."ondropped": Triggered when the item is dropped to the ground. Callstogroundto handle uninstallation logic."exitlimbo": Triggered when an item is removed from an inventory slot but not necessarily dropped (e.g., during a swap). Callsonexitlimboto handle uninstallation logic, unless deferred uninstall is enabled.
- Pushes:
"containerinstalleditem": Pushed to thetargetentity whenOnInstalledis called, withself.instas the event data."containeruninstalleditem": Pushed to thetargetentity whenOnUninstalledis called, withself.instas the event data.