Manual:DIL Manual/spellinfo()
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_*andTAR_*constants are in
spelldef.h, whichmacros.hdoesn't include: add#include <spelldef.h>at the top of the zone. OnlySPLCST_*can be used there:MEDIA_*andTAR_*are written with<<, which DIL doesn't have, so vmc stops with a syntax error at the<. Use the numbers:MEDIA_*as above;TAR_IGNORE32,TAR_CHAR64,TAR_OBJ128,TAR_ROOM256,TAR_FIGHT_SELF512,TAR_FIGHT_VICT1024,TAR_SELF_ONLY2048,TAR_SELF_NONO4096,TAR_AUTO_SELF8192.
- There are gaps in the numbering (no spells from 167 to 174), so a loop over all spells must
not stop at the first 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.