Quest State Changed Event
-
- Posts: 4
- Joined: Wed Sep 26, 2018 6:36 am
Quest State Changed Event
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");
?
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");
?
Re: Quest State Changed Event
Hi,
Add an OnQuestStateChange() method to a script on the Dialogue Manager. For example:
If you change a quest state using the Script "..." dropdowns or manually typing something like:
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.
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));
}
Code: Select all
SetQuestState("MyQuest", "active");
-
- Posts: 4
- Joined: Wed Sep 26, 2018 6:36 am
Re: Quest State Changed Event
Great! Thank you!
Re: Quest State Changed Event
Happy to help!
Re: Quest State Changed Event
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?
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?
Re: Quest State Changed Event
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.
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.
Re: Quest State Changed Event
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();
}
Re: Quest State Changed Event
Yup, you recalled correctly, sir. I figured it out as you were tying I assume. Thanks, Tony.
Re: Quest State Changed Event
Glad you found it!