Deployhelper
Overview
The DeployHelper component equips an entity with the ability to "assist" or react to deployment actions occurring nearby. When an item is deployed by a player within a configurable range of an entity with this component, the DeployHelper can activate, triggering custom callbacks. Activation can be filtered by specific recipe names or a special deployhelper_key set on the placerinst. This component is designed for entities that provide temporary buffs or interactions based on proximity to player construction or placement.
Dependencies & Tags
This component implicitly relies on the entity (inst) having the capability to register for and receive periodic updates via inst:StartWallUpdatingComponent(self) and inst:StopWallUpdatingComponent(self). This usually means the entity either has a wallupdater component or implements similar update logic.
None identified for explicit tags added/removed by the component itself.
Properties
The DeployHelper component initializes several properties, primarily for callbacks and filtering.
| Property | Type | Default Value | Description |
|---|---|---|---|
onenablehelper | function | nil | A callback function (inst, enabled, recipename, placerinst) that is called when the helper starts (enabled = true) or stops (enabled = false). recipename and placerinst are only provided on enable. |
recipefilters | table | nil | A table of recipe names ({ [recipename] = true }) that, if present, determines which deployed recipes can activate this helper. Populated via AddRecipeFilter. |
keyfilters | table | nil | A table of keys ({ [key] = true }) that, if present, determines which placerinst.deployhelper_key values can activate this helper. Populated via AddKeyFilter. |
canenablehelper | function | nil | An optional callback function (inst) that returns true if the helper can currently be enabled, or false otherwise. If nil, the helper can always enable. |
onstarthelper | function | nil | An optional callback function (inst, recipename, placerinst) that is called immediately when the helper starts, even if already active. |
delay | number | nil | An internal countdown used to manage the helper's active duration. Not intended for direct external modification. |
Main Functions
TriggerDeployHelpers(x, y, z, range, recipe, placerinst)
- Description: This is a global function responsible for iterating through all active
DeployHelperinstances registered in theDEPLOY_HELPERStable. It checks if any helper is within the specified range of the deployment point and if it matches the provided recipe orplacerinst.deployhelper_keyfilters. If conditions are met andcanenablehelperallows, it callsStartHelperon the matchingDeployHelperinstance. - Parameters:
x: (number) The X coordinate of the deployment.y: (number) The Y coordinate of the deployment.z: (number) The Z coordinate of the deployment.range: (number) The maximum distance (radius) in which a helper can activate, measured from the deployment point.recipe: (table) TheRecipeobject for the item being deployed. Can benilif activation is key-based.placerinst: (entity) The entity that performed the deployment action. May contain adeployhelper_keyproperty.
DeployHelper:OnEntitySleep()
- Description: This method is called when the component's parent entity goes to sleep. It removes the helper from the global
DEPLOY_HELPERStable, effectively deactivating it, and callsStopHelperto clean up its state. - Parameters: None.
DeployHelper:OnEntityWake()
- Description: This method is called when the component's parent entity wakes up. It adds the helper back to the global
DEPLOY_HELPERStable, making it available for activation again. - Parameters: None.
DeployHelper:AddRecipeFilter(recipename)
- Description: Adds a specific recipe name to the internal
recipefilterstable. If this table is present, the helper will only activate for deployments of recipes listed here. - Parameters:
recipename: (string) The name of the recipe (e.g., "science_machine").
DeployHelper:AddKeyFilter(key)
- Description: Adds a specific key to the internal
keyfilterstable. If this table is present, the helper will only activate for deployments where theplacerinsthas a matchingdeployhelper_keyproperty. - Parameters:
key: (string) The key to add to the filter.
DeployHelper:StartHelper(recipename, placerinst)
- Description: Activates the helper. If it's not already active (or delayed), it sets an internal
delaycountdown, registers the component for periodic updates viainst:StartWallUpdatingComponent, and triggers theonenablehelpercallback (withtrue) andonstarthelpercallback. Ifdelayis already set, it simply resetsdelayto 2. - Parameters:
recipename: (string) The name of the recipe or thedeployhelper_keythat triggered the helper.placerinst: (entity) The entity that initiated the deployment.
DeployHelper:StopHelper()
- Description: Deactivates the helper. If it is currently active (i.e.,
delayis set), it clears thedelay, unregisters the component from periodic updates viainst:StopWallUpdatingComponent, and triggers theonenablehelpercallback (withfalse). - Parameters: None.
DeployHelper:OnWallUpdate()
- Description: This method is called periodically while the helper is active and registered with
inst:StartWallUpdatingComponent. It decrements the internaldelaycountdown. Whendelayreaches1or less, it callsStopHelperto deactivate the helper. - Parameters: None.