Here is how NPC scripts work. It has been designed so that someone who doesn't know how to program can write one. Brackets indicate optional entries.
{Tongues spoken by the NPC}
{Dialogue line number} {NPC text}
{Condition to say dialogue option} ; {New dialogue line number if condition met} [, {if condition not met}] ; {Possible NPC reaction} [, {Parameters}] ; {Answer text for the player} ; [Repeat]
A condition could be requiring an item or a certain amount of gold.
A reaction could be ending the conversation or talking gold from the player.
Not all lines have conditions or reactions: they are optional.
Here is an example of an NPC who speaks Common and Elven and just says hello. Answering hello triggers the reaction "endtalk" which ends the conversation. There must always be an option to end the conversation, otherwise the player is stuck in conversation mode.
Common;Elven
00 Hello, player.
no condition;0;endtalk;Hello NPC.
First line: tongues
Second line: NPC text
Third line: dialogue options and actions
The third line is always: conditions ; new dialogue number ; NPC action ; answer text
Remember: the action is "endtalk", which ends the conversation. The new dialogue line number is 0, which means that when the player says "Hello NPC", they stay at the same line.
Here is the same NPC, but with a slightly more elaborate script. He says "Hello" and the player answers "Who are you?" The only difference with Example 1 is that the player is sent to a new line after they answer "Who are you?" which allows the NPC to say who they are.
Common;Elven
00 Hello, player.
no condition;1;no reaction;Who are you?
01 I am just an NPC.
no condition;1;endtalk;Goodbye.
Here is how to make the script more compact. You can just type "n" (or anything) when there are no conditions or parameters. The endtalk reaction doesn't have a parameter, but some reactions do.
Common;Elven
00 Hello, player.
n;1;n;Who are you?
01 I am just an NPC.
n;1;endtalk;Goodbye.
1) What do you put on the first line?
Tongues
Conditions
NPC text
2) What is the correct way to write tongues?
English; French; Spanish
English;French;Spanish
English ; French ; Spanish
3) How do you end the conversation?
With the "endtalk" condition
With the "endtalk" reaction
With the "endtalk" answer
4) What comes first?
Condition
Reaction
The text of the answer
Highlight (select with your mouse) the following line to see the answers.
1 - 1, 2 - 2, 3 - 2, 4 - 1
Here is how to offer more than one answer. If the player answers "Who are you?", the script goes to line 1. If the player answers "Where are we?", the script goes to line 2. The condition/dialogue number/reaction block is repeated after the first one.
Common;Elven
00 Hello, player.
n;1;n;Who are you?;n;2;n;Where are we?
01 I am just an NPC.
n;1;endtalk;Goodbye.
02 We are inside of a script.
n;2;endtalk;Goodbye.
Here is how to add a condition. The player can only say "Where are we?" if they are a gnome. If they are a gnome, the script goes to line 2; if they are not, it goes to line 3.
Common;Elven
00 Hello, player.
n;1;n;Who are you?;race,gnome;2,3;n;Where are we?
01 I am just an NPC.
n;1;endtalk;Goodbye.
02 We are inside of a script.
n;2;endtalk;Goodbye.
03 You are not a gnome, you can't say that.
n;3;endtalk;Goodbye.
Condition: race
Parameter: gnome
Here is how to inflict 2 points of damage if they ask "Where are we?" The reaction "dmg,2" is added after the dialogue option.
Common;Elven
00 Hello, player.
n;1;n;Who are you?;race,gnome;2,3;dmg,2;Where are we?
01 I am just an NPC.
n;1;endtalk;Goodbye.
02 We are inside of a script.
n;2;endtalk;Goodbye.
03 You are not a gnome, you can't say that.
n;3;endtalk;Goodbye.
Reaction: dmg
Parameter: 2
1) What is the order of the player answer line?
New line number / condition / reaction / player text
Condition / new line number / reaction / player text
Condition / new line number / player text / reaction
2) How do you test if someone is an elf?
With the reaction "race,elf"
With the condition "if,elf"
With the condition "race, elf"
3) How do you send the player to a new line?
It's automatic
You give them a new line number, before the condition
You give them a new line number, after the condition
4) How do you deal two points of damage to a player when they answer "Hit me" at line 0?
1;dmg,2;Hit me
1;Hit me;dmg,2
n;1;dmg,2;Hit me
Highlight (select with your mouse) the following line to see the answers.
1 - 2, 2 - 1, 3 - 3, 4 - 3
Here is how to show the option "Where are we?" only if the player is a gnome. Use the * symbol before the condition. If the player is not a gnome, they will only see the option "Who are you?" but won't see "Where are we?"
Common;Elven
00 Hello, player.
n;1;n;Who are you?;*race,gnome;2,3;dmg,2;Where are we?
01 I am just an NPC.
n;1;endtalk;Goodbye.
02 We are inside of a script.
n;2;endtalk;Goodbye.
03 You are not a gnome, you can't say that.
n;3;endtalk;Goodbye.
Tip: make sure that not all the options are hidden, or players who don't meet any of the conditions won't have anything to answer.
Since the answer "Where are we?" is only shown to gnomes, the condition is always met when a player selects the option. Hence, line 3 is never reached and we can remove it. It's not necessary to do this: it just makes the script more compact.
Common;Elven
00 Hello, player.
n;1;n;Who are you?;*race,gnome;2;dmg,2;Where are we?
01 I am just an NPC.
n;1;endtalk;Goodbye.
02 We are inside of a script.
n;2;endtalk;Goodbye.
Find what is wrong with the following statements. The answer is given under each statement (highlight it).
n;1;n;Who are you?;2;n;Where are we?
Answer: A condition is missing before the second dialogue option.
00 Hello, player
endtalk;0;n;Bye!
Answer: The reaction "endtalk" is used as a condition.
00 Hello, player.
1;n;Hello!;0;endtalk;Bye!
Answer: All the conditions are missing.
00 Hello, player.
*race,elf;1;n;Hello!
Answer: There's no dialogue option for players who are not elven.
The first option to make a seller NPC is to use conditions and reactions. Use a condition to test if the player has gold, and use reactions to give the item and take the gold. You can have a list of reactions by separating them with a dot, e.g. "take,10.give,longsword" to take 10 gold and give a longsword.
Common
00 Hello, player.
gold,10;1,2;take,10.give,short sword;[Buy short sword];gold,10;1,2;take,10.give,longsword;[Buy longsword];n;0;endtalk;Goodbye.
01 Here is your item!
n;0;endtalk;Goodbye.
O2 You don't have enough gold.
n;0;endtalk;Goodbye.
The second option is to use a special line. A special line replaces a dialogue option and opens a table to trade or to craft items. The dialogue is ended when the table is displayed, therefore the special line is not followed by conditions etc.
Find the sell specifications in the following chapter. NPCs can also craft items with a special line.
Common
00 Hello, player.
n;1;Show me the trading table.;n;0;endtalk;Goodbye.
sell;gold;short sword,longsword
-empty-
Here is the list of all conditions:
str,{str score}
dex,{dex score}
con,{con score}
int,{int score}
wis,{wis score}
cha,{cha score}
skill,{skill name},{difficulty class (DC)}
moralabove,{moral alignment, number between 0 and 999}
moralunder,{moral alignment}
ethicalabove,{ethical alignment}
ethicalunder,{ethical alignment}
item,{item name, must be in inventory}
gold,{amount of copper coins}
gender,{m or f}
class,{class name}
race,{race name}
level,{level}
date,{day},{month}
Here is the list of all actions:
give,{item}
give,{gold}
take,{item}
take,{gold}
givexp,{experience points}
givealign,{moral alignment points}
buff,{buff/spell effect name}
addpet,{pet name}
removepet,{pet name}
spawn,{monster name}
dmg,{damage points}
warp,{room number; to teleport}
Here are the special lines:
sell ; {currency} ; {item 1} , {item 2} [, repeat]
craft ; {item 1} ; {ingredient} , {amount of ingredient} , {other ingredient} , {amount of ingredient } [ ; repeat] ; {item 2} ; {ingredient} , {amount of ingredient} [ ; repeat]