Page 1 of 1
Play dialouge once player takes damage
Posted: Thu Apr 08, 2021 1:57 pm
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 ?
Re: Play dialouge once player takes damage
Posted: Thu Apr 08, 2021 2:22 pm
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");
}
}
Re: Play dialouge once player takes damage
Posted: Thu Apr 08, 2021 2:41 pm
by soniclinkerman
Awesome! I figured I needed a script, and your example of one will be great for me to use. Thanks!
Re: Play dialouge once player takes damage
Posted: Thu Apr 08, 2021 2:46 pm
by Tony Li
Glad to help!
Re: Play dialouge once player takes damage
Posted: Thu Apr 08, 2021 4:57 pm
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.
Re: Play dialouge once player takes damage
Posted: Thu Apr 08, 2021 5:18 pm
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:
Re: Play dialouge once player takes damage
Posted: Thu Apr 08, 2021 5:24 pm
by soniclinkerman
Thank you so much Tony! Assigning the player's transform did the trick!
Re: Play dialouge once player takes damage
Posted: Thu Apr 08, 2021 7:41 pm
by Tony Li
Great!