Abandon State

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Abandon State

Post 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
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Abandon State

Post by nivlekius »

Finally found this post.
viewtopic.php?t=1693
Going to give it a try..
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Abandon State

Post 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.
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Abandon State

Post 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.
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Abandon State

Post 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.
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Abandon State

Post 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.
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Abandon State

Post by nivlekius »

restarting Unity seemed to fix it for some reason
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Abandon State

Post 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.
User avatar
Tony Li
Posts: 22056
Joined: Thu Jul 18, 2013 1:27 pm

Re: Abandon State

Post by Tony Li »

That code above looks fine.
nivlekius
Posts: 105
Joined: Thu Feb 28, 2019 4:39 pm

Re: Abandon State

Post by nivlekius »

Awesome, thank you, once again.
Post Reply