Difference between revisions of "Manual:DIL Manual/spellinfo()"
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: | ||
| − | + | = 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 <code>i</code> and sets the other seven arguments from the | |
| − | + | 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>. | ||
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| − | + | ! Name !! Type !! Meaning | |
| − | + | |- | |
| − | + | | i || integer || The spell number, 0 to <code>SPL_TREE_MAX</code> - 1 (499). [[Manual:DIL Manual/spellindex()|spellindex()]] finds it from a name. | |
| − | + | |- | |
| − | + | | realm || integer variable || Set to <code>ABIL_MAG</code> (0) or <code>ABIL_DIV</code> (1): the ability the spell is cast with. | |
| − | + | |- | |
| + | | 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. | ||
| + | |} | ||
| − | + | == Returns == | |
| − | + | String: the spell's name, or <code>""</code> 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 <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 <spelldef.h></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><<</code>, which DIL doesn't have, so vmc stops with a syntax error at the | ||
| + | <code><</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. | ||
| − | + | == Example == | |
| − | + | <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; | ||
| + | } | ||
| − | + | 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 | ||
| + | </pre> | ||
| + | A player command that describes the spell named. The zone needs | ||
| + | <code>#include <spelldef.h></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_*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.
- 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.