Forum rules - please read before posting.

Variable conversation UI based on RPG-like XP system

Hey, excited that we're getting our project started with AC! Loving it so far.

I'm wondering if this is going to be possible with AC, or if we'll need to look into something like Dialogue System or other custom development to make it work. What we want to do is have a conversation system that adapts based on various XP skill trees. Basically, you can unlock more responses along a slice of a pie if you have enough XP in that certain skill.

Here's a prototype animation to give an idea of what we're going for.

So we'll have different animations based on all the variations of the pie, and we'll need to call the correct animation (and the corresponding dialogue options) after checking the XP variables for each of the 7 pie slices.

Is this type of system possible in AC? If possible, any insight into how we can do that would be awesome. I'm not a developer by any stretch, but I have some comfort with programming.

Comments

  • edited February 2021

    Welcome to the community, @mikewolsfeld.

    To clarify: each pie slice has its own XP value, and the amount of responses unlocked in each slice is then base on that slice's value?

    Yes, that should be possible - though Dialogue System does have a great integration with AC, should it'd be worth looking into that as well.

    I would, however, recommend separating the visuals from the functionality to begin with. Putting aside the graphics/animation for the moment, it'd be best to first focus on just having the correct responses be shown in a regular list.

    To do this with AC alone, you'll want to store your various XP values as Global Variables, and create a Conversation with all the possible responses.

    You could conceivably handle the response locking/unlocking using Actions. Before your Dialogue: Start conversation Action, you could use a large network of Variable: Check and Dialogue: Toggle option Actions to turn on/off the various responses based on your XP values. However, this would quickly get very complex - it's a lot easier to do this through scripting. AC's open API means that you can write code equivalent for anything that an Action can do.

    Somethine like this, attached to the Conversation, should do it:

    using UnityEngine;
    using AC;
    
    public class ConversationPieSlice : MonoBehaviour
    {
    
        public Conversation conversation;
        public PieSlice angrySlice;
        public PieSlice happySlice;
    
    
        private void OnEnable () { EventManager.OnStartConversation += OnStartConversation; }
        private void OnDisable () { EventManager.OnStartConversation -= OnStartConversation; }
    
    
        private void OnStartConversation (Conversation _conversation)
        {
            if (conversation == null) conversation = GetComponent <Conversation>();
    
            if (conversation == _conversation)
            {
                EvalSlice (angrySlice);
                EvalSlice (happySlice); 
            }
        }
    
    
        private void EvalSlice (PieSlice pieSlice)
        {
            pieSlice.Eval (conversation);
        }
    
    
        [System.Serializable]
        public class PieSlice
        {
    
            public string xpVariableName;
            public SubSlice[] subSlices;
    
    
            public void Eval (Conversation conversation)
            {
                GVar xpVariable = GlobalVariables.GetVariable (xpVariableName);
                int xpValue = xpVariable.IntegerValue;
    
                foreach (SubSlice subSlice in subSlices)
                {
                    subSlice.Eval (conversation, xpValue);
                }
            }
    
        }
    
    
        [System.Serializable]
        public class SubSlice
        {
    
            public int dialogueOptionID;
            public int minXP;
    
    
            public void Eval (Conversation conversation, int xpValue)
            {
                bool turnOn = xpValue >= minXP;
                conversation.SetOptionState (dialogueOptionID, turnOn, false);
            }
    
        }
    
    }
    

    This script's Inspector allows you to define Happy and Angry slices: which XP variable they're linked to, the dialogue options within them, as well as the minimum XP required for each option.

    The script hooks into the OnStartConversation event to determine if the Conversation is currently being run. If it is, it then evaluates each slice - and sub-slice, to determine which options should be shown.

    A tutorial on custom events can be found here, while the links above will take you to the Scripting Guide that covers all of AC's public functions and variables.

    Again, it's best to get the functionality working as intended before incorporating proper visuals animation - so have a tinker with the script and see how you go.

  • This is amazing, thanks so much for taking the time to respond! Glad the code is relatively simple and saves a ton of dragging and dropping. I'll try it out.
  • Thanks again, @ChrisIceBox , I think I understand the basics of how that code works (or at least enough that I can probably learn to edit it for our needs), but I'm a little lost with how to have that code plug-in/talk to AC. Or in other words, I can probably figure out how to edit the .cs file to do what you're saying, but where does AC reference this .cs file to run the code?

    Is it in the "Custom Action Scripts" section of the Actions menu in AC? Where I assign a scripts folder, and include that .cs file in that folder?

    The 'Calling Custom Events' tutorial just says to "Create a new C# script." Thanks to the user manual I figured out how to create a .cs file in the Project tab, but I'm now lost on how to make sure that AC references that .cs at the start of each conversation.

    Sorry if I'm asking too much, I'm new to both AC and Unity.

  • edited February 2021

    When it comes to inserting custom code into AC, there are generally three approaches:

    1. Custom Actions, which can be made use of in ActionLists, AC's visual-scripting system
    2. Custom Events, which hook into common tasks that AC performs, and adding additional behaviour
    3. Code replacement scripts, e.g. replacing a character's motion controller with another asset

    You can find more on this topic in the Manual's "Integrating new code" section.

    The script I posted is a custom event script, in that it waits for a given Conversation to be run - and modifies it based on data you've set in its Inspector. It doesn't need to be moved to a particular folder - it just needs to be placed in the scene, and have its Inspector filled in.

    The convenient thing about custom events is that AC doesn't need to be aware of any script that subscribes to its events: so long as it's present in the scene, and registered to an event (via the OnEnable function), it'll run by itself.

    The best place to assign it, however, is on the same GameObject as the Conversation itself. You can have multiple Conversations in a scene, so you can also have multiple instances of the script.

    To do this, just locate your Conversation object, open the Inspector, and drag the script file from your Project window (which should be named ConversationPieSlice.cs) onto the Inspector.

    The script will then appear as a new component. At the top will be a "Conversation" field - so set this to be the same Conversation it's attached to.

    You'll then also need to expand and fill in the fields for the HappySlice / AngrySlice fields - once you've defined your Variables in the Variables Manager.

    I have, however, just fixed a bug in the code above - so you'll need to update the script beforehand.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.