Dynamicmusic
Based on game build 722832 | Last updated: 2026-04-17
Overview
DynamicMusic controls adaptive background music playback for player entities. It responds to environmental conditions (season, cave/forest, ruins, lunar island), player activities (working, building, fighting), and special events (boss fights, mini-games, festivals). The component manages multiple music layers including busy themes, danger themes, epic fight music, and triggered event music. It uses the world's focal point sound emitter and listens to numerous player events to determine appropriate audio playback. Note: This component has no public methods on self — all functionality is event-driven via PushEvent calls.
Usage example
local inst = CreateEntity()
inst:AddComponent("dynamicmusic")
-- Music is controlled via events, not direct method calls
inst:PushEvent("playeractivated", player)
inst:PushEvent("enabledynamicmusic", true)
-- Trigger specific music themes via events
player:PushEvent("playracemusic")
player:PushEvent("playcarnivalmusic", { is_game_active = true })
player:PushEvent("triggeredevent", { name = "dragonfly", level = 1, duration = 60 })
Dependencies & tags
External dependencies:
TheFocalPoint.SoundEmitter-- global sound emitter for music playbackTheSim:FindEntities()-- entity searching for nearby threats and pirates
Components used:
areaaware-- checks if player is in specific areas viaCurrentlyInTag()combat-- retrieves combat target for danger music detectionreplica.combat-- network-replicated combat component for target accessreplica.follower-- checks follower relationships for music exclusion
Tags:
cave-- checked on inst to determine cave vs forest musicNightmare-- checked via areaaware for ruins musiclunacyarea-- checked via areaaware for lunar island musicepic-- marks entities that trigger epic fight musicnoepicmusic-- excludes entities from triggering epic musicprey,hostile-- checked for danger music eligibilityattack,working-- checked on player for action-based musiccrewmember-- marks pirate entities for pirate musicshadow,shadowchesspiece,smolder,thorny,nodangermusic-- exclude from danger triggersfeasting-- checked for feast music activationbird,butterfly,shadowminion,abigail,possessedbody,smashable,wall,engineering,smoldering,veggie-- various exclusion tags for danger music
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | entity | -- | The entity instance that owns this component (assigned from constructor parameter). |
Internal State
These are private local variables, not part of the public API:
| Variable | Type | Initial Value | Description |
|---|---|---|---|
_isenabled | boolean | true | Whether dynamic music is currently enabled. |
_busytask | task | nil | Scheduled task for busy music timeout. |
_dangertask | task | nil | Scheduled task for danger music timeout. |
_pirates_near | task | nil | Periodic task for checking nearby pirates. |
_triggeredlevel | number | nil | Current level of triggered danger music. |
_isday | boolean | nil | Whether the current world phase is day. |
_busytheme | number | nil | Current busy music theme identifier. |
_extendtime | number | nil | Timestamp for extending music duration (set to 0 in StartSoundEmitter). |
_soundemitter | SoundEmitter | nil | Reference to the global sound emitter. |
_activatedplayer | entity | nil | Currently activated player entity. |
_hasinspirationbuff | number | nil | Inspiration buff state (0 or 1). |
Main functions
ShouldPlayDangerMusic(player, target)
- Description: Global function that determines if danger music should play based on target's tags and follower relationship. Returns
falseif target has no combat component, is prey without hostile tag, has exclusion tags (bird, butterfly, shadow, etc.), or is a shadow minion/abigail/possessed body that is not following the player. - Parameters:
player-- entity instance (the player checking for danger)target-- entity instance (the potential threat target)
- Returns: boolean --
trueif danger music should play,falseotherwise - Error states: Errors if
target.replica.combatis accessed whentarget.replicais nil (no guard present).
Events & listeners
Listens to (on component entity):
playeractivated-- initializes player listeners and sound emitter for the activated playerplayerdeactivated-- removes player listeners and cleans up sound emitterenabledynamicmusic-- enables or disables dynamic music functionality
Listens to (on player entity):
buildsuccess-- extends busy music durationgotnewitem-- extends busy music durationperformaction-- checks for attack or work actions to trigger appropriate musicattacked-- triggers danger music when attacked by valid threatsgoinsane-- plays insanity stinger soundgoenlightened-- plays enlightenment stinger soundtriggeredevent-- starts triggered danger music for boss fights and special eventsplayboatmusic-- starts ocean sailing musicisfeasting-- starts feast music during winter's feastplayracemusic-- starts Year of the Carrat race musicplayhermitmusic-- starts hermit island musicplaytrainingmusic-- starts training mini-game musicplaypiratesmusic-- starts pirate proximity music systemplayfarmingmusic-- starts farming musichasinspirationbuff-- updates inspiration buff intensity parameterplaycarnivalmusic-- starts summer carnival ambient or mini-game musicstageplaymusic-- starts stage play mood music (happy, mysterious, dramatic, confession)playpillowfightmusic-- starts Year of the Carrat pillow fight musicplayrideofthevalkyrie-- starts Wigfrid's Ride of the Valkyrie musicplayboatracemusic-- starts boat race musicplaybalatromusic-- starts Balatro mini-game musicwx_performedspinaction-- triggers danger or busy music based on WX-78 spin action
Watches world state:
phase-- triggers dawn/dusk stinger sounds on phase changesseason-- resets busy theme on season change for appropriate seasonal music
Pushes: None identified