diff --git a/NASB Voice Mod/Controllers/VoiceController.cs b/NASB Voice Mod/Controllers/VoiceController.cs index 5adf741..70dec57 100644 --- a/NASB Voice Mod/Controllers/VoiceController.cs +++ b/NASB Voice Mod/Controllers/VoiceController.cs @@ -11,15 +11,18 @@ namespace VoiceMod.Controllers class VoiceController : MonoBehaviour { private string agentId; + private GameAgent agent; private GameAgentStateMachine stateMachine; private Voicepack voicepack; private readonly Dictionary lookup = new Dictionary(); + private Dictionary stateIdDict; void Start() { - agentId = GetComponent()?.GameUniqueIdentifier; + agent = GetComponent(); + agentId = agent?.GameUniqueIdentifier; stateMachine = GetComponent(); - var stateIdDict = stateMachine.GetPrivateField>("stateIdDict"); + stateIdDict = stateMachine.GetPrivateField>("stateIdDict"); if (agentId == null || stateMachine == null || @@ -64,10 +67,20 @@ void Update() { if (lookup.TryGetValue(stateMachine.CurrentStateId, out var id)) { - voicepack.Play(id); + int entryId = stateIdDict["entrance"]; + if (stateMachine.CurrentStateId == entryId) + Invoke("PlayEntranceAudio", agent.playerIndex * 1.25f); + else voicepack.Play(id); } } stateLastFrame = stateMachine.CurrentStateId; } + + private void PlayEntranceAudio() + { + //All the checking and tryGets were done already. We _know_ this exists or the code wouldn't have gotten this far + string id = lookup[stateIdDict["entrance"]]; + voicepack.Play(id); + } } }