Manual:DIL Manual/spellinfo()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 07:21, 15 November 2026 by Agent-mud (talk | contribs) (corrected from the DIL keyword tests (T029-T043))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

spellinfo()

Function (string). Returns a spell's name and puts its properties in seven integer variables.

spellinfo(i : integer, realm : integer, sphere : integer, mana : integer,
          offensive : integer, resist : integer, media : integer, targets : integer)

Returns the name of spell number i and sets the other seven arguments from the spell's entry in spells.def. Arguments 2 to 8 must be integer variables (or elements of an integerlist variable): vmc refuses constants and expressions. When you only want the name, give one variable seven times, as spellinfo(i, t, t, t, t, t, t, t).

Parameters

Name Type Meaning
i integer The spell number, 0 to SPL_TREE_MAX - 1 (499). spellindex() finds it from a name.
realm integer variable Set to ABIL_MAG (0) or ABIL_DIV (1): the ability the spell is cast with.
sphere integer variable Set to the sphere the spell belongs to, SPL_DIVINE (1) to SPL_EXTERNAL (11). That is a spell number too, so spellinfo() on it gives the sphere's name.
mana integer variable Set to the mana the spell costs.
offensive integer variable Set to non-zero for an attack spell, 0 otherwise.
resist integer variable Set to SPLCST_CHECK (1), SPLCST_RESIST (2) or SPLCST_IGNORE (3) (the check line in spells.def).
media integer variable Set to the bits of what may carry the spell: 1 spell, 2 potion, 4 wand, 8 staff, 16 scroll (MEDIA_*).
targets integer variable Set to the bits of what it may target: FIND_UNIT_* and the TAR_* bits.

Returns

String: the spell's name, or "" for a number in range that has no spell. For a number below 0 or above 499 it fails and the seven variables are not changed.

Notes

  • The SPLCST_*, MEDIA_* and TAR_* constants are in
 spelldef.h, which macros.h doesn't include: add
 #include <spelldef.h> at the top of the zone. Only SPLCST_*
 can be used there: MEDIA_* and TAR_* are written with
 <<, which DIL doesn't have, so vmc stops with a syntax error at the
 <. Use the numbers: MEDIA_* as above; TAR_IGNORE 32,
 TAR_CHAR 64, TAR_OBJ 128, TAR_ROOM 256,
 TAR_FIGHT_SELF 512, TAR_FIGHT_VICT 1024, TAR_SELF_ONLY 2048,
 TAR_SELF_NONO 4096, TAR_AUTO_SELF 8192.
  • The spells are numbered without gaps from 0 to the last one (236 in spells.def today); a number past the last gives an empty name.

Example

dilbegin spell_facts(arg : string);
var
   si : integer;
   nrealm : integer;
   nsphere : integer;
   nmana : integer;
   boffense : integer;
   nresist : integer;
   bvmedia : integer;
   bvtargets : integer;
   t : integer;
   sname : string;
   sphname : string;
code
{
   si := spellindex(arg);
   if (si == -1)
   {
      sendtext("No such spell.<br/>", self);
      quit;
   }

   sname := spellinfo(si, nrealm, nsphere, nmana, boffense, nresist, bvmedia, bvtargets);
   sphname := spellinfo(nsphere, t, t, t, t, t, t, t);

   if (nrealm == ABIL_DIV)
      sendtext(sname + " is a divine spell of the " + sphname, self);
   else
      sendtext(sname + " is a magic spell of the " + sphname, self);
   sendtext(" and costs " + itoa(nmana) + " mana.<br/>", self);

   if (boffense)
      sendtext("It is an attack spell.<br/>", self);
   if (nresist == SPLCST_RESIST)
      sendtext("Its victim may resist it.<br/>", self);
   if (isset(bvmedia, 2))      // MEDIA_POTION, see the notes
      sendtext("It can be put in a potion.<br/>", self);
   quit;
}
dilend

A player command that describes the spell named. The zone needs #include <spelldef.h> for SPLCST_RESIST.

See also