Difference between revisions of "Manual:DIL Manual/spellinfo()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(corrected from the DIL keyword tests (T029-T043))
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
−
<span id="bfsplinf"></span>
+
= spellinfo() =
−
string spellinfo(idx : integer, i1 : integer, i2 : integer, i3 : integer,
+
'''Function''' (string). Returns a spell's name and puts its properties in seven integer variables.
−
                  i4 : integer, i5 : integer, i6 : integer, i7 : integer, )
 
  
−
    idx : The spell index (SPL_XXX). You might want to use spellindex
+
spellinfo(i : integer, realm : integer, sphere : integer, mana : integer,
−
           to find this value.
+
           offensive : integer, resist : integer, media : integer, targets : integer)
  
−
    Returns:
+
Returns the name of spell number <code>i</code> and sets the other seven arguments from the
−
      The full name of the spell, or the empty string if no such spell.
+
spell's entry in <code>spells.def</code>. 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 <code>spellinfo(i, t, t, t, t, t, t, t)</code>.
  
−
    All the integer parameters are set to the following values:
+
== Parameters ==
−
      i1  : Spell realm (MAG / DIC)
+
{| class="wikitable"
−
      i2  : Spell sphere (SPL_XXX)
+
! Name !! Type !! Meaning
−
      i3  : Mana usage
+
|-
−
      i4  : 0 if a non-offensive spell, non-zero otherwise
+
| i || integer || The spell number, 0 to <code>SPL_TREE_MAX</code> - 1 (499). [[Manual:DIL Manual/spellindex()|spellindex()]] finds it from a name.
−
      i5  : Resistance required (SPLCST_XXX)
+
|-
−
      i6  : Mediums (MEDIA_XXX)
+
| realm || integer variable || Set to <code>ABIL_MAG</code> (0) or <code>ABIL_DIV</code> (1): the ability the spell is cast with.
−
      i7  : Targets (FIND_UNIT_XXX & TAR_XXX)
+
|-
 +
| sphere || integer variable || Set to the sphere the spell belongs to, <code>SPL_DIVINE</code> (1) to <code>SPL_EXTERNAL</code> (11). That is a spell number too, so <code>spellinfo()</code> 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 <code>SPLCST_CHECK</code> (1), <code>SPLCST_RESIST</code> (2) or <code>SPLCST_IGNORE</code> (3) (the <code>check</code> line in <code>spells.def</code>).
 +
|-
 +
| media || integer variable || Set to the bits of what may carry the spell: 1 spell, 2 potion, 4 wand, 8 staff, 16 scroll (<code>MEDIA_*</code>).
 +
|-
 +
| targets || integer variable || Set to the bits of what it may target: <code>FIND_UNIT_*</code> and the <code>TAR_*</code> bits.
 +
|}
  
−
  Example:
+
== Returns ==
−
    s := "cu li wo"; /* cure light wounds */
+
String: the spell's name, or <code>""</code> for a number in range that has no spell. For a
−
    i := spellindex(s);
+
number below 0 or above 499 it fails and the seven variables are not changed.
−
    s := spellinfo(i, i1, i2, i3, i4, i5, i6, i7);
 
−
    /* s & i1 - i7 now set */
 
−
<span id="bfsplinf"></span>
 
−
string spellinfo(idx : integer, i1 : integer, i2 : integer, i3 : integer,
 
−
                  i4 : integer, i5 : integer, i6 : integer, i7 : integer, )
 
  
−
    idx : The spell index (SPL_XXX). You might want to use spellindex
+
== Notes ==
−
          to find this value.
+
* The <code>SPLCST_*</code>, <code>MEDIA_*</code> and <code>TAR_*</code> constants are in
 +
  <code>spelldef.h</code>, which <code>macros.h</code> doesn't include: add
 +
  <code>#include &lt;spelldef.h&gt;</code> at the top of the zone. Only <code>SPLCST_*</code>
 +
  can be used there: <code>MEDIA_*</code> and <code>TAR_*</code> are written with
 +
  <code>&lt;&lt;</code>, which DIL doesn't have, so vmc stops with a syntax error at the
 +
  <code>&lt;</code>. Use the numbers: <code>MEDIA_*</code> as above; <code>TAR_IGNORE</code> 32,
 +
  <code>TAR_CHAR</code> 64, <code>TAR_OBJ</code> 128, <code>TAR_ROOM</code> 256,
 +
  <code>TAR_FIGHT_SELF</code> 512, <code>TAR_FIGHT_VICT</code> 1024, <code>TAR_SELF_ONLY</code> 2048,
 +
  <code>TAR_SELF_NONO</code> 4096, <code>TAR_AUTO_SELF</code> 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.
  
−
    Returns:
+
== Example ==
−
      The full name of the spell, or the empty string if no such spell.
+
<pre>
 +
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;
 +
  }
  
−
    All the integer parameters are set to the following values:
+
  sname := spellinfo(si, nrealm, nsphere, nmana, boffense, nresist, bvmedia, bvtargets);
−
      i1  : Spell realm (MAG / DIC)
+
  sphname := spellinfo(nsphere, t, t, t, t, t, t, t);
−
      i2  : Spell sphere (SPL_XXX)
 
−
      i3  : Mana usage
 
−
      i4  : 0 if a non-offensive spell, non-zero otherwise
 
−
      i5  : Resistance required (SPLCST_XXX)
 
−
      i6  : Mediums (MEDIA_XXX)
 
−
      i7  : Targets (FIND_UNIT_XXX & TAR_XXX)
 
  
−
   Example:
+
   if (nrealm == ABIL_DIV)
−
    s := "cu li wo"; /* cure light wounds */
+
      sendtext(sname + " is a divine spell of the " + sphname, self);
−
    i := spellindex(s);
+
  else
−
    s := spellinfo(i, i1, i2, i3, i4, i5, i6, i7);
+
      sendtext(sname + " is a magic spell of the " + sphname, self);
−
    /* s & i1 - i7 now set */
+
  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
 +
</pre>
 +
A player command that describes the spell named. The zone needs
 +
<code>#include &lt;spelldef.h&gt;</code> for <code>SPLCST_RESIST</code>.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/spellindex()|spellindex()]]
 +
* [[Manual:DIL Manual/cast spell()|cast spell()]]
 +
* [[Manual:DIL Manual/spells|spells]]
 +
* [[Manual:DIL Manual/isset()|isset()]]

Latest revision as of 07:21, 15 November 2026

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