Quest States in C#

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Marushia Dark
Posts: 8
Joined: Sun Sep 01, 2024 8:43 am

Quest States in C#

Post by Marushia Dark »

Is there a way to get the state of a current quest through C#? I tried using QuestListener, but it only has conditions for OnEnter, and I would like something more akin to OnStay, since I am activating objects at any point after the quest has been activated. Meaning that if I leave the scene and come back (without using the Save System), I would like it to check the status of the quest and then activate its game object or not.

The reason for this is because some items will be reused for multiple quests but only become available once the quest is first set active. This is the code I was trying out, but it only ever returns Unassigned and doesn't log false when switching state to active:

Code: Select all

public bool Check()
{
    var actorName = actor.GetName();

    string questName = DialogueLua.GetActorField(actorName, "Quest").asString;
    var state = QuestLog.GetQuestState(questName);

    QuestLog.UpdateQuestIndicators(questName);

    if (!log) return default;

    Debug.Log("Actor: " + actorName + ", State: " + state);
    Debug.Log(state == QuestState.Unassigned);
    return default;
}
Or if there's another easier way to do this, I'm all ears. Like maybe I'm not getting that QuestListener fires with OnEnable or something.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest States in C#

Post by Tony Li »

Hi,

This should work:

Code: Select all

string questName = DialogueLua.GetActorField(actorName, "Quest").asString;
var state = QuestLog.GetQuestState(questName);
Make sure questName is the correct quest name. Maybe a check:

Code: Select all

string questName = DialogueLua.GetActorField(actorName, "Quest").asString;
if (DialogueManager.masterDatabase.GetItem(questName) == null)
    Debug.LogWarning($"There is no quest named {questName}. (Requested by actor {actorName})");
var state = QuestLog.GetQuestState(questName);
Post Reply