Play dialouge once player takes damage

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
soniclinkerman
Posts: 82
Joined: Wed Mar 31, 2021 6:48 pm

Play dialouge once player takes damage

Post by soniclinkerman »

Hey!

I want a specific dialogue to play ONLY if I take some damage. It's meant to only play once and never again. Is there a way to do this ?
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Play dialouge once player takes damage

Post by Tony Li »

Hi,

Here's how to play a conversation only once: How To: Run a Conversation Only Once

To play it when the player first takes damage, you'll need some kind of script or event that runs when the player takes damage. You can either set up a Dialogue System Trigger and manually call its OnUse() method, or call DialogueManager.StartConversation() directly. Example:

Code: Select all

using PixelCrushers.DialogueSystem;
...
public void TakeDamage(int damage)
{
    health -= damage;
    
    if (DialogueLua.GetVariable("hasPlayedDamageDialogue").asBool == false)
    {
        DialogueLua.SetVariable("hasPlayedDamageDialogue", true);
        DialogueManager.StartConversation("You Took Damage");
    }
}
soniclinkerman
Posts: 82
Joined: Wed Mar 31, 2021 6:48 pm

Re: Play dialouge once player takes damage

Post by soniclinkerman »

Awesome! I figured I needed a script, and your example of one will be great for me to use. Thanks!
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Play dialouge once player takes damage

Post by Tony Li »

Glad to help!
soniclinkerman
Posts: 82
Joined: Wed Mar 31, 2021 6:48 pm

Re: Play dialouge once player takes damage

Post by soniclinkerman »

Hey Sorry again, but I was wondering why the "Onconversation" end doesn't run when I run a dialogue through script?

On the start of a conversation, I have a function that makes the player movement false, but for some reason, this function doesn't run at all when I activate dialogue via code.
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Play dialouge once player takes damage

Post by Tony Li »

Hi,

OnConversationStart and OnConversationEnd (and the related Dialogue System Events component) only run on the Dialogue Manager GameObject and the GameObjects that are being used as the conversation's current actor and conversant.

If you start a conversation through script, pass the GameObjects:

Code: Select all

DialogueManager.StartConversation("You Took Damage", playerTransform);
or add Dialogue Actor components to them so they can register themselves as being the GameObjects associated with the actors in the database.

More info:
soniclinkerman
Posts: 82
Joined: Wed Mar 31, 2021 6:48 pm

Re: Play dialouge once player takes damage

Post by soniclinkerman »

Thank you so much Tony! Assigning the player's transform did the trick!
User avatar
Tony Li
Posts: 22037
Joined: Thu Jul 18, 2013 1:27 pm

Re: Play dialouge once player takes damage

Post by Tony Li »

Great!
Post Reply