Manual:DIL Manual/SFB CMD

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:24, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

SFB_CMD

Constant (integer, vme.h: 0x0004).

wait(SFB_CMD, condition)

The command event. A program waiting with SFB_CMD (in wait() or interrupt()) wakes whenever a player or a monster near it types a command, before the command runs. That includes commands the server doesn't know, commands the character isn't allowed to use, moving in a direction, and commands that DIL runs with exec(). Because the command hasn't happened yet, the program can stop it with block.

What the event holds

Variable Value
activator the character who typed the command
argument the rest of the line, without the spaces at either end ("all from corpse")
cmdstr the full name of the command ("get")
excmdstr the word as typed, in lower case ("ge")
excmdstr_case the word exactly as typed ("Ge")
command("get") TRUE
medium, target null

Notes

  • Commands are matched by name: command("north") is also true when the player typed "n". There are no CMD_NORTH or CMD_GET constants; only the automatic events have numbers (CMD_AUTO_* in vme.h).
  • A word the server doesn't know comes as CMD_AUTO_UNKNOWN, and command("tester") is true when the typed word is the start of "tester". Unless a program blocks it, the server then answers "... is not a known command.", so a program that makes up its own command must block.
  • The event reaches the character's room, the things the character carries and wears, everything else in the room (other characters, but of them only what they wear, and what is inside open transparent units), and the room around the room if this one is transparent.
  • A program doesn't get the commands of the unit it runs on, unless it is declared aware (dilbegin aware name();). A program on a player that watches what the player types needs aware.
  • The event comes before the level and position checks, so a program also sees commands the character can't use.
  • When characters follow someone, each follower's step sends its own SFB_CMD for the direction, with an empty argument.
  • The programs on a unit get the event one after another, in fnpri order. A block stops the command and every program after this one; give a blocking program a low priority, such as FN_PRI_BLOCK.
  • activator and the other values belong to this event only. Unit variables that aren't secured become null at every wake, so copy what you need right after the wait.

Example

dilbegin fnpri(FN_PRI_BLOCK) guardnorth();
code
{
   heartbeat := PULSE_SEC * 5;

   :start:
   wait(SFB_CMD, command("north") and (activator.type == UNIT_ST_PC));

   if (activator.level >= IMMORTAL_LEVEL)
      goto start;

   act("$1n steps in front of you and shakes $1s head.",
       A_SOMEONE, self, null, activator, TO_VICT);
   block;
   goto start;
}
dilend

A guard who stops mortal players from going north.

See also