Difference between revisions of "How do you set up a scripted conversation between two or more NPCs?"

no edit summary
imported>Maturin
 
imported>Vagrant0
Line 2: Line 2:




'''Creating a basic scripted conversation between two NPCs.'''
==Creating a basic scripted conversation between two NPCs.==
 


There are two simple ways to get NPCs to talk to each other:
There are two simple ways to get NPCs to talk to each other:
Line 37: Line 38:




'''Creating a speech by a single NPC'''
 
== Creating a speech by a single NPC ==
 


Setting up a "speech" by an NPC (where he is the only one talking) is actually a variant of the process given above. You can either use StartConversation to tell him to talk to himself (e.g. BurdRef.Startconversation BurdRef), or set up the conversation so that all the infos are "Next Speaker: Self" (e.g. you have a second NPC present, but he never speaks).
Setting up a "speech" by an NPC (where he is the only one talking) is actually a variant of the process given above. You can either use StartConversation to tell him to talk to himself (e.g. BurdRef.Startconversation BurdRef), or set up the conversation so that all the infos are "Next Speaker: Self" (e.g. you have a second NPC present, but he never speaks).




'''Creating a conversation between multiple NPCs'''
 
== Creating a conversation between multiple NPCs ==
 


Getting more than two NPCs to talk to each other, or getting NPCs to talk and move at the same time, requires abandoning the game's conversation generator completely, and handling everything by script. The key commands here are [[Say]] and [[SayTo]], in combination with script timers which track when it is time for the next NPC to speak. All the NPC conversations in the character creation sequence were handled in this way.
Getting more than two NPCs to talk to each other, or getting NPCs to talk and move at the same time, requires abandoning the game's conversation generator completely, and handling everything by script. The key commands here are [[Say]] and [[SayTo]], in combination with script timers which track when it is time for the next NPC to speak. All the NPC conversations in the character creation sequence were handled in this way.
Line 99: Line 104:


See the CharacterGen quest, CharGenMain topic for an extensive example.
See the CharacterGen quest, CharGenMain topic for an extensive example.
== Another Strategy For Speeches and Conversations Between Multiple NPCs==
This method deals mostly for cases where you have actors who are not near each other eg. two persons/groups shouting at each other from opposite sides of the road.
Similar to above, but a bit less complicated, another way to approach this is to first setup the quest script with just a variable defined. For our purposes, we'll just use the variable (short) ''nuline''. Save that script, and attach it to your quest. Then have all your dialogues created in the order you want them spoken, setting up a condition of who you want to speak them, and adding a condition using the quest variable ''nuline''. Using that variable, make every new dialogue assigned to a new value of this variable eg. first dialogue uses a value of 1, second dialogue uses a value of 2, and so on. Now, you have a clean list of all the dialogues, in order.
The way that this method differs from what is mentioned above is that most of the nuts and bolts is in the result script of each dialogue, allowing for finer tuning, and less clutter in the quest script.
Going back to the quest scripting, you will now need to add a small portion so that new lines will be called when the old one finishes. Every dialogue you defined previously needs to be called individually, normal conversation handling will not be kicking in since you will be having NPCs who are essentially talking to themselves, or talking at another NPC.
First things first, you'll need to add the variables '''''ref speaker''''', '''''ref target''''', and '''''float convtimer''''' to the top of your quest script. The purpose of all of these will be similar to above, since it will use similar scripting, but they will be handled slightly different, being that the speaker and target are now being defined as references instead of just numbers to be interpreted by the quest script.
The scripting to add to your quest should look something like
<pre>
if convTimer > 0
set convTimer to convTimer - getSecondsPassed
elseif speaker > 0
if target == 0
set convTimer to speaker.Say <topic>, 1
else
set convTimer to speaker.SayTo target <topic>, 1
target.look speaker
endif
endif
</pre>
The flag at the end of ''say'' and ''sayto'' is to force subtitles, which is usually a good idea given how your dialogue may not be voiced at this point, if at all.
The remaining working will be done within the result script of each of the dialogues. Within each result script area, you should always have 2 things;
'''set <quest>.nuline to <quest>.nuline + 1'''
and
'''set <quest>.convTimer to <duration of sound file +/- a few seconds>'''
The first line is there to help the dialogue proceed to the next line after it has been spoken. The second line is there to further refine the timing between this dialogue and the next, and allowing for momentary pauses. Until you have sound files created or generated, you can just use an estimate as to how long you think that line will be spoken for. You can always adjust this later.
(the ''convtimer'' part within the quest script is still needed to prevent the same line being looped in certain circumstances)
In addition to those 2 things, you also need to do some more work in the result script to setup the next dialogue to be spoken. These should be included in the result script of any dialogue for which there is a change of speaker or target for the next dialogue.
'''set <quest>.speaker to <ref to speak the next line>'''
'''set <quest>.target to <ref who will be spoken to (0 if none)>'''
If the dialogue is supposed to pause until after an event takes place, you do not need to include these lines, but instead directly call ''<speaker>.sayto <target> <topic>'' within separate scripting when that event is done (such as a quest stage update). During such a time that you don't want any lines spoken, you should set the ''<quest>.speaker'' to 0, and ''<quest>.nuline'' to some value which is not used by any dialogues. You can also use another condition in the quest script to act as a switch to turn on and off the portion that controls calling the next dialogue (the bit mentioned earlier).
This method is a bit easier to apply to your standard quest since you can rather easily add additional lines or speakers without having to go back to the quest script to register a new reference, all you have to do is adjust the result script to point to a different speaker, and change the ''nuline'' conditions for dialogues that take place afterward. This method is also a bit easier to understand since it is presented without the context of existing quests.






[[Category:Solutions]]
[[Category:Solutions]]
Anonymous user