Skip to main content

Minigame

Overview

This component manages the core behavior of a minigame entity within the Entity Component System. It handles activation/deactivation cycles, dynamically assigns spectators and participants based on proximity, tracks the current state (intro, playing, outro), and maintains an "excitement" timer used for UI or gameplay feedback. It operates at the world level by scanning for nearby entities and managing their roles in the minigame.

Dependencies & Tags

  • Adds minigame_spectator component to entities entering the spectator radius.
  • Adds minigame_participator component to entities entering the participator radius.
  • Relies on presence of:
    • Transform component on its host entity (for position).
    • follower component (optional, to filter out followers during spectator detection).
  • Tags used for entity filtering:
    • Spectators: Cannot have tags "monster" or "player"; must have tag "character" (one-of).
    • Participators: Must have tag "player".

Properties

PropertyTypeDefault ValueDescription
instEntityReference to the host entity.
activebooleanfalseWhether the minigame is currently active.
activate_fnfunction?nilOptional callback invoked when the minigame activates.
deactivate_fnfunction?nilOptional callback invoked when the minigame deactivates.
spectator_distnumber20Radius (units) within which eligible entities become spectators.
participator_distnumber20Radius (units) within which eligible players become participants.
watchdist_minnumberTUNING.MINIGAME_CROWD_DIST_MINMinimum viewing distance threshold (used elsewhere, not directly in this component).
watchdist_targetnumberTUNING.MINIGAME_CROWD_DIST_TARGETTarget viewing distance threshold.
watchdist_maxnumberTUNING.MINIGAME_CROWD_DIST_MAXMaximum viewing distance threshold.
gametypestring"unknown"Identifier for the minigame type (set externally).
excitement_timenumber0Timestamp of the last excitement event.
excitement_delaynumber5Time window (seconds) after excitement_time during which IsExciting() returns true.
statestring"intro"Current state: "intro", "playing", or "outro".
active_pulsePeriodicTask?nilActive repeating task triggered during gameplay.

Main Functions

OnRemoveFromEntity()

  • Description: Ensures the minigame is deactivated when the host entity is removed from the world.
  • Parameters: None.

SetOnActivatedFn(fn)

  • Description: Registers a callback function to be executed upon activation.
  • Parameters:
    • fn (function): A function accepting a single Entity argument.

SetOnDeactivatedFn(fn)

  • Description: Registers a callback function to be executed upon deactivation.
  • Parameters:
    • fn (function): A function accepting a single Entity argument.

IsActive()

  • Description: Returns whether the minigame is currently active.
  • Parameters: None.

Activate()

  • Description: Activates the minigame, cancels any prior activation, triggers the activation callback, and starts a repeating DoActivePulse task every 0.75 seconds.
  • Parameters: None.

Deactivate()

  • Description: Deactivates the minigame, cancels the periodic pulse task (if any), and pushes the "ms_minigamedeactivated" event. Invokes the deactivation callback if registered.
  • Parameters: None.

AddSpectator(spectator)

  • Description: Ensures the given entity has the minigame_spectator component and assigns this minigame as its watched minigame.
  • Parameters:
    • spectator (Entity): The entity to register as a spectator.

AddParticipator(participator, notimeout)

  • Description: Ensures the given entity has the minigame_participator component, sets this minigame as its active minigame, and optionally sets the notimeout flag.
  • Parameters:
    • participator (Entity): The entity to register as a participant.
    • notimeout (boolean, optional): If true, disables timeout for this participant.

DoActivePulse()

  • Description: Scans for eligible spectators and participants within configured radii using TheSim:FindEntities, then adds them to the minigame. Runs automatically at intervals while active.
  • Parameters: None.

SetIsIntro(), GetIsIntro()

  • Description: Sets/gets the state to "intro".
  • Parameters: None.

SetIsPlaying(), GetIsPlaying()

  • Description: Sets/gets the state to "playing".
  • Parameters: None.

SetIsOutro(), GetIsOutro()

  • Description: Sets/gets the state to "outro".
  • Parameters: None.

RecordExcitement()

  • Description: Updates excitement_time to the current game time.
  • Parameters: None.

TimeSinceLastExcitement()

  • Description: Returns the time elapsed (in seconds) since RecordExcitement was last called.
  • Parameters: None.

IsExciting()

  • Description: Returns true if TimeSinceLastExcitement() is within excitement_delay seconds.
  • Parameters: None.

GetDebugString()

  • Description: Returns a formatted string with current active/excitement status for debugging.
  • Parameters: None.

Events & Listeners

  • Listens for: None.
  • Pushes:
    • "ms_minigamedeactivated": Sent during Deactivate() when the minigame was previously active.