using { /UnrealEngine.com/Temporary/Diagnostics } # For printing debug messages using { /Fortnite.com/Devices } # To access Audio Players and Guards using { /Verse.org/Simulation } # Core simulation logic # This is our custom device. It will be placed in the level. # Think of this as the "Brain" for the barks. guard_bark_manager := class(concrete): # 1. REFERENCES # This is the Audio Player we want to control. # @editable means you can drag-and-drop an Audio Player into this slot in the editor. @editable BarkAudioPlayer: audio_player_device = audio_player_device{} # This is the Guard NPC we are listening to. # We link this in the editor to the specific guard. @editable TargetGuard: agent = agent{} # 2. STATE VARIABLES # IsInCooldown is like a "Talking" flag. # If true, the guard is already speaking, so we ignore new barks. # Think of this like a "Reload" state on a weapon; you can't shoot while reloading. var IsSpeaking: logic = false # 3. THE EVENT LISTENER # This function listens for the "Alerted" event from the Guard. # When the guard spots a player, this code runs. OnGuardAlerted: listenable(agent_alerted_event) = event(Guard: agent, Player: agent): # Check if the guard is the one who alerted, and if they aren't already talking. if (Guard == TargetGuard and IsSpeaking == false): # Set the flag to true. The guard is now "speaking". IsSpeaking = true # Play the audio. # We tell the Audio Player to play the "Alert" clip. BarkAudioPlayer.Play(AudioAsset = GetAlertAudioAsset()) # Wait for 2 seconds (simulating bark duration). # This is like a "Delay" device. await Delay(2.0) # Reset the flag. The guard stops "speaking". IsSpeaking = false # Helper function to get the audio asset. # In a real setup, you'd link these via @editable variables. # For this demo, we simulate getting the asset. GetAlertAudioAsset(): audio_asset = audio_asset{} # 4. SECOND EVENT: DAMAGE # Listen for when the guard takes damage. OnGuardDamaged: listenable(agent_damage_event) = event(Source: agent, Target: agent, Damage: float): # If the target is our guard and not currently talking... if (Target == TargetGuard and IsSpeaking == false): IsSpeaking = true # Play the "Hit" bark. BarkAudioPlayer.Play(AudioAsset = GetHitAudioAsset()) # Shorter delay for a hit sound. await Delay(0.5) IsSpeaking = false GetHitAudioAsset(): audio_asset = audio_asset{}