Page 1 of 1

Quest States in C#

Posted: Mon Sep 02, 2024 10:36 pm
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.

Re: Quest States in C#

Posted: Tue Sep 03, 2024 8:08 am
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);