Page 1 of 1
Quest progression event
Posted: Sat Jan 30, 2021 12:59 pm
by Haytam95
Hi!
I'm using Dialogue System quest system in order to make my level progress. Each level have some quests that are active and each sub state should perform some changes to the level.
For example, at the first level, the character spawns in first view perspective and have restricted movement (Also the bed where is have the collider disabled):
(This is, Quest A state 1 for example)
When the character interacts with a specific object, then I execute the Lua code to complete state 1 and set the state 2 as active. In state two, the character view should be third person, have free movement and the bed collision be re-enabled.
(This is Quest A state 2)
So the question: Is there any event that tells me when a Quest entry is updated?
Thank you (And thank you too for helping me with my rewired question, I didn't wanted to answer there to avoid bump
)
Re: Quest progression
Posted: Sat Jan 30, 2021 3:52 pm
by Tony Li
Hi,
If you want everything in one script, you could add a script to the Dialogue Manager that has an
OnQuestStateChange or OnQuestSEntryStateChange method. Example:
Code: Select all
void OnQuestStateChange(string quest)
{
switch (quest)
{
case "Bedroom Quest":
if (QuestLog.GetQuestEntryState(quest, 1) == QuestState.Active)
{
// Set first person with restricted movement.
}
else if (QuestLog.GetQuestEntryState(quest, 2) == QuestState.Active)
{
// Set third person; enable bed collider.
}
break;
}
}
Or, if you don't want to put a script on the Dialogue Manager, assign a delegate to QuestLog.SetQuestEntryStateOverride. Example:
Code: Select all
QuestLog.SetQuestEntryStateOverride = OnSetQuestEntryState;
void OnSetQuestEntryState(string quest, int entry, string stateString)
{
var state = QuestLog.StringToState(stateString);
QuestLog.DefaultSetQuestEntryState(quest, entry, state);
switch (quest)
{
case "Bedroom Quest":
// similar to example above.
break;
}
}
Re: Quest progression event
Posted: Sat Jan 30, 2021 3:55 pm
by Haytam95
Tony that's great! The second example is exactly what I need (as Dialogue System manager is in a singleton)
I'll try it now and see how does that work!! Thank you
Re: Quest progression event
Posted: Sat Jan 30, 2021 4:04 pm
by Tony Li
Glad to help! Keep in mind that it's a delegate, not an event, so you can only assign one handler to it. If you set the delegate to null, it will revert to the default behavior only (i.e., only call QuestLog.DefaultSetQuestEntryState).
Re: Quest progression event
Posted: Sat Jan 30, 2021 4:17 pm
by Haytam95
Right, it's nice to know that!
I only will have one "LevelProgress" script per scene, so I think it should work nice.
If sometime I need to have more than one script to handle quests, I could broadcast an event from Dialogue System with a custom script and subscribe to it if needed. Right? Using this same tecnique
Re: Quest progression event
Posted: Sat Jan 30, 2021 4:18 pm
by Tony Li
Yes, do can certainly do that. Or you could add a script to the Dialogue Manager that adds a C# event that your scene scripts can register for. Example:
Code: Select all
public class MyQuestEventScript : MonoBehaviour // on Dialogue Manager
{
public event System.EventHandler<string> questStateChanged = delegate {};
void OnQuestStateChanged(string quest)
{
questStateChanged(quest);
}
}
Then your scene scripts can hook into it like this:
Code: Select all
void OnEnable()
{
DialogueManager.instance.GetComponent<MyQuestEventScript>().questStateChanged += HandleQuestState;
}
void OnDisable()
{
DialogueManager.instance.GetComponent<MyQuestEventScript>().questStateChanged -= HandleQuestState;
}
void HandleQuestState(string quest)
{
//...
}
Re: Quest progression event
Posted: Sat Jan 30, 2021 4:25 pm
by Haytam95
Hey, that look even better!!!!
I'll go that way, looks cleaner and even more flexible (And avoids the risk to loss delegate reference)