Manual:DIL Manual/spellindex()

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

spellindex()

Function (integer). Finds a spell's number from its name or an abbreviation of it.

spellindex(s : string)

Looks for s among the spell names from spells.def and returns that spell's number, the same number as its SPL_* constant (values.h, vme.h). Every word may be abbreviated: "cu li wo" finds cure light wounds. Case doesn't matter, and spaces in front are skipped.

The spell spheres are in the same list: numbers 0 to 11 (SPL_ALL to SPL_EXTERNAL) are theory, divine sphere and so on to acid sphere.

Parameters

Name Type Meaning
s string The spell's name, whole or with its words abbreviated.

Returns

Integer: the spell number, or -1 when no spell matches (also for ""). It fails when s is a string variable that was never set: i := spellindex(s) then leaves i as it was, so set i or test s first.

Notes

  • The words of s are matched one by one against the words of each name. The name
 that matches the most words wins; on a tie the lowest number wins. So "fire" finds
 the fire sphere (7), not fireball, and "cure" finds the first spell whose
 name begins with cure. Words after a full match are ignored:
 "cure light wounds now" still finds cure light wounds.
  • Spells only; skills and weapons are other lists.
  • Spell numbers run from 0 to SPL_TREE_MAX - 1 (499), with gaps.

Example

dilbegin spell_num(arg : string);
var
   si : integer;
code
{
   si := spellindex(arg);
   if (si == -1)
      sendtext("There is no spell called '" + arg + "'.<br/>", self);
   else
      sendtext("'" + arg + "' is spell number " + itoa(si) + ".<br/>", self);
   quit;
}
dilend

A player command (func = in commands.def) that tells the number of the spell named, as the god command in commands.zon that sets a unit's spell skill looks it up.

See also