Scripting Dialogs for NPCs

RPMod features, downloads, installation instructions and announcements
Post Reply
Cyril Feraan
Lost One
Posts: 1974
Joined: Mon Jul 02, 2007 4:53 pm
Location: Alzoc III
Contact:

Scripting Dialogs for NPCs

Post by Cyril Feraan »

Scripting Dialogues for NPCs, A Tutorial
Original tutorial by Cyril Feraan, edited and completed by Soh Raun.

A special thanks to Gabe Alkorda for helping me out and providing example files for me to learn from.



I. Introduction
  • It can produce a very interesting effect to include NPCs with dialogs in your RPs, especially in missions or even just training scenarios. In this brief tutorial, we'll take a look at how you can go about making dynamic NPCs a reality.
II. What does a dynamic NPC consist of?
  • To make a dynamic NPC function, you must do three things.

    1) Write a dialog (.dlg) file containing the script for your NPC.
    2) Have the dialog file uploaded to your server(s) of choice.
    3) Spawn an npc with a specific name, then apply the dialog to the npc with the NPC dialog command.

    Code: Select all

    /npc dialog <dialogname> <npcname>
    This ensures your dialog is applied to the spawned NPC.
III. Making dialog files
  • Although the latter two steps are fairly easy, the most complicated and challenging aspect of creating a dynamic NPC is to make a proper dialog file. However with time and practice, it becomes quite a simple process.
  • Dialog file walkthrough

    The first thing in every script must be the name of the script. This is at the very top of the script file. Note that it is this line NOT the name of the .dlg file that is referred to when you use the NPC dialog syntax.

    Then, the entire following script must be enclosed in brackets { }. This tells the game what is within the script file and what is not.

    So, now our script file will look like this.

    Code: Select all

    JEDI_Dialog
    {
    }
    Now, we need to add some content.

    Dialogs can either consist of NPC or player nodes. NPC nodes contain lines of dialog that are said by the NPC to the player. Player nodes contain lines of dialog or lists of choices that can be performed from the player to the NPC. We will start with a NPC node.

    Every node within a dialog file must have a name, just like the dialog itself. Inside the main set of brackets, we use a similar syntax to enclose each individual node.

    Code: Select all

    JEDI_Dialog
    {
    
    	hello
    	{
    		<node key/value pairs>
    	}
    
    }
    Notice how the node is indented with tabs. While this isn't mandatory, it will greatly help you visualize the structure of your dialog and avoid mistakes (like forgetting to close a bracket).
  • NPC nodes

    There are seven basic key/value pairs that we can refer to when writing a NPC node. These are listed in the order they are normally listed within the dialog file.

    entity

    Specifies whether it is a NPC or player node.

    Code: Select all

    entity npc
    text

    Specifies the dialog itself that the NPC says to the player. All dialog must be surrounded by quotes.

    Code: Select all

    text "<dialog>"
    anim

    Specifies the NPC animation to display on-screen above the black dialog menu bar.

    A few examples of typical conversation animations have been provided within the syntax in this guide, however, a full list of possible humanoid animations is accessible from the file animation.cfg within RPMod-Animations.pk3 in GameData/rpmod. Other animations (for non-humanoid models) can be found in the respective animation.cfg for each of those non-humanoid mode types within models/players/<modelname> directory in assets1.pk3, which can be accessed from GameData/base.

    Code: Select all

    anim <animname>
    duration

    Specifies the duration (in seconds) before the dialog files proceeds to the value specified in the next command (see below).

    Code: Select all

    duration <value>
    skip

    When set at a value of "1", if a player clicks, he may override the duration command, literally skipping past dialog and forcing the dialog file to refer to the next command immediately.

    When at "0", a player may not click to skip ahead.

    Code: Select all

    skip <value>
    next

    Specifies the next NPC or player node for the dialog file to move onto. A lack of a next field within a certain node will cause the conversation to end after the number of seconds specified within the duration field. Either another line of dialog (another NPC node) or reply options (player node) can be linked to from a NPC node.

    Code: Select all

    next <another node name>
    action

    Specifies specific actions to accompany the dialog, in the form of server commands.

    Since all commands are server-side, coordinates must always be specified when a command like RPeffect is used, even when you intend to have a command take place precisely where you are standing. Since it is server-side and not client-side, it is impossible for the game to understand where you want the action to take place otherwise.

    Code: Select all

    action "<command1>; <command2>; <command3>"
    Example of coordinate specification:

    Code: Select all

    action "rpeffect add env/fire 123 456 789 0"
    Failure to specify coordinates will mean your action field will not work properly, though it won't cause the entire dialog to fail.

    Note that for more complex actions, you may place your commands inside a .cfg file and have it executed with the "exec script.cfg" command.


    Let us add instances of each of these fields to our dialog file.

    Code: Select all

    JEDI_Dialog
    {
    
    	hello
    	{
    		entity npc
    		text "Hello there."
    		anim BOTH_TALK1
    		duration 2
    		skip 1
    		next reply
    		action "rpeffect add env/dome 0 0 0 0; rpinfoitem -1 60 This infoitem has been added through the use of the action field."
    	}
    
    }
    We will also need to let the dialog file know where to start. Just inside the first bracket, we will use the start command to let the game know what is the first node to refer to. The first node can either be a NPC or a player node.

    Code: Select all

    JEDI_Dialog
    {
    	start hello
    
    	hello
    	{
    		entity npc
    		text "Hello there."
    		anim BOTH_TALK1
    		duration 2
    		skip 1
    		next reply
    		action "rpeffect add env/dome 0 0 0 0; rpinfoitem -1 60 This infoitem has been added through the use of the action field."
    	}
    
    }
  • Player nodes

    Now, it's time to allow the player to reply to the NPC. We'll use a player node this time. Player nodes can work in two ways: exactly like NPC nodes (refer to the documentation above in that case), or as a list of choices for the player to choose from. Here are the specific fields you can use for choice-oriented player nodes.

    entity

    Specifies whether it is a NPC or player node.

    Code: Select all

    entity player
    anim

    Specifies the player animation to display on-screen above the black dialog menu bar.

    A few examples of typical conversation animations have been provided within the syntax in this guide, however, a full list of possible humanoid animations is accessible from the file animation.cfg within RPMod-Animations.pk3 in GameData/rpmod.

    Code: Select all

    anim <animname>
    choice

    Creates an selectable option on the dialog menu bar. There can be up to 5 choice nodes in a player node.

    Code: Select all

    choice
    {
    }
    • A choice node can contain several key/value pairs within its brackets:

      text

      Specifies a dialog option that the player says to the NPC. All dialog must be surrounded by quotes.

      Code: Select all

      text "<dialog option>"
      rank

      Specifies the minimum rank permitted to access a particular option.

      Rank value of 1: Restricts the choice to Initiates and higher.
      Rank value of 2: Restricts the choice to Padawans and higher.
      Rank value of 3: Restricts the choice to Knights and higher.
      Rank value of 4: Restricts the choice to Masters and higher.
      Rank value of 5: Restricts the choice to Council and higher.

      Code: Select all

      rank <1>
      next

      Specifies the next NPC or player node for the dialog file to move onto. A lack of a next field within a certain node will cause the conversation to end after selecting the option. Usually, a NPC node is linked to from a player node.

      Code: Select all

      next <another node name>
    Using the key/value pairs available for a player node, we can add one to our dialog file.

    Code: Select all

    JEDI_Dialog
    {
    	start hello
    
    	hello
    	{
    		entity npc
    		text "Hello there."
    		anim BOTH_TALK1
    		duration 2
    		skip 1
    		next reply
    		action "rpeffect add env/dome 0 0 0 0; rpinfoitem -1 60 This infoitem has been added through the use of the action field."
    	}
    
    	reply
    	{
    		entity player
    		choice
    		{
    			text "Hello, how are you doing?"
    			rank 1
    			next reply2
    		}
    		choice
    		{
    			text "Goodbye." 
    		}
    	}
    
    }
    Notice how if the player selects the "Goodbye" option, there is no next field; the conversation will end. However, a next is specified if the player is a bit more sociable and selects "Hello, how are you doing?". Also note how you can only ask "How are you doing?" if you are at least of the rank of Initiate. Guests must simply say "Goodbye."
  • Wrapping up

    Let us add one more NPC node now.

    Code: Select all

    JEDI_Dialog
    {
    	start hello
    
    	hello
    	{
    		entity npc
    		text "Hello there."
    		anim BOTH_TALK1
    		duration 2
    		skip 1
    		next reply
    		action "rpeffect add env/dome 0 0 0 0; rpinfoitem -1 60 This infoitem has been added through the use of the action field."
    	}
    
    	reply
    	{
    		entity player
    		choice
    		{
    			text "Hello, how are you doing?"
    			rank 1
    			next reply2
    		}
    		choice
    		{
    			text "Goodbye." 
    		}
    	}
    
    	reply2
    	{
    		entity npc
    		text "Hello there."
    		anim BOTH_STAND1_TALK3
    		duration 2
    		skip 0
    	}
    
    	// End of dialog file.
    
    }
    Note the // at the end. This is the final "command" of importance. It allows us to make comments throughout our dialog file that will be ignored by the game, but allow us to make notes or remember what a certain part of the dialog file file is meant to refer to or be used for.

    You can also have multiple dialogs in the same file (remember that the game refers to a dialog by its listed name at the top of the dialog script, not the file name). However, this is not recommended in most circumstances, since it may cause a particular dialog file to become very large.

    Lastly, make sure to always end your dialog file with an empty line, as the game will expect so.

    The above dialog can be saved in a text file as <whatever>.dlg, then uploaded in the rpmod/dialogs directory of a server and used. So, we'd have JEDI_dialog.dlg, and after it is uploaded, we can make an NPC with:

    Code: Select all

    /npc spawn kyle test
    Then in-game, to load our dialog file:

    Code: Select all

    /npc dialog JEDI_dialog test
    Now, the dynamic NPC is complete and can be used freely!
Have fun with this. :)
Last edited by Cyril Feraan on Sun Aug 16, 2009 10:42 pm, edited 1 time in total.

|age_44|height_1.83m|weight_80kg|race_fondorian|
mentor_jamus.kevari|padawans_nira'kalen'nuruodo_ian.prine

Cyril Feraan
Lost One
Posts: 1974
Joined: Mon Jul 02, 2007 4:53 pm
Location: Alzoc III
Contact:

Post by Cyril Feraan »

Method for Effectively Applying NPC Dialogs to Inanimate Objects In-Game

In the previous post, I discussed how to create dynamic NPC dialogs that could be applied to any given NPC once uploaded to the server. In this post, I will discuss how to use NPCs and dialogs to give players the impression of inanimate objects possessing dialogs. Note that this is a crude workaround with its flaws, which will be explained later, but that it is the only way to create such an effect, so even the flaws are acceptable if a certain effect is desired. For example, how do you make it so that a book can bring up a dialog box? How do you make a computer console in-game have selectable options? This is the best work around.

The first thing you'll need to do is create an NPC suitable for creating this effect. Use a syntax that gives the NPC an invisible skin.

Code: Select all

/npc spawn <npctype> <npcname> <npcteam> jared/i
Here is the NPC that I will use for this tutorial:

Code: Select all

/npc spawn prisoner alpha 0 jared/i
Caution! Be careful that you do not create some sort of NPC that will move/attack if NPCs are unfrozen. This is not the kind of effect you want in your roleplay scenarios.

With your NPC spawned, you can now apply the dialog to it. Use the normal npc dialog syntax to apply it.

Finally, you want to position your NPC just above or to the side of your desired object. In this case, I want to make this console have a dialog 'attached' to it. I place the NPC above and just behind the console, walk up to it, press 'use', and voila...

<img width="530" src="http://home.att.net/~gkskis/console_npc.jpg">

Here is what is actually going on...

<img width="530" src="http://home.att.net/~gkskis/sense_npc.jpg">

What if I want to make a book model in-game have a dialog attached? The same method applies.

<img width="530" src="http://home.att.net/~gkskis/book_npc.jpg">

The obvious disadvantages associated with this method are:

A) You cannot pass through the area that the dynamic NPC resides in, since it takes up real space in the map.
B) You can end up accidentally moving an NPC (physically or with the Force) since again, it takes up real map space.
C) The NPC will cast a small shadow.


Plausible workarounds:

A) Do not place your NPC in such a manner that it obstructs or detracts from the natural flow of gameplay.
B) Do not attempt to use this method in areas where a battle scene will take place, for there is a definite risk your invisible NPC will end up moved or otherwise damaged.
C) Try to put the NPC in a spot where the shadow is not distracting.


Cheers.

|age_44|height_1.83m|weight_80kg|race_fondorian|
mentor_jamus.kevari|padawans_nira'kalen'nuruodo_ian.prine

Post Reply