Quest State Changed Event

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
raingame_forgot_pass
Posts: 4
Joined: Wed Sep 26, 2018 6:36 am

Quest State Changed Event

Post by raingame_forgot_pass »

Hi, Tony!

I didn't find any event like "QuestStateChangedEvent", so I could listen to that in my C# code like:

void Start()
{
QuestLog.QuestStateChangedEvent += QuestStateChangedEventHandler;
}

void QuestStateChangedEventHandler(string questName, QuestState newState)
{
// my code
}

Are there any? Or how can I handle every quest state change for example to save it?

Upd:
Ok, I have created event by myself: http://prntscr.com/kywm6s

But.. When I change Quest State in Conversation's "Script" field, my event does not call, it uses Lua code instead of QuestLog class. How to solve this problem? Do I have to simply register a new function with parameters "questName" and "state" and call this func in Script field:
SetQuestState("MyQuest", "acitve");
HandleQuestChangedEvent("MyQuest", "acitve");
?
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest State Changed Event

Post by Tony Li »

Hi,

Add an OnQuestStateChange() method to a script on the Dialogue Manager. For example:

Code: Select all

void OnQuestStateChange(string questTitle) {
    Debug.Log("Quest " + questTitle + " state is now " + QuestLog.CurrentQuestState(questTitle));
}
If you change a quest state using the Script "..." dropdowns or manually typing something like:

Code: Select all

SetQuestState("MyQuest", "active");
then the Dialogue System will call your OnQuestStateChange() method. The Dialogue System will also call the method if you call QuestLog.SetQuestState("MyQuest", QuestState.Active) in a C# script.
raingame_forgot_pass
Posts: 4
Joined: Wed Sep 26, 2018 6:36 am

Re: Quest State Changed Event

Post by raingame_forgot_pass »

Great! Thank you!
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest State Changed Event

Post by Tony Li »

Happy to help!
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Quest State Changed Event

Post by nivlekius »

Hey Tony,
I'm having an issue. I'm using the custom quests state code that you helped me make and I'm setting my quests to a custom state called "ready" that is the same as unassigned but when I talk to an npc and set another npc's quest state to ready. It works as expected by putting an exclamation mark above the other npc's head but it ALSO puts it into the journal. It shouldn't be doing that as it is not in the active state yet... it is in the ready, or unassigned state. I've looked all over for something that might be causing this (through all the conversations etc.) but I can't find what the problem might be. Any idea?
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest State Changed Event

Post by Tony Li »

Hi,,

I don't remember the details of the custom quest code. Are you sure it's not putting the quest into the active state somehow?

I vaguely recall that there might have been some custom quest log window code. If so, please review the code. It might add "ready" quests to the list.
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Quest State Changed Event

Post by nivlekius »

I think I found it in the CustomQuestLog script. Perhaps I can make the "ready" state equal "abandoned" or something like that? Most of them shouldn't be abandonable anyway.

Code: Select all

protected override void ShowQuests(QuestState questStateMask)
    {
        currentQuestStateMask = questStateMask;

        // If we're viewing active quests, also include preempted ones, which report as unassigned:
        var mask = questStateMask;
        if (mask == QuestState.Active) mask = mask | QuestState.Unassigned;

        noQuestsMessage = GetNoQuestsMessage(questStateMask);
        List<QuestInfo> questList = new List<QuestInfo>();
        if (useGroups)
        {
            var records = QuestLog.GetAllGroupsAndQuests(mask, true);
            foreach (var record in records)
            {
                if (!IsQuestVisible(record.questTitle)) continue;
                // If it's really unassigned and not preempted, skip it:
                if (QuestLog.CurrentQuestState(record.questTitle) == "unassigned") continue;
                questList.Add(GetQuestInfo(record.groupName, record.questTitle));
            }
        }
        else
        {
            string[] titles = QuestLog.GetAllQuests(mask, true, null);
            foreach (var title in titles)
            {
                if (!IsQuestVisible(title)) continue;
                // If it's really unassigned and not preempted, skip it:
                if (QuestLog.CurrentQuestState(title) == "unassigned") continue;
                questList.Add(GetQuestInfo(string.Empty, title));
            }
        }
        quests = questList.ToArray();
        OnQuestListUpdated();
    }
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Quest State Changed Event

Post by nivlekius »

Yup, you recalled correctly, sir. I figured it out as you were tying I assume. Thanks, Tony.
User avatar
Tony Li
Posts: 22055
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quest State Changed Event

Post by Tony Li »

Glad you found it! :-)
Post Reply