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<private> 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):
Verse Library
verse
01 Standalone
Listens for guard alert events to trigger audio barks while preventing overlapping speech.
verse-library/script-that-handles-barks-from-guards/01-standalone.verse
Sign in free to read the full source 🌴
This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.