From Mod Wiki
Firstly, there are two methods for creating dialogs. As briefly documented in the article on Quest creation, there is a 'static' dialog tree which allows for a fairly simple conversation to be defined. Additionally, you can create 'dynamic' or script controlled dialogs.
Static vs Dynamic - which to use.
For most dialogs, the static dialog will be simpler and sufficient. It will define a pre-planned conversation tree that can branch either by user selection, or the use of 'preconditions'.
Dynamic dialogs will use script to determine how the conversation progresses instead of a pre-planned tree. In the standard game, nearly every stalker has the option of having 'cool info' that more or less randomly gives a response when you ask if they know anything interesting. This uses a 'dynamic' dialog with script 'randomly' deciding which response the stalker will give.
A simple static dialog might be as follows.
- 1 - Hey, man, what's up?
- 2 - Not much, how are things with you?
- 11 - Pretty good, thanks.
- 111- Good to hear, keep it up.
- 12 - I've been better.
- 121- Well, tomorrow's a new day, here's hoping for better luck.
- 13 - I'm scraping bottom here, man.
- 131- That sucks, mate. Sorry to hear it.
So a simple conversation with one opening line, one response, and three branches for the third response. We may choose to let the user pick one of the three branches, or limit which are available with preconditions.
To define this dialog statically, we would make a dialog xml structure, and insert it into one of the dialog*.xml files in the config\gameplay folder.
<dialog id="our_casual_conversation"> <phrase_list> <phrase id="0"> <text>our_casual_dialog_0</text> <next>1</next> </phrase> <phrase id="1"> <text>our_casual_dialog_1</text> <next>11</next> <next>12</next> <next>13</next> </phrase> <phrase id="11"> <text>our_casual_dialog_11</text> <next>111</next> </phrase> <phrase id="12"> <text>our_casual_dialog_12</text> <next>121</next> </phrase> <phrase id="13"> <text>our_casual_dialog_13</text> <next>131</next> </phrase> <phrase id="111"> <text>our_casual_dialog_111</text> </phrase> <phrase id="121"> <text>our_casual_dialog_121</text> </phrase> <phrase id="131"> <text>our_casual_dialog_131</text> </phrase> </phrase_list> </dialog>
Dynamic dialogs do not define the whole tree, but rather define an initialization script that will be able to determine what phrases to add.
<dialog id="dm_hello_dialog"> <init_func>dialog_manager.init_intro_dialog</init_func> </dialog>
Both Dynamic and Static dialogs allow the use of the <precondition> tag. Preconditions are script functions that must return 'true' for the dialog to be enabled. Many precondition functions are defined in dialog_manager.script.
It is important to note any errors in dialog_manager.script will prevent the dialog_manager global from being assigned and will crash the game immediately with the message
- [error]Arguments : LUA error: e:\games\stalker\gamedata\scripts\_g.script:1255: attempt to index global 'dialog_manager' (a nil value)
Preconditions are called with five parameters - the original speaker, the other speaker, and P1,P2,and P3 (which I've yet to see used, and have no idea what they really are)
A simple precondition might look like
function precondition_is_stalker(speaker1,speaker2,P1,P2,P3) if IsStalker(speaker2) then return true end return false end
and there are many predefined preconditions, like
function has_2000_money(first_speaker, second_speaker) return first_speaker:money() >= 2000 end
Which dialog*.xml to use
You will have noticed there are several dialog*.xml files in the config/gameplay folder. One is generically named dialog.xml, and the rest have a zone name in them (IE. dialog_escape.xml) Very basically, all zones will include the dialog.xml and the zone specific xml... so if your new dialog will only show up in one zone, add it to the zone specific (to keep resource usage down), but if it will be used in multiple zones (all zones), you may add it to the dialog.xml.
In all of the dialogs, you have put an identifier, not the actual text you want to appear. This is to allow multiple language versions of the game. You must add entries to the appropriate stable_dialog*.xml file(s) for the languages you will support.
How to add dialogs to characters
Dialogs are added to characters via <start_dialog> or <actor_dialog> tags in the character definition. These determine who is speaker1 and who is speaker2. <start_dialog> tags indicate the npc is starting the conversation and is speaker1.
If your dialog is for a specific character, you simply add it to that character's definition. If your dialog should be available to all characters, you may add it to character_dialogs.xml, and it will show up for everyone EXCEPT special characters (unless preconditions limit it further).
So, if we wanted our static dialog to show up for all random characters, we would add