Page 1 of 1

Trigger Specific Dialogue From Script?

Posted: Tue Feb 01, 2022 3:05 pm
by PayasoPrince
Hello,

I reviewed the tutorial videos and wasn't able to find this.

I want to trigger a specific dialogue from a usable when a specific method is called on my player.

For example:

My player with a ProximitySelector is in range of a usable GameObject.
My player then calls the method:

Code: Select all

private void GetReactionFromNPC:
{
        ProximitySelector.CurrentUsable." Start a specific dialogue now"
}
How can I accomplish this? :?:

Re: Trigger Specific Dialogue From Script?

Posted: Tue Feb 01, 2022 4:01 pm
by Tony Li
Assuming I understand you correctly, I can suggest two ways to do that:

1. Put a Dialogue Actor on each NPC. Name each reaction conversation according to the Dialogue Actor's name plus " Reaction". For example, if the NPC is "Adam", then the conversation would be "Adam Reaction". Start it like this:

Code: Select all

string title = DialogueActor.GetActorName(ProximitySelector.CurrentUsable.transform) + " Reaction";
DialogueManager.StartConversation(title, this.transform, ProximitySelector.CurrentUsable.transform);

2. Or define a Boolean variable "Reaction" in your dialogue database. Add two Dialogue System Trigger components to the NPC. Configure the first one to start the NPC's normal conversation (if any). Set its Conditions > Lua Conditions to: Variable["Reaction"] ~= true. Configure the second Dialogue System Trigger to start the NPC's reaction conversation and run Lua code to set Reaction false. Set its Conditions > Lua Conditions to: Variable["Reaction"] == true. Start it like this:

Code: Select all

DialogueLua.SetVariable("Reaction", true);
ProximitySelector.UseCurrentSelection();

Re: Trigger Specific Dialogue From Script?

Posted: Tue Feb 01, 2022 10:06 pm
by PayasoPrince
Thanks, Tony!

I went with the first way you mentioned and it seems to be working. The only problem is, it's not applying the "Cinemachine Camera Priority On Dialogue Event" Virtual Camera that I have on the actor. :?

Re: Trigger Specific Dialogue From Script?

Posted: Tue Feb 01, 2022 10:24 pm
by PayasoPrince
More specifically, it's using the vcam that is on the Player. However, I need it to use the NPC's vcam.

Re: Trigger Specific Dialogue From Script?

Posted: Wed Feb 02, 2022 8:48 am
by Tony Li
Hi,

Make sure the correct GameObjects are being used for the characters. For example, if in the Dialogue Editor you've set the conversation's Actor to be the Player and the Conversant to be the NPC, then make sure to pass the player transform as the second parameter to DialogueManager.StartConversation and pass the NPC transform as the third parameter.

Both GameObjects will receive the dialogue event. If you want the NPC's vcam to take priority, set its Cinemachine Camera Priority On Dialogue Event priority to a higher value.

Re: Trigger Specific Dialogue From Script?

Posted: Wed Feb 02, 2022 10:57 am
by PayasoPrince
Oh, goodness. The issue was the third parameter. I was not passing the usables transform :oops:.

It's working wonderfully now, thanks!

Re: Trigger Specific Dialogue From Script?

Posted: Wed Feb 02, 2022 11:03 am
by Tony Li
Glad to help! :-)