Page 1 of 1

Set Quest state from script?

Posted: Sat Apr 14, 2018 9:51 pm
by timbecile
I'm sure this has been asked a bunch, but I couldn't find it anywhere in the search.

What I'm trying to do is set the quest state from a c# script that's triggered after all the spawned enemies have been killed.

How do I do that?

Re: Set Quest state from script?

Posted: Sat Apr 14, 2018 10:50 pm
by Tony Li
Hi,

To set the quest state from a C# script, use QuestLog.SetQuestState:

Code: Select all

using PixelCrushers.DialogueSystem;
...
QuestLog.SetQuestState("My Quest", QuestState.Success);
A common way to trigger something after all the spawned enemies have been killed is to add an Increment On Destroy and Quest Trigger (or, more generally, Dialogue System Trigger) to each enemy:
  • Increment On Destroy will increment a variable. Configure its OnIncrement() event to call the Quest Trigger's OnUse method.
  • Set the Quest Trigger's trigger dropdown to OnUse, and set its Condition to require that the variable is greater than or equal to the number of spawned enemies. If so, set the quest state.
Using this technique, you don't need a C# script.

Re: Set Quest state from script?

Posted: Mon Apr 16, 2018 9:25 pm
by timbecile
Thanks Tony!

Is there a way at runtime to see what state a quest is in?

Re: Set Quest state from script?

Posted: Mon Apr 16, 2018 9:36 pm
by Tony Li
Yes, lots of ways. :-) If you're playing in the Unity editor, open the Dialogue Editor window and click on the Watches tab. Then add a watch on the quest.

If you're in a build, add a Lua Console to the Dialogue Manager. During play, press ~+L to open the Lua Console, and enter:

Code: Select all

return CurrentQuestState("My Quest")
where My Quest is the name of your quest.

In a script, check QuestLog.GetQuestState("My Quest").

And of course you can always set up a quest log window or quest tracker HUD so the player can check the state of quests.