Moonstormstaticcatcher
Based on game build 714014 | Last updated: 2026-03-03
Overview
Moonstormstaticcatcher manages the logic for capturing moonstorm static charges. It maintains a reference to a current target entity and performs capture operations using proximity and capturability checks. It coordinates with the moonstormstaticcapturable component on target entities to register targeting, untargeting, and successful capture events.
Usage example
local inst = CreateEntity()
inst:AddComponent("moonstormstaticcatcher")
-- Set a custom callback to run on successful capture
inst.components.moonstormstaticcatcher:SetOnCaughtFn(function(catcher, doer)
print("Static caught by", doer and doer:GetDebugName())
end)
-- Attempt to target a capturable entity
local target = GetSomeCapturableEntity()
if target then
inst.components.moonstormstaticcatcher:OnTarget(target)
end
-- Attempt to capture the targeted static charge
local success, reason = inst.components.moonstormstaticcatcher:Catch(target, inst)
Dependencies & tags
Components used: moonstormstaticcapturable
Tags: None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | GEntity | nil (assigned in constructor) | The entity instance that owns this component. |
target | GEntity? | nil | The currently targeted capturable entity. |
oncaughtfn | function? | nil | Optional callback invoked when a catch succeeds. |
Main functions
OnRemoveFromEntity()
- Description: Automatically called when the component is removed from its entity. Ensures any active target is properly untargeted.
- Parameters: None.
- Returns: Nothing.
SetOnCaughtFn(fn)
- Description: Assigns a callback function to be executed on successful static capture.
- Parameters:
fn(function) - callback taking two arguments:(catcher_inst, doer_inst). - Returns: Nothing.
Catch(target, doer)
- Description: Attempts to capture the given target, validating proximity and capturability. On success, notifies the target's
moonstormstaticcapturablecomponent and triggers theoncaughtfncallback. - Parameters:
target(GEntity) — the entity to capture (expected to havemoonstormstaticcapturable).doer(GEntity) — the entity performing the catch (usually the owner of this component).
- Returns:
(true)— if capture succeeded.(false, reason)— if capture failed ("MISSED"for invalid target, distance, or disabled capturable state).
- Error states: Returns early with
("MISSED")if:target:IsValid()isfalse,doeris not within1 + doer:GetPhysicsRadius(0) + 0.2units oftarget, ortarget.components.moonstormstaticcapturableis missing or not enabled.
OnTarget(target)
- Description: Begins targeting a capturable entity. Clears any previous target before setting a new one. Registers this component as a targeter on the target's
moonstormstaticcapturablecomponent. - Parameters:
target(GEntity) — the entity to target. - Returns: Nothing.
- Error states: Does nothing if
targetis invalid or lacksmoonstormstaticcapturable. No-op iftargetis unchanged.
OnUntarget(target)
- Description: Ends targeting of the current or specified entity. Unregisters this component from the target's
moonstormstaticcapturable. - Parameters:
target(GEntity?) — optional specific target to untarget; if omitted, untargets the storedself.target. - Returns: Nothing.
- Error states: Does nothing if no active target is set or
targetdoes not match.
Events & listeners
- Listens to: None identified.
- Pushes: None identified.
(Note: Events are handled via the target'smoonstormstaticcapturablecomponent; see that component's documentation formoonstormstaticcapturable_targetedandmoonstormstaticcapturable_untargeted.)