Difference between revisions of "Manual:DIL Manual/SFB CMD"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
 
(checked against the compiler and the interpreter; example compiles)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
= SFB_CMD =
 +
'''Constant''' (integer, vme.h: 0x0004).
  
 +
wait(SFB_CMD, condition)
  
−
<span id="sfbcmd"></span>
+
The command event. A program waiting with <code>SFB_CMD</code> (in <code>wait()</code> or <code>interrupt()</code>) 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 <code>exec()</code>. Because the command hasn't happened yet, the program can stop it with <code>block</code>.
  
−
SFB_CMD            Command message
+
== What the event holds ==
 +
{| class="wikitable"
 +
! 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
 +
|}
  
−
  When this flag is set, the program gets activated by all commands (legal
+
== Notes ==
−
  or illegal) issued by PC's or NPC's. Moving around is also considered a
+
* Commands are matched by name: <code>command("north")</code> is also true when the player typed "n". There are no <code>CMD_NORTH</code> or <code>CMD_GET</code> constants; only the automatic events have numbers (<code>CMD_AUTO_*</code> in vme.h).
−
  command.
+
* A word the server doesn't know comes as <code>CMD_AUTO_UNKNOWN</code>, and <code>command("tester")</code> 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 <code>block</code>.
 +
* 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 <code>aware</code> (<code>dilbegin aware name();</code>). A program on a player that watches what the player types needs <code>aware</code>.
 +
* 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 <code>SFB_CMD</code> for the direction, with an empty argument.
 +
* The programs on a unit get the event one after another, in <code>fnpri</code> order. A <code>block</code> stops the command and every program after this one; give a blocking program a low priority, such as <code>FN_PRI_BLOCK</code>.
 +
* <code>activator</code> 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.
  
−
  Assume a janitor executes the command '
+
== Example ==
−
  Ge all from corpse',
+
<pre>
−
   And Ge interprets to 'get'
+
dilbegin fnpri(FN_PRI_BLOCK) guardnorth();
 +
code
 +
{
 +
   heartbeat := PULSE_SEC * 5;
  
−
   then this will occur in the DIL program:
+
   :start:
 +
  wait(SFB_CMD, command("north") and (activator.type == UNIT_ST_PC));
  
−
      'activator'... is a unitptr to the janitor.
+
  if (activator.level >= IMMORTAL_LEVEL)
−
      'cmdstr'...... is a string which contains 'get'
+
       goto start;
−
      'excmdstr'...... is a string which contains 'ge'
 
−
      'excmdstr_case'...... is a string which contains 'Ge'
 
−
       'argument'.... will contain 'all from corpse'
 
  
−
      command(CMD_GET) will evaluate to TRUE.
+
  act("$1n steps in front of you and shakes $1s head.",
 +
      A_SOMEONE, self, null, activator, TO_VICT);
 +
  block;
 +
  goto start;
 +
}
 +
dilend
 +
</pre>
 +
A guard who stops mortal players from going north.
  
−
 
+
== See also ==
−
---~---~---~---~---~---~---~---~---
+
* [[Manual:DIL Manual/wait()|wait()]]
 +
* [[Manual:DIL Manual/interrupt()|interrupt()]]
 +
* [[Manual:DIL Manual/block|block]]
 +
* [[Manual:DIL Manual/command()|command()]]
 +
* [[Manual:DIL Manual/argument|argument]]
 +
* [[Manual:DIL Manual/cmdstr|cmdstr]]
 +
* [[Manual:DIL Manual/excmdstr|excmdstr]]
 +
* [[Manual:DIL Manual/aware|aware]]
 +
* [[Manual:DIL Manual/fnpri|fnpri]]
 +
* [[Manual:DIL Manual/SFB DONE|SFB_DONE]]

Latest revision as of 23:24, 14 November 2026

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