Pegasus
Home/News  |  Connecting  |  Maps  |  Building

Building Info

[Back to List/Search]

NPCs

(24 July, 2000)
NPCs, or Non-Player Characters, are special objects that are capable of responding to the ask command and of automatic activity driven by the global cron process. NPCs may be entities with which players interact directly or, they may be used for localized weather-like phenomenon or to provide objects with relatively sophisticated behaviors without having to program them in MUF.

This is a brief tutorial for creating NPCs. It assumes you understand the basics of building, creating objects, and using property lists (q.v.)

Set the following properties on an object (the pipe symbol ¦ separates possible choices and emphasized terms should be replaced with the appropriate substitution):

@set npc_name=_npc:yes
@set npc_name=sex:male¦female¦neuter

This property is only required if you want the NPC to have responses driven by the global cron process:

@set npc_name=.canforce:yes

Be sure to describe, lock, and set a fail message.

Logging Unknown Inquiries

If you want your NPC to keep track of things it is asked (with the ask npc_name=question command) that it does not know:

@set npc_name=_asklog:y

A property list called log will be created on the NPC and unknown inquiries will be appended to it. You can check these periodically (presumably to modify your NPC to learn things you didn't realize it should know) using the lcat command (q.v.) You should also purge the list on occasion using the lremove command (q.v.)

Creating Responses

Next, use the property list editor (ledit - q.v.) to create a list called _response. This list will contain the responses of the NPC when asked questions with the ask command. The first line of each entry should begin with an ampersand (&) followed by a list of words for the given response, separated by spaces. Note that they must be single words.

&hello greetings salutations

After the list of terms, each line contains a single action. When the NPC responds to the ask command, it will choose one of the actions from that list at random. That action may be a single pose:

says, "Greetings, my friend!"
waves cheerfully!

... or it may be a call to a script (see below) or other action, prefaced by an at-sign (@):

@greetings

Puppet Heartbeat

You may also create a special entry called the heartbeat. This is a list of actions from which the global cron process will choose at each cycle:

&puppet_heartbeat
sighs.
looks around.
waits for someone to talk to him.

As of this writing, NPCs must be registered with the global cron process by a wizard before this will work. Email me (Dev@Evermore.com) or leave me page mail on Peg, including the debref of the NPC you want added to the cron process.

Remember that an NPC that does something in the same room on every heartbeat can be very annoying for players in the room. So, it is often a good idea to include some null actions or actions that have no output in your heartbeat list. Also consider setting a delay on the actions to keep them from happening right on the heartbeat.

Scripts

Scripts are collections of commands that may be called from the main _response list as described above. Scripts may (theoretically) be any length. Unlike the entries in the _response list, which are all automatically poses unless prefixed by a control character (& or @,) you must specify a command for scripts. Pose works from a colon. Prepending an exclamation point allows you to access any normal MUCK command. A dollar sign with a number allows you to insert a pause (length is determined by the number.) With a little careful planning, you can use scripts to make NPCs move around and interact with the environment.

led npc_name=greetings
i
:keens, "I fled, and cry'd out, Death;"
:keens, "Hell trembled at the hideous
name, and sigh'd"
:keens, "From all her caves, and back
resounded, Death."
$3
!spoof [Milton - Paradise Lost]
.
q

[Top of the page]