Manual:DIL Manual/cast spell()
cast_spell()
Function (integer), or Procedure with four arguments. Casts a spell without mana or the caster's own casting.
cast_spell(spell : integer, caster : unitptr, medium : unitptr, tgt : unitptr, effect : string) : integer cast_spell(spell : integer, caster : unitptr, medium : unitptr, tgt : unitptr);
Makes the spell happen as if caster had cast it through medium on tgt: no mana is used, the caster's position, fighting and casting time don't matter. It's how magic items work: a potion, a ring that heals, a weapon that strikes with lightning. The success roll uses the medium: an object's power, or a character's own ability and skill in that spell.
With five arguments it is a function and returns the result; with four it is a procedure (cast_spell(i, self, self, u); as a statement), with no effect argument.
Parameters
| Name | Type | Meaning |
|---|---|---|
| spell | integer | The spell, a SPL_* constant from vme/include/values.h (such as SPL_CURE_WOUNDS_1, SPL_BLESS).
|
| caster | unitptr | The character who casts it; the spell's messages treat it as the caster. |
| medium | unitptr | What the magic comes from: the object (potion, ring, wand) or the caster itself. |
| tgt | unitptr | The target of the spell. In the procedure form it may be null. |
| effect | string | "" for the spell's ordinary messages, or a template "name@zone" that shows the effect instead. It must take three arguments (unitptr, unitptr, integer): the two units of the spell and the amount (-1 or less when the spell failed). It runs on the caster.
|
Returns
The function form returns the spell's result: for most spells the success roll, above 0 when the spell worked; -1 when the spell can't be cast like this or not on that target. 0 when spell isn't a castable spell number (a spell group, or a spell that isn't implemented). The call fails, and the variable assigned keeps its old value, when caster is null or not a character, or medium or tgt is null.
Notes
- The spell must allow being cast as a spell (
MEDIA_SPELLin itsmediumsinvme/etc/spells.def); otherwise the caster is told "This spell wasn't meant to be there! Please report." and nothing happens. - A target the spell can't take gets "The magic disappears when cast on ...".
- An offensive spell counts as an attack by
casterfor the law. - Spells don't all pass the two units to the effect template in the same order: some pass the medium first, most of those in spells.zon the target first. Check the spell before writing an effect.
- Programs on the units can block the cast as they block an ordinary
castcommand. - The spell can kill the target. Afterwards the program's secures are checked at once.
Example
dilbegin ring_glow(medi : unitptr, targ : unitptr, hm : integer);
code
{
act("Your $2N glows softly.", A_ALWAYS, self, medi, targ, TO_CHAR);
return;
}
dilend
dilbegin heal_ring();
var
n : integer;
code
{
:start:
wait(SFB_CMD, command("say") and (activator == self.outside)
and ("heal" in argument) and (self.equip != 0));
n := cast_spell(SPL_CURE_WOUNDS_1, self.outside, self, self.outside,
"ring_glow@ex");
pause;
goto start;
}
dilend
A ring that heals its wearer when the wearer says "heal", with its own message, as the claws in arena.zon do. The example zone is called ex.