Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

RPG Dialogue Tree

Discussion in 'Made With Unity' started by xathos, Aug 5, 2010.

  1. xathos

    xathos

    Joined:
    Sep 24, 2009
    Posts:
    23
    Hello everyone. First of all, I have way too many projects (Multiplayer FPS, RTS in development), which is kind of why I haven't really finished anything yet (and hence, general lack of posts here).

    However, I recently started on a smaller scale project, which was intended to be a simple RPG, and ended up creating a dialogue tree system for NPCs. It's quite similar to the dialogue system used in NWN (and most other RPGs, for that matter): Dialogue is composed of nodes, which have dialog options that link to other nodes. Each node can also change other variables in the gameworld - starting or updating a quest, for example.

    The code is relatively simple, and kind of messy at the moment, but here's a quick demo. Left-click to interact with NPCs (there's only one), and 'q' opens up your quest log. I'll apologize in advance for the audio, as it was just a crappy audio recording of me via Audacity - though I think that it serves it's function quite well.

    Anyways, take a look at the web player here: http://hackthetruth.org/upload/Xathos/Prototype NPC Conversation.html, and let me know what you guys think of it.
     
  2. DavidB

    DavidB

    Joined:
    Dec 13, 2009
    Posts:
    530
    Simple and effective, nice work :D
     
  3. xathos

    xathos

    Joined:
    Sep 24, 2009
    Posts:
    23
    Thanks. I'm working on polishing it up a bit (the code is pretty messy as is), and then I'm planning on releasing it to the community.

    My current goal is to build a NPC dialog script that is flexible enough to be used in almost any RPG. The dialog takes care of itself, and starts when it is called with the BeginDialog() function; a OnEndDialog function is provided within the script (which can be coded to do just about anything), and similar OnQuestUpdate() and OnReceiveReward() functions (which have their respective DialogQuestData and DialogRewardData classes). With proper coding, this script should be able to be integrated into just about any RPG project without intrusively forcing users to use a specific quest class structure, as the developer can define it himself (or herself) without messing with the core dialog code.
     
  4. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    i like it :D
     
  5. Ethan

    Ethan

    Joined:
    Jan 2, 2008
    Posts:
    497
    looks good :)
    looking forward to testing it
     
  6. xToxicInferno

    xToxicInferno

    Joined:
    Jan 31, 2010
    Posts:
    47
    This is great, one question though, when you choose a dialogue option, and a new text is displayed is that pre-setup or does it do it automatically. What i am asking is, does the buttons automatically position themselves relative to the text or did you go in and do it manually.

    Also, you should find someway to have it so when you click a option mid-speech it cuts the speech short as it is unpleasant to listen to two different speech's on top of each other.
     
  7. ExDeaDguY

    ExDeaDguY

    Joined:
    Aug 25, 2009
    Posts:
    455
    You should make it so 2 audio clips dont overlap. Easy way to do this: Make an active audio clip variable, when a new one becomes active, replace the active clip. and stop/destroy to previous one? Idk but yeah. thats how Id do it :p.
     
  8. xathos

    xathos

    Joined:
    Sep 24, 2009
    Posts:
    23
    Yeah, I know that, and it's implemented in the next version :)

    I was planning on finishing it and releasing it shortly after the initial post, but I got kind of sidetracked, and now school's started up again, so...

    I'll try to get it finished by the end of the month, when I have time to complete it
    :wink:
     
  9. Crouton

    Crouton

    Joined:
    May 10, 2010
    Posts:
    12
    Awesome can't wait till you finish this
     
  10. SilverFoxMedia

    SilverFoxMedia

    Joined:
    Nov 7, 2009
    Posts:
    153
    That's a real nice dialogue system, I've been using one that is more like that of Mass Effect's but I prefer the whole classic dialogue tree system like you've done. I can't wait to see the final product.
     
  11. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    do you still work on this?
     
  12. Caliber-Mengsk

    Caliber-Mengsk

    Joined:
    Mar 24, 2010
    Posts:
    683
    If you click the buttons quickly, the sounds keep playing and you can have many overlapping vo.
     
  13. Dares

    Dares

    Guest

    Joined:
    May 8, 2010
    Posts:
    35
    It's exacly the thing i was trying to make but i fail :(. It's just perfect type of Mass Effect or Gothic dialog system. Simple but effective :). Really great work Xathos.
     
  14. Deleted User

    Deleted User

    Guest

    Do you still work on the project ? Can't wait for the script :) very good work.
     
  15. xathos

    xathos

    Joined:
    Sep 24, 2009
    Posts:
    23
    Still working on it... I never was entirely happy with it, so I've never quite decided to release it, and I've rebuilt it at least three times already.

    Actually, I've started turning it into a full featured RPG (albeit without a combat system due to a lack of art assets), so there should be a lot more to this when I'm finally done-ish. Development's been rather slow with schoolwork and such, but I'll hopefully release something soon-ish.
     
  16. allen

    allen

    Joined:
    Mar 21, 2010
    Posts:
    81
  17. hike1

    hike1

    Joined:
    Sep 6, 2009
    Posts:
    401
    I tried the unitypackage, I can say ''hi, cube' and 'that's nice, goodbye' then I get this:


    ArgumentException: Getting control 0's position in a group with only 0 controls when doing mouseDown
    Aborting
    UnityEngine.GUILayoutGroup.GetNext () (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/GUILayoutUtility.cs:417)
    UnityEngine.GUILayoutUtility.BeginLayoutArea (UnityEngine.GUIStyle style, System.Type LayoutType) (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/GUILayoutUtility.cs:184)
    UnityEngine.GUILayout.BeginArea (Rect screenRect, UnityEngine.GUIContent content, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/GUILayout.cs:211)
    UnityEngine.GUILayout.BeginArea (Rect screenRect) (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/GUILayout.cs:201)
    NPC Conversation Script (Example).DrawDialog () (at Assets/Example/NPC Conversation Script (Example).js:170)
    NPC Conversation Script (Example).OnGUI () (at Assets/Example/NPC Conversation Script (Example).js:141)

    Something in unity changing the last 2 years maybe?
     
  18. hike1

    hike1

    Joined:
    Sep 6, 2009
    Posts:
    401
    Only other post I could find with this error:

    http://forum.unity3d.com/threads/13...position-in-a-group-with-only-0-controls-when

    Try putting your keydown check inside the Update function, also use Input.GetKeyDown instead of checking Event.current, since Event.current is always null inside the Update function.

    The reason you get that error message is, OnGUI is called several times per frame, and if you draw different number of controls in one of those called in the same frame, you might get this error message.

    These are lines 169-194 of npc conversation example.js

    GUI.Box (dim, ""); //Background Box
    GUILayout.BeginArea(dim);
    dialogDispScrolPos = GUILayout.BeginScrollView (dialogDispScrollPos);
    var curConvers = conversations[cIndex];

    GUILayout.Label (curConvers.dialog[curConvers.dIndex].npcDialog);
    for (response in curConvers.dialog[curConvers.dIndex].responses)
    {
    if (response.enabled)
    {
    if (GUILayout.Button(response.response, GUILayout.ExpandWidth(false)))
    {
    if (response.onlyAllowOnce)
    {
    response.enabled = false;
    }
    LinkToNode(response);
    }
    }
    }
    GUILayout.EndScrollView();
    GUILayout.EndArea();
    }

    function EndDialog ()
    {