Manual:DIL Manual/cmdptr

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:27, 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

cmdptr

Type. A pointer to one of the game's commands.

var
   cmd : cmdptr;

A cmdptr gives a program the facts about a command, as set in commands.def: its name, type, and who may use it. chead() is the first command, cmd.next the next one (null after the last), and getcmd(word) the command a word means when typed, abbreviations included.

Fields

Field Type Meaning
name string the command's full name
type integer its type: TYPE_SOCIAL, TYPE_SKILL and the others in values.h
level integer the lowest level that may use it
position integer the lowest position it can be used in (POSITION_...)
loglevel integer from which level the use is logged; 0 for not at all
speed integer its speed in combat
next cmdptr the next command

Each field's page has the details.

Notes

  • Commands stay for as long as the server runs, so cmdptr variables keep their value through waits. They are not saved with a unit: after loading they are null.
  • A field of a null cmdptr fails; test cmd == null first.
  • There is no previous field, and the function is getcmd(), not getcommand(), though older pages said so.
  • cmd.profession compiles but stops the program with a type error when it runs.

Example

dilbegin do_mycmds(arg : string);
var
   cmd : cmdptr;
   s : string;
code
{
   cmd := chead();
   while (cmd != null)
   {
      if ((cmd.level <= self.level) and (cmd.type != TYPE_SOCIAL)
          and (cmd.type != TYPE_SKILL))
         s := s + cmd.name + " ";
      cmd := cmd.next;
   }
   pagestring("You can use: " + s + "<br/>", self);
   quit;
}
dilend

A command that lists the commands the player's level allows, leaving out socials and skills; adapted from comm_dil in commands.zon.

See also