Beargerspawner
Overview
The Beargerspawner component is a master-simulation-only manager responsible for controlling the appearance of the Bearger giant. It handles the entire lifecycle of Bearger spawning during the Autumn season, including determining the number of Beargers to spawn based on chances, managing a countdown timer, selecting an eligible player to spawn near, and issuing warnings (sounds and character speech) as the spawn time approaches. It also tracks active Beargers and persists its state across game sessions.
Dependencies & Tags
None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | inst | A reference to the entity instance this component is attached to. |
Main Functions
SetSecondBeargerChance(chance)
- Description: Deprecated function. Intended to set the spawn chance for a second Bearger.
- Parameters:
chance(number): The desired spawn chance.
SetFirstBeargerChance(chance)
- Description: Deprecated function. Intended to set the spawn chance for the first Bearger.
- Parameters:
chance(number): The desired spawn chance.
OnPostInit()
- Description: Initializes the component after the world has loaded. It calculates the base spawn delay from tuning values and sets up the world timer used to trigger Bearger spawns. If the component was loaded from a save with a pre-existing timer, it resumes that timer.
- Parameters: None.
DoWarningSpeech(_targetplayer)
- Description: Triggers the character-specific warning speech ("That sounded big!") for the target player and any other players within a large radius. The speech is delivered after a short, random delay.
- Parameters:
_targetplayer(Player): The player entity chosen as the center of the warning event.
DoWarningSound(_targetplayer)
- Description: Spawns a
beargerwarning_lvlprefab at the target player's location. The level of the warning (1-4) depends on the time remaining until the spawn, creating an escalating sense of dread. - Parameters:
_targetplayer(Player): The player entity chosen as the center of the warning event.
OnUpdate(dt)
- Description: The main update loop for the component. It checks the spawn timer and manages the warning state. When the timer drops below the warning duration threshold, it selects a target player and begins issuing periodic sound and speech warnings until the timer expires and the Bearger spawns.
- Parameters:
dt(number): The time elapsed since the last update.
LongUpdate(dt)
- Description: A less frequently called update function that simply calls
OnUpdate(dt). - Parameters:
dt(number): The time elapsed since the last long update.
OnSave()
- Description: Gathers the component's state into a data table for saving. This includes the warning status, number of Beargers to spawn, last kill day, number already spawned, and references to any currently active Beargers.
- Parameters: None.
OnLoad(data)
- Description: Populates the component's state from a saved data table.
- Parameters:
data(table): The saved data table generated byOnSave.
LoadPostPass(newents, savedata)
- Description: Called after all entities have been loaded. It resolves saved GUIDs for active Beargers into entity references and resumes the spawn timer if conditions are still valid.
- Parameters:
newents(table): A map of saved GUIDs to newly loaded entity instances.savedata(table): The original saved data for this component.
GetDebugString()
- Description: Returns a formatted string containing the current status of the spawner, such as time until spawn, warning state, and the number of active Beargers. Used for debugging.
- Parameters: None.
SummonMonster(player)
- Description: A debug function that forces a Bearger to spawn soon. It sets the spawn timer to 10 seconds and activates the component's update loop.
- Parameters:
player(Player): The player to target for the spawn.
Events & Listeners
This component listens for the following world events:
ms_playerjoined: When a player joins the server, they are added to the list of potential targets for a Bearger spawn.ms_playerleft: When a player leaves, they are removed from the potential target list. If they were the current target, a new one is picked.seasontick: On each new day, this is used to check if it's Autumn and time to roll the chances for Bearger spawns for the season.beargerremoved: When a Bearger entity is removed from the world for any reason, it is removed from the internal list of active Beargers.beargerkilled: When a Bearger is killed, it is removed from the active list, the spawn timer is stopped, and the current day is recorded as the last kill day to enforce a cooldown period.