How can I prevent characters within a group from repeating the same dialogue?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
ds2497
Posts: 55
Joined: Wed Jun 14, 2023 2:13 am

How can I prevent characters within a group from repeating the same dialogue?

Post by ds2497 »

Hi there!

I've been working on a scenario for two days, but I haven't been able to make it work. I believe this is a common situation in games, here is the scenario:

There are three soldiers, A, B, and C, who share a secret dialogue. The player will talk to them and gather information, but only the last NPC will provide vital information. Regardless of the order of conversation, the player will always receive Pointless Info 1, Pointless Info 2, and Vital Info. In other words, if the player speaks to the NPCs in the order of A => B => C, soldier C will provide the vital information necessary for the quest. If the player speaks to the NPCs in the order of C => A => B, then soldier B will give the vital information. In addition, the player cannot talk to the same NPC three times to obtain the vital information.

I've tried using custom Lua, quest counter(I have Quest Machine in my project) and writing my own code to keep track of the NPCs the player has talked to, but I haven't had any luck. I'm wondering if you could recommend an approach to achieve this? How should I setup the conditions?

Thanks!
User avatar
Tony Li
Posts: 22130
Joined: Thu Jul 18, 2013 1:27 pm

Re: How can I prevent characters within a group from repeating the same dialogue?

Post by Tony Li »

Hi,

Will all 3 characters share the same lines of dialogue? If so, you can make them share the same conversation. To use different actors for the same conversation, see: Character GameObject Assignments

If that's what you're looking for, let me know. I can put together a small example scene for you. It would use DS variables to remember that an actor has said A, B, or C lines.
User avatar
ds2497
Posts: 55
Joined: Wed Jun 14, 2023 2:13 am

Re: How can I prevent characters within a group from repeating the same dialogue?

Post by ds2497 »

Yes, three characters share the same dialogue named "Secret." For the "Secret" dialogue, I have set the "Common Actor" for the Actor field, while the NPCs' Actor fields are set up as "Soldier A," "Soldier B," and "Soldier C."

This is likely a logical problem. If you could provide me with a demo, it would be very helpful!
User avatar
ds2497
Posts: 55
Joined: Wed Jun 14, 2023 2:13 am

Re: How can I prevent characters within a group from repeating the same dialogue?

Post by ds2497 »

Hi Tony,

Thanks for providing the example scene! I just had a look at it and I'm wondering what would happen if the player keeps talking to the same soldier? This is one problem I'm trying to solve. From my understanding, the dialogue would need to keep track of which soldiers have already responded to the player, and only then can it prevent the player from speaking to the same actor again.

Please let me know if my understanding is incorrect. Thank you!
User avatar
Tony Li
Posts: 22130
Joined: Thu Jul 18, 2013 1:27 pm

Re: How can I prevent characters within a group from repeating the same dialogue?

Post by Tony Li »

Hi,

Oh, sorry, I misunderstood. I thought the player could keep speaking to the same actor to get more info. If they have to speak to a different actor each time, you can use variables to keep track of which actors the player has already spoken to. See: How To: Run a Conversation Only Once
User avatar
ds2497
Posts: 55
Joined: Wed Jun 14, 2023 2:13 am

Re: How can I prevent characters within a group from repeating the same dialogue?

Post by ds2497 »

Hi Tony,

Thank you for your reply!

In order to address this issue using variables, I believe it requires something like "Talked{{CurrentActor}}" that can access the current actor's ID and incorporate it into the variable's name. If I were to use a variable like "TalkedNpc", it would lead to the second soldier considering himself already spoken to the player after the player has spoken to the first soldier. This occurs because they share the same dialogue.

Fortunately, I managed to resolve the problem by utilizing a quest counter and a custom Lua script. I will provide the approach here for anyone else encountering a similar issue. :D

For the custom Lua script:
Image

For dialogue conditions and scripts:
Image

For the second node, the condition counter would be 1 instead of 0, and the script counter would be 2 instead of 1. As for the third soldier, the counter would also increase by 1.

Thank you very much for your help!
User avatar
Tony Li
Posts: 22130
Joined: Thu Jul 18, 2013 1:27 pm

Re: How can I prevent characters within a group from repeating the same dialogue?

Post by Tony Li »

Hi,

Thanks for sharing your solution!

You could also use the Variable["ConversantIndex"] variable. When talking to Soldier A, its value will be "Soldier_A". When talking to Soldier B, its values will be "Soldier_B".

Then you can define variables "Talked_To_Soldier_A" and "Talked_To_Soldier_B".

In your conversation, you can set these variables like this:
  • Script: Variable["Talked_To_" .. Variable["ConversantIndex"]] = true
When talking to Soldier A, this is equivalent to:
  • Script: Variable["Talked_To_Soldier_A"] = true
Similarly, you can check if the player has talked to Soldier A like this:
  • Conditions: Variable["Talked_To_" .. Variable["ConversantIndex"]] == true
User avatar
ds2497
Posts: 55
Joined: Wed Jun 14, 2023 2:13 am

Re: How can I prevent characters within a group from repeating the same dialogue?

Post by ds2497 »

Got it, thanks for sharing!
Post Reply