Page 1 of 1

Abandon State

Posted: Sun Mar 24, 2019 12:23 pm
by nivlekius
Hey Tony,
What's the best way to change the default state that Abandon Quest goes to for a specific quest? I've looked around, tried a few things but I'm guessing that like usual it's easier than I'm making it.

Thanks

Re: Abandon State

Posted: Sun Mar 24, 2019 1:53 pm
by nivlekius
Finally found this post.
viewtopic.php?t=1693
Going to give it a try..

Re: Abandon State

Posted: Sun Mar 24, 2019 2:09 pm
by Tony Li
OnQuestStateChange() will work, as in that post. If you want to make it general-purpose, you could add a field named, say, "Abandoned State", to the Quests template whose type is Quest State, and set its default value (e.g., abandoned). If you want a specific quest to go to the unassigned state when abandoned, you could change the field's value for that quest.

Then your OnQuestStateChange() might look like this:

Code: Select all

void OnQuestStateChange(string quest)
{
    if (QuestLog.CurrentQuestState(quest) == "abandoned")
    {
        var desiredState = DialogueLua.GetQuestField(quest, "Abandoned State").asString;
        if (desiredState != "abandoned")
        {
            QuestLog.SetQuestState(quest, desiredState);
        }
    }
}
Alternatively, you could assign a delegate to QuestLog.SetQuestStateOverride.

Re: Abandon State

Posted: Sun Mar 24, 2019 2:20 pm
by nivlekius
I did something similar

Code: Select all

public void OnQuestStateChange(string questName)
    {
       if(questName == "wells/10goblins")
        {
            if(QuestLog.CurrentQuestState(questName) == "abandoned" || QuestLog.CurrentQuestState(questName) == "unassigned")
            {
                QuestLog.SetQuestState(questName, "ready");
            }
        }
    }
I did basically the same earlier but I used GetQuestState instead and it caused a hang and I was getting byte reallocation messages. But what I just posted is almost instant. Does that look like it'll be ok? Just want to make sure I'm not causing any kind of leak, which is what looked like was happening before.

Re: Abandon State

Posted: Sun Mar 24, 2019 2:22 pm
by nivlekius
I'd like it to be more portable so I don't have to write the quest name for each one as there are only going to be a few NPCs that need this.

Re: Abandon State

Posted: Sun Mar 24, 2019 2:29 pm
by nivlekius
NVM those reallocation messages are still going crazy and I commented out the stuff I just did and it's still happening. Now I don't know why it is doing it.

Re: Abandon State

Posted: Sun Mar 24, 2019 2:39 pm
by nivlekius
restarting Unity seemed to fix it for some reason

Re: Abandon State

Posted: Sun Mar 24, 2019 3:08 pm
by nivlekius
So, it looks like that if the code I posted above looks like it won't cause any issues I'm good to go.

Re: Abandon State

Posted: Sun Mar 24, 2019 3:40 pm
by Tony Li
That code above looks fine.

Re: Abandon State

Posted: Sun Mar 24, 2019 3:45 pm
by nivlekius
Awesome, thank you, once again.