Auto Complete

Announcements, support questions, and discussion for the Dialogue System.
User avatar
nathanj
Posts: 303
Joined: Sat May 28, 2016 12:30 am

Auto Complete

Post by nathanj »

Hello, Tony

After a year away from DS I am happy to say that we are back and the system is so great! The Cinemachine and Timeline integrations you've added is awesome.This totally answers my needs of our current project.

I have two questions I have't been able to find anything on.

#1. Is it possible to have quests auto complete? Say I have a firewood gathering quest where the player needs to collect 5 pieces of firewood. We are using Timeline to trigger the start of Quests and not using conversations at all.

Ignore. Face Palm
#2 The second one is a little more of the "oh come on, figure it out yourself" vein but I'm not sure where to look. With the firewood, I can increment my variable value through the On Use of the Quest Trigger script but the item is not destroyed. I know that there is an Increment on Destroy script but still, how is the Destroy to be called?

Thanks in advance.

Nathan
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Auto Complete

Post by Tony Li »

Hi Nathan,

It sounds like you may have got it all sorted out already. I'll cover one way to implement this kind of quest in case it's helpful for you or other readers in the future:

If you're using Increment On Destroy (which can be set to listen for OnDestroy or OnDisable events), this component has an OnIncrement() event.

You can add a Quest Trigger to the same GameObject. Set its trigger to OnUse. Then point the Increment On Destroy's OnIncrement() event to QuestTrigger.OnUse.

In the Quest Trigger, set Condition > Lua Conditions to require that the firewood variable is at least 5. For example, after using the point-and-click Lua wizard, the condition might look like:

Code: Select all

Variable["firewood"] >= 5
In the regular area, not the Condition, select the quest name and the Success state from the dropdowns.

If you want to execute other actions in addition to setting the quest to Success, you can use a Dialogue System Trigger instead of a Quest Trigger. This all-in-one component combines Quest Trigger, Alert Trigger, Sequence Trigger, etc. For example, you could use it to set the quest to Success, show an alert message, and run some sequence.
User avatar
nathanj
Posts: 303
Joined: Sat May 28, 2016 12:30 am

Re: Auto Complete

Post by nathanj »

Hey Tony

I'm so sorry for the hassle, I thought I had deleted the thread. :?

Just to confirm, yes, your response makes perfect sense. In case it helps here are images of the two components I needed for this.

Here is the Condition Observer that listens for a particular quest's state.
Image

And here is the Increment On Destroy
Image

However, I actually do have a question I do not know the answer for. Is there such a thing in Dialogue System that allows me to enable and disable specific components depending on quest states?

I'm trying to design a level that has no dialogue from NPCs. The only dialogue comes in the forum of alerts driven through the timeline (quests are started here). What I would like to do is have some timeline triggers only available during specific quest states. Say, the Timeline trigger to start a fire only becomes active once the gather fire materials quest is completed.

I could write up a script for this, but I'm wondering if there's anything in the system already that allows this?

Thanks again,

Nathan
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Auto Complete

Post by Tony Li »

Hi Nathan,

Condition Observer gets the job done, but I recommend using Dialogue System Trigger instead. It's more efficient. Condition Observer keeps repeatedly checking every second, whereas Dialogue System Trigger only checks when Increment On Destroy increments the firewood variable.

In the Dialogue System Trigger's Action > Sequence section, you can use the SetEnabled() sequencer command to enable the next quest trigger:

Image
User avatar
nathanj
Posts: 303
Joined: Sat May 28, 2016 12:30 am

Re: Auto Complete

Post by nathanj »

Thanks Tony,

This is great... However, I am not having my Quest complete, though I have collected the required items. I believe I have replicated your settings, is there anything else that might be missing or that is required for this to complete? I disabled the Condition Observer, though i don't believe that would effect it since it is what we are trying to bypass.

I believe that the Sequencer can access any component on the connected game object. Is this correct?

Image
User avatar
nathanj
Posts: 303
Joined: Sat May 28, 2016 12:30 am

Re: Auto Complete

Post by nathanj »

OK,

Figured it out. Now i need a solution ;)

I have the Dialogue System Trigger component attached to each pickup item because I would like to spawn the pickup items.

The problem was that these items are destroyed before the methods withing the DSTrigger can run. If I added the DSTrigger to a separate game object, connecting the firewood Increment On Destroy Event to the separate game object, it worked.

So my question: is there a way to connect the DSTrigger to components that are spawned?


Thanks in advance

Nathan
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Auto Complete

Post by Tony Li »

You are absolutely right. I'll put together a working example and post it here.
User avatar
nathanj
Posts: 303
Joined: Sat May 28, 2016 12:30 am

Re: Auto Complete

Post by nathanj »

Thank you, Tony.

One other thing, completely unrelated. How hard would it be for you to make a Sequencer plugin for Timeline? That would be such a useful tool.

Nathan
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Auto Complete

Post by Tony Li »

What do you mean by a sequencer plugin? The Dialogue System does have Timeline support. It's simple but covers most of the bases. If you have any feature suggestions, I'd be happy to have them.


Okay, here's an example scene: FirewoodTest_2018-01-17.unitypackage

The components are exactly the same but, as you pointed out, I had to move Dialogue System Trigger to a different GameObject so it wouldn't be destroyed before running.

This requires a short script to connect Increment On Destroy to Dialogue System Trigger. I included the script in the package above, and I'll paste it below, too. It's fairly general-purpose. You can add it to any Increment On Destroy and specify the GameObject name or tag of a Dialogue System Trigger. It will set up Increment On Destroy's OnIncrement() event automatically, so you can leave this event blank in your prefab.

ConnectIncrementOnDestroyToDialogueSystemTrigger.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

/// <summary>
/// This is a general purpose script that connects an IncrementOnDestroy component
/// to a DialogueSystemTrigger component on a different GameObject.
/// </summary>
[RequireComponent(typeof(IncrementOnDestroy))]
public class ConnectIncrementOnDestroyToDialogueSystemTrigger : MonoBehaviour
{

    [Tooltip("If set, connect to the Dialogue System Trigger on the GameObject with this name.")]
    public string triggerGameObjectName;

    [Tooltip("If set, connect to the Dialogue System Trigger on the GameObject with this tag.")]
    public string triggerTag;

    private void Start()
    {
        GameObject triggerGameObject = null;
        if (!string.IsNullOrEmpty(triggerGameObjectName))
        {
            triggerGameObject = GameObject.Find(triggerGameObjectName);
        }
        if (!string.IsNullOrEmpty(triggerTag) && triggerGameObject == null)
        {
            triggerGameObject = GameObject.FindGameObjectWithTag(triggerTag);
        }
        if (triggerGameObject == null)
        {
            if (Debug.isDebugBuild) Debug.LogWarning("Can't find " + triggerGameObject + " " + triggerTag + " to connect Increment On Destroy to Dialogue System Trigger.", this);
        }
        else
        {
            var trigger = triggerGameObject.GetComponent<DialogueSystemTrigger>();
            if (trigger == null)
            {
                if (Debug.isDebugBuild) Debug.LogWarning(triggerGameObject.name + " doesn't have a Dialogue System Trigger to connect Increment On Destroy.", this);
            }
            else
            {
                var incrementOnDestroy = GetComponent<IncrementOnDestroy>();
                incrementOnDestroy.onIncrement.AddListener(trigger.OnUse);
            }
        }
    }
}
I'm finishing work for the day, but I'll check back in the morning.
User avatar
nathanj
Posts: 303
Joined: Sat May 28, 2016 12:30 am

Re: Auto Complete

Post by nathanj »

Thank you for doing this, Tony. It works great and now I have pretty much everything working exactly how I want. I can not believe how easy this was. Now I just have to go through and actually set up some quests...

The sequencer pluging. I'm really just being lazy and should figure out how to use the Playable Director Wizard. I am basically just thinking of the ability to send SetEnabled and SetDisabled commands to game objects from teh Timeline. I know that I could use animations but this gets messy. Really, I'm just being lazy and need to learn how to use the wizard. :roll:

Everything here is looking great. Thanks again.

Nathan
Post Reply