NPC_Dialogue
NPC dialogue support module.
Tells the dialog object something and returns its response and optionally a number of topics that are refered to by this topic.
It supports a number of command constructs. They have to follow the
@match directive, and there can be multiple commands that will be
executed in order.
A single-line comment. It will be completely ignored.
Parses the message using a perl regular expression (by default
case-insensitive). Any matches will be available as $match->[$index].
If the regular expression does not match, the topic is skipped.
Example:
@match deposit @parse deposit (\d+) (\S+) @eval bank::deposit $match->[0], $match->[1]
Evaluates the given perl code. If it returns false (or causes an exception), the topic will be skipped, otherwise topic interpretation is resumed.
The following local variables are defined within the expression:
@parse.@setstate and
@ifstate.@setflag and @ifflag.The environment is that standard "map scripting environment", which is limited in the type of constructs allowed (no loops, for example).
Here is a example:
@match hi @cond grep $_->name =~ /royalty/, $who->inv You got royalties there! Wanna have!
You may want to change the name method there to something like title,
slaying or any other method that is allowed to be called on a
cf::object here.
@match found earhorn
@cond grep $_->slaying =~ /Gramp's walking stick/, $who->inv
@eval my @g = grep { $_->slaying =~ /Gramp's walking stick/ } $who->inv; $g[0]->decrease_ob_nr (1);
Thanks for the earhorn!
This example is a bit more complex. The @eval statement will search
the players inventory for the same term as the @cond and then
decreases the number of objects used there.
(See also the map: scorn/houses/cornerbrook.map for an example how this is
used in the real world :-)
Like @cond, but proceed regardless of the outcome.
Like @cond, but the return value will be stringified and prepended to
the message.
Sets the named state state to the given value. State values are
associated with a specific player-NPC pair, so each NPC has its own state
with respect to a particular player, which makes them useful to store
information about previous questions and possibly answers. State values
get reset whenever the NPC gets reset.
See @ifstate for an example.
Requires that the named state has the given value, otherwise this
topic is skipped. For more complex comparisons, see @cond with
$state. Example:
@match quest @setstate question quest Do you really want to help find the magic amulet of Beeblebrox? @match yes @ifstate question quest Then fetch it, stupid!
Sets the named flag flag to the given value. Flag values are
associated with a specific player and can be seen by all NPCs. with
respect to a particular player, which makes them suitable to store quest
markers and other information (e.g. reputation/alignment). Flags are
persistent over the lifetime of a player, so be careful :)
See @ifflag for an example.
Requires that the named flag has the given value, otherwise this
topic is skipped. For more complex comparisons, see @cond with
$flag. Example:
@match I want to do the quest! @setflag kings_quest 1 Then seek out Bumblebee in Navar, he will tell you... @match I did the quest @ifflag kings_quest 1 Really, which quets?
And Bumblebee might have:
@match hi @ifflag kings_quest Hi, I was told you want to do the kings quest?
Trigger all objects with the given connected-id.
When the state argument is omitted the trigger is stateful and retains an internal state per connected-id. There is a limitation to the use of this: The state won't be changed when the connection is triggered by other triggers. So be careful when triggering the connection from other objects.
When a state argument is given it should be either 0 or 1. 1 will 'push' the connection and 0 will 'release' the connection. This is useful for example when you want to let a npc control a door.
Trigger all objects with the given connected-id by 'releasing' the connection.
Plays the given sound face (either an alias or sound file path) so that only the player talking to the npc can hear it.
Plays the given sound face (either an alias or sound file path) as if the npc had made that sound, i.e. it will be located at the npc and all players near enough can hear it.
Adds the given topic names (separated by |) to the list of topics
returned.