using { /Fortnite.com/Devices } using { /UnrealEngine.com/Temporary/Diagnostics } # This is our custom device blueprint. # Think of it as a "Smart Music Remote" that we place in the level. combat_music_switch := class(creative_device): # @editable means you can change these settings in the editor panel. # It's like the "dials" on a radio. # The Guard Spawner that triggers the change. @editable EnemySpawner: guard_spawner_device = guard_spawner_device{} # The Music Manager we want to control. @editable MusicController: music_manager_device = music_manager_device{} # This is our "Light Switch" variable. # It starts as False (Calm Mode). is_panic_mode: bool = false # This function runs when the device is first placed in the world. # It's like the "Power On" button for your code. OnBegin(): void = # Subscribe to the spawner's "Spawned" event. # This means: "Hey Spawner, tell me every time you make a new enemy." EnemySpawner.SpawnedEvent.Subscribe(SpawnHandler) # This is the function that runs when the event happens. # 'spawner' is the specific spawner that just made an enemy. SpawnHandler := func(spawner: guard_spawner_device): void = # Toggle our light switch. # If it was False, it becomes True. If True, it becomes False. is_panic_mode = !is_panic_mode if (is_panic_mode): # PANIC MODE ON # Switch to A Minor (scary) and speed up the tempo. # We use SetKey and SetTempo to change the global audio state. MusicController.SetKey(MusicKey.A_Minor) MusicController.SetTempo(120.0) # Faster beats! Print("PANIC MODE ACTIVATED: Music is now SCARY.") else: # CALM MODE ON # Switch back to C Major (safe) and slow down. MusicController.SetKey(MusicKey.C_Major) MusicController.SetTempo(80.0) # Slow, chill beats. Print("CALM MODE: Music is now CHILL.")