Get Current Conversation Fields

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Janooba
Posts: 4
Joined: Tue Jan 05, 2021 1:03 am

Get Current Conversation Fields

Post by Janooba »

Heyo!

I'm currently working on a script that will manage freezing the player, as well as any viewmodel animations that may be needed at the start and end of a conversation (think pulling out a phone/putting it away)

I've added a custom field to the conversation in the database, but I have no idea how to actually get this in-script.

Here's what I got so far:

Code: Select all

public void OnConversationStart(Transform actor)
{
    bool freezePlayer = DialogueLua.GetConversationField(/* what do I put here */, "FreezePlayer").AsBool;

    if (freezePlayer)
        PlayerController.LockPlayer();

    PlayerController.I.HUDController.HideHUD();
}

public void OnConversationEnd(Transform actor)
{
    PlayerController.UnlockPlayer();
    PlayerController.I.HUDController.ShowHUD();
}
Image

Any help is appreciated. Thanks!
User avatar
Tony Li
Posts: 22159
Joined: Thu Jul 18, 2013 1:27 pm

Re: Get Current Conversation Fields

Post by Tony Li »

Hi,

It looks like you only want to freeze the player in specific conversations.

If you want to freeze the player in all player-involved conversations, you don't need a "Freeze" field. Just add a Dialogue System Events component to the player's GameObject and set up the OnConversationStart()/OnConversationEnd() events, or add a script to the player that has OnConversationStart() and OnConversationEnd() methods. Since it's on the player, they will only be invoked when the player is the conversation's primary actor or conversant.

If you only want to freeze the player in specific player-involved conversations, do the exact same thing -- except, in OnConversationStart(), look up the "Freeze" field by passing DialogueManager.lastConversationID to DialogueLua.GetConversationField:

Code: Select all

public void OnConversationStart(Transform actor)
{
    bool freezePlayer = DialogueLua.GetConversationField(DialogueManager.lastConversationID, "FreezePlayer").AsBool;

    if (freezePlayer)
        PlayerController.LockPlayer();

    PlayerController.I.HUDController.HideHUD();
}
Note: If you want to freeze the player in some conversations where the player is not the primary actor or conversant, move the script/Dialogue System Events component to the Dialogue Manager. Alternatively, hook into the DialogueManager.instance.conversationStarted/conversationEnded C# events.
Janooba
Posts: 4
Joined: Tue Jan 05, 2021 1:03 am

Re: Get Current Conversation Fields

Post by Janooba »

Hey! Thanks for the incredibly quick response. That's exactly what I needed. I couldn't find where to get the conversation's reference ID.

I kind of assumed "DialogueManager.lastConversationID" meant that the current active conversation wouldn't be referenced until it ended, given the name. But it's all good!

And yep, you got it, I only want to freeze the player for some conversations.
User avatar
Tony Li
Posts: 22159
Joined: Thu Jul 18, 2013 1:27 pm

Re: Get Current Conversation Fields

Post by Tony Li »

Glad to help!

DialogueManager.lastConversationID should really be called DialogueManager.lastConversationIDStarted, since it's the ID number twin to DialogueManager.lastConversationStarted, which is the title of the conversation. It uses lastConversationID to keep the name a bit shorter.
Post Reply