Page 1 of 1
Scripted response on timeout
Posted: Mon Jul 12, 2021 6:09 am
by ProvencalG
Hi,
I'm implementing a mechanic in my game where some dialogues are timed and on timeout it triggers a specific response.
Maybe I can use the "low", "below normal" to "high" parameter to define which response will be triggered.
But how do I trigger it ? I know I have to set timeout to custom, and use the OnConversationTimeout() method. But how do I trigger the response ?
Thanks.
Re: Scripted response on timeout
Posted: Mon Jul 12, 2021 8:55 am
by Tony Li
Hi,
You probably don't want to use priority levels (BelowNormal, AboveNormal, etc.) because only the highest priority level with available nodes will be used.
In your OnConversationTimeout() method, you can examine the current list of responses (DialogueManager.currentConversationState.pcResponses). You could add a custom field to your dialogue entry template to specify what to do on timeout. If the field is set, you can use its content to decide what to do.
Re: Scripted response on timeout
Posted: Mon Jul 12, 2021 9:34 am
by ProvencalG
Ok thanks, so with a custom field on my response nodes I can specify which one will be triggered on timeout.
But how do I trigger the response?
For example, if I have a character that says to the player: "Give me your money now!"
The player can answer 1: "Here, that's all I have", 2: "My... my money?", 3: "Or I can alert the cops just over there"
He has 5 seconds and on time out, the game automatically selects the response 2: "My... my money?".
So on the node "Give me your money now!" I can set a bool "isTimed" true, and on 2: "My... my money?" I can set the custom field that says it's the time out response.
Then in my script, I check if the bool is timed and if it is I fire some animations (to let the player know that this is timed) and on timeout check for the custom field and activate this response and some more animations (to show him he wasn't quick enough and what response got triggered).
Re: Scripted response on timeout
Posted: Mon Jul 12, 2021 12:59 pm
by Tony Li
Hi,
Set "isTimed" on "My... my money?".
In the "Give me your money now!" node, add
SetTimeout(5) to the Sequence field. To make the sequence also play the Dialogue Manager's Default Sequence, also include {{default}}. Example:
- Sequence: SetTimeout(5); {{default}}
In OnConversationTimeout() (
example), loop through the responses to identify the node whose "isTime" field is true:
Code: Select all
void OnConversationTimeout()
{
foreach (Response response in DialogueManager.currentConversationState.pcResponses)
{
if (Field.LookupBool(response.destinationEntry.fields, "isTimed"))
{
DialogueManager.standardDialogueUI.OnClick(response);
return;
}
}
}
Re: Scripted response on timeout
Posted: Tue Jul 13, 2021 10:36 am
by ProvencalG
Thanks again for the help.
So the "DialogueManager.standardDialogueUI.OnClick(response);" is not available for me, it does not find standardDialogueUI, and if I put it like "DialogueManager.DialogueUI.OnClick()" it does not find any OnClick() method.
Also, can I access the timeout value ? And the time passed ? So I can know how much time is left before timeout, so I can time stuff.
Re: Scripted response on timeout
Posted: Tue Jul 13, 2021 10:38 am
by ProvencalG
Never mind the first issue: I wrote
"(DialogueManager.dialogueUI as StandardDialogueUI).OnClick(responseToTrigger);"
instead and it seems to works.
Re: Scripted response on timeout
Posted: Tue Jul 13, 2021 11:34 am
by Tony Li
Hi,
The DialogueManager.standardDialogueUI property was added in a recent version. If you're using an older version, this property won't be present, so the way you did it is perfect.
ProvencalG wrote: ↑Tue Jul 13, 2021 10:36 amAlso, can I access the timeout value ? And the time passed ? So I can know how much time is left before timeout, so I can time stuff.
DialogueManager.displaySettings.GetResponseTimeout() returns the timeout value.
The menu's current time passed is handled internally. But you can check the timer's slider value:
Code: Select all
var ui = DialogueManager.dialogueUI as StandardDialogueUI; //(Use standardDialogueUI property in v2.2.18+)
var timerSlider = ui.conversationUIElements.defaultMenuPanel.timerSlider;