Page 1 of 1
Randomize PC responces
Posted: Sat May 18, 2019 4:31 pm
by hellwalker
Hi,
So I have a system where I have ~10 player responses and I want to randomly show only 3.
Since I have only 3 response buttons setup in response panel, that's not a problem, but the dialogue always shows first three responses. Is there an easy way to randomize link priorities for responses?
Thanks.
Re: Randomize PC responces
Posted: Sat May 18, 2019 11:17 pm
by Tony Li
There are a few ways you can do this.
The easiest way takes advantage of the fact that you've only set up 3 response buttons. If you shuffle the 10 responses first, the response menu will appear to randomly show 3 responses. It's actually provided all 10 responses, but since they're in a shuffled order, the first 3 are randomly chosen from the 10. To do this, add a script to the Dialogue Manager that has an
OnConversationResponseMenu method:
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class ShuffleResponses : MonoBehaviour
{
void OnConversationResponseMenu(Response[] responses)
{
if (responses.Length > 3) // If we have more than 3 responses, shuffle them.
{
int n = responses.Length; // Standard Fisher-Yates shuffle algorithm.
for (int i = 0; i < n; i++)
{
int r = i + Random.Range(0, n - i);
Response temp = responses[r];
responses[r] = responses[i];
responses[i] = temp;
}
}
}
}
Another approach is to use the Conditions field on the responses. Briefly, you'll randomly choose 3 unique numbers x, y, and z. Then set the Conditions on the responses so that only 3 responses of the 10 will equal x, y, or z. If you want to use this approach and would like more details, just let me know.
Re: Randomize PC responces
Posted: Fri May 24, 2019 9:29 pm
by hellwalker
Thank you! I think the combination of the two would be best for me. I only need to shuffle responses in specific cases. So maybe if I tag responses or conversation with certain field and shuffle only conversations with that field? Would this work?
Re: Randomize PC responces
Posted: Fri May 24, 2019 9:40 pm
by Tony Li
Yes, that would work. For example, you could add a Boolean field named "Shuffle" to the dialogue entry template, with a default value of false. When you want responses to be shuffled, on one or more of them set the field to true.
You could modify the OnConversationResponseMenu code above to first loop through all of the responses. If any of them have a Shuffle field that's set to true, shuffle the responses. Otherwise leave them as-is.