Adding a quest state

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
timbecile
Posts: 110
Joined: Mon Mar 12, 2018 11:00 pm

Adding a quest state

Post by timbecile »

I've found that I have a need to add a quest state now and again that I can check for in script. Is there a way to add a quest state?

for instance, a guy who unlocks a door assigns a quest.
when quest is success he gives the player his reward and sets the quest state to "done" or something

then the locked door checks for the 'done' state to allow the player entry.


Is there a way to do that?
User avatar
Tony Li
Posts: 21070
Joined: Thu Jul 18, 2013 1:27 pm

Re: Adding a quest state

Post by Tony Li »

Yes. But I may be misunderstanding what you need. I'm going to assume that you don't need separate states "success" and "done". I'll describe how to do what you described without scripting first. Then I'll describe how to do the same thing with scripting.

Define a quest in the Quests section of your dialogue database.

Let's say you use a conversation to turn in the quest. In the dialogue entry node, use the Script field's "..." dropdown wizard to select the quest and the "success" state. This will set the quest to "success" when the node plays.

Add two Dialogue System Triggers to the door.

Set the first trigger's Condition to require that the quest state is "active". (I'm assuming in this example that the quest can either be active or successful.) Add, say, a bark action that barks "Door is locked."

Set the second trigger's Condition to require that the quest state is "success". Add some actions to open the door, or load a new scene, or whatever. (The door in the Dialogue System's demo uses an action to switch between DemoScene1 and DemoScene2.)

---

To set a quest state in code, use QuestLog.SetQuestState():

Code: Select all

using PixelCrushers.DialogueSystem;
...
QuestLog.SetQuestState("Some Quest", QuestState.Success);
To check the current quest state, use QuestLog.GetQuestState():

Code: Select all

if (QuestLog.GetQuestState("Some Quest") == QuestState.Success) {
    // open door.
} else {
    // show message that door is still locked.
}
---

Now if you really do need separate "done" and "success" states, technically you can do that. The Dialogue System treats the string "success" and "done" both as successfully-completed quest states.

To set a quest state using a string:

Code: Select all

QuestLog.SetQuestState("Some Quest", "success");
// or
QuestLog.SetQuestState("Some Quest", "done");
To check it, use CurrentQuestState() instead of GetQuestState(). (CurrentQuestState returns the string value.)

Code: Select all

if (QuestLog.CurrentQuestState("Some Quest") == "done") {
    // open door.
}
Post Reply