Index


NAME

NPC_Dialogue

DESCRIPTION

NPC dialogue support module.

($reply, @topics) = $dialog->tell ($msg)

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.

@comment text...

A single-line comment. It will be completely ignored.

@parse regex

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]

@cond perl

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:

$who - The cf::object::player object that initiated the dialogue.
$npc - The NPC (or magic_ear etc.) object that is being talked to.
$map - The map the NPC (not the player) is on.
$msg - The actual message as passed to this method.
$match - An arrayref with previous results from @parse.
$state - A hashref that stores state variables associated with the NPC and the player, that is, it's values relate to the the specific player-NPC interaction and other players will see a different state. Useful to react to players in a stateful way. See @setstate and @ifstate.
$flag - A hashref that stores flags associated with the player and can be seen by all NPCs (so better name your flags uniquely). This is useful for storing e.g. quest information. See @setflag and @ifflag.
$find - see @find, below.

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:

matching for an item name
   @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.

matching for an item name and removing the matched item
   @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;
   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 :-)

@eval perl

Like @cond, but proceed regardless of the outcome.

@msg perl

Like @cond, but the return value will be stringified and prepended to the reply message.

@check match expression

Executes a match expression (see http://pod.tst.eu/http://cvs.schmorp.de/deliantra/server/lib/cf/match.pm) to see if it matches.

self is the npc object, object, source and originator are the player communicating with the NPC.

If the check fails, the match is skipped.

@find match expression

Like @check in that it executes a match expression, but instead of failing, it gathers all objects into an array and provides a reference to the array in the $find variable.

When you want to skip the match when no objects have been found, combine @find with @cond:

   @match see my spellbook
   @find type=SPELLBOOK in inv
   @cond @$find
   It looks dirty.
   @match see my spellbook
   I can't see any, where do you have it?

@setstate state value

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.

@ifstate state value

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!

@setflag flag value

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 :)

Perversely enough, using @setfflag without a value clears the flag as if it was never set, so always provide a flag value (e.g. 1) when you want to set the flag.

See @ifflag for an example.

@ifflag flag value

Requires that the named flag has the given value, otherwise this topic is skipped. For more complex comparisons, see @cond with $flag.

If no value is given, then the ifflag succeeds when the flag is true.

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 connected-id [state]

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 a positive integer. Any value != 0 will 'push' the connection (in general, you should specify 1 for this) and 0 will 'release' the connection. This is useful for example when you want to let an NPC control a door.

Trigger all objects with the given connected-id by 'releasing' the connection.

@playersound face-name

Plays the given sound face (either an alias or sound file path) so that only the player talking to the npc can hear it.

@npcsound face-name

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.

@addtopic topic

Adds the given topic names (separated by |) to the list of topics returned.