Recipescanner
Overview
The Recipescanner component is attached to entities that act as scanning devices (e.g., the Scanning Station). When a target is scanned, it resolves the corresponding recipe, validates unlock conditions, unlocks the recipe for the doer if possible, and triggers associated events. It integrates with the builder system and enforces recipe unlock logic, including restrictions like nounlock, no_deconstruction, and builder capacity.
Dependencies & Tags
- Adds the
"recipescanner"tag to the entity on initialization. - Removes the
"recipescanner"tag when the component is removed from the entity. - Relies on the following components being present on relevant entities:
doermust have a"builder"component.targetmust support"NOCLICK"tag and may defineSCANNABLE_RECIPENAMEor rely ontarget.prefab.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | — | Reference to the entity the component is attached to (set in constructor). |
onscanned | function | nil | Optional callback function invoked after a successful scan; set via SetOnScannedFn. |
Main Functions
SetOnScannedFn(fn)
- Description: Sets an optional callback function to be invoked whenever a scan operation completes successfully.
- Parameters:
fn(function): A function that accepts four arguments:scanner(the scanning entity),target(the scanned entity),doer(the player/entity performing the scan), andrecipe_name(string).
Scan(target, doer)
- Description: Attempts to scan a
targetentity and unlock its corresponding recipe for thedoer. Returns a boolean indicating success, and optionally a reason string on failure (e.g.,"CANTLEARN","KNOWN"). - Parameters:
target(Entity): The entity being scanned (must be a valid scannable item).doer(Entity): The entity performing the scan (must have a"builder"component).
- Returns:
success(boolean):trueif the recipe was unlocked,falseotherwise.reason(string, optional): A string explaining why the scan failed ("CANTLEARN"or"KNOWN").
Events & Listeners
- Pushes:
"onrecipescanned"on thetargetentity with payload{ scanner = self.inst, doer = doer, recipe = recipe.name }after a successful scan. - No internal event listeners are registered—the component does not listen for any events via
inst:ListenForEvent.