Page 1 of 1

Get Current Conversation Fields

Posted: Mon Aug 02, 2021 5:44 pm
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!

Re: Get Current Conversation Fields

Posted: Mon Aug 02, 2021 6:06 pm
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.

Re: Get Current Conversation Fields

Posted: Mon Aug 02, 2021 6:13 pm
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.

Re: Get Current Conversation Fields

Posted: Mon Aug 02, 2021 6:20 pm
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.