Page 1 of 1
Quest State Changed Event
Posted: Wed Sep 26, 2018 6:42 am
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");
?
Re: Quest State Changed Event
Posted: Wed Sep 26, 2018 8:36 am
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.
Re: Quest State Changed Event
Posted: Thu Sep 27, 2018 1:20 am
by raingame_forgot_pass
Great! Thank you!
Re: Quest State Changed Event
Posted: Thu Sep 27, 2018 8:23 am
by Tony Li
Happy to help!
Re: Quest State Changed Event
Posted: Tue Nov 05, 2019 2:26 pm
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?
Re: Quest State Changed Event
Posted: Tue Nov 05, 2019 3:11 pm
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.
Re: Quest State Changed Event
Posted: Tue Nov 05, 2019 3:18 pm
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();
}
Re: Quest State Changed Event
Posted: Tue Nov 05, 2019 3:18 pm
by nivlekius
Yup, you recalled correctly, sir. I figured it out as you were tying I assume. Thanks, Tony.
Re: Quest State Changed Event
Posted: Tue Nov 05, 2019 3:22 pm
by Tony Li
Glad you found it!