Minigame Spectator
Overview
This component enables an entity (typically a spectator, such as a non-player or observer) to register interest in a specific minigame. It manages cleanup logic by removing itself from the entity when the watched minigame ends or is deactivated, and prevents the entity from attacking players while the minigame is active.
Dependencies & Tags
- Requires
inst.components.combat(if present) to drop combat targets. - No tags are added or removed.
- Listens to events on the watched minigame object:
"onremove"and"ms_minigamedeactivated".
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | (passed in constructor) | Reference to the entity the component is attached to. |
minigame | Entity? | nil | Reference to the minigame entity currently being watched; nil if none. |
onminigameover | function | (lambda defined in _ctor) | Callback function that removes the component from inst when invoked. |
Main Functions
MinigameSpectator:OnRemoveFromEntity()
- Description: Cleans up event listeners attached to the minigame before the component is fully removed from the entity.
- Parameters: None.
MinigameSpectator:SetWatchingMinigame(minigame)
- Description: Sets the given
minigameas the active minigame to watch. Registers event listeners for minigame termination and drops the entity's combat target if it is a player. - Parameters:
minigame(Entity): The minigame entity to watch. Must be valid and not already set (the method is idempotent only ifminigameisnil).
MinigameSpectator:GetMinigame()
- Description: Returns the currently watched minigame entity, or
nilif none. - Parameters: None.
MinigameSpectator:GetDebugString()
- Description: Returns a human-readable debug string indicating whether a minigame is being watched.
- Parameters: None.
Events & Listeners
- Listens for:
"onremove"on the minigame entity → triggersonminigameover."ms_minigamedeactivated"on the minigame entity → triggersonminigameover.
- Triggers:
- None (does not push events).