Difference between revisions of "Manual:DIL Manual/cast spell()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="bpcast_s"></span>
+
= cast_spell() =
−
cast_spell( i : integer, caster : unitptr, medium : unitptr, target : unitptr )
+
'''Function''' (integer), or '''Procedure''' with four arguments. Casts a spell without mana or the caster's own casting.
  
−
    WILL EVENTUALLY BE OBSOLETE AND REPLACED BY THE CAST_SPELL BELOW.
+
cast_spell(spell : integer, caster : unitptr, medium : unitptr, tgt : unitptr, effect : string) : integer
 +
cast_spell(spell : integer, caster : unitptr, medium : unitptr, tgt : unitptr);
  
−
    i : Spell index to cast. See SPL_* in values.h and/or vme.h.
+
Makes the spell happen as if <code>caster</code> had cast it through <code>medium</code> on <code>tgt</code>: 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.
−
    caster : The caster of the spell.
 
−
    medium : The medium, with which the spell is cast, might be caster.
 
−
    target : The target of the spell.
 
  
−
    Use this to cast spells without performing all the usual mana stuff, etc.
+
With five arguments it is a function and returns the result; with four it is a procedure (<code>cast_spell(i, self, self, u);</code> as a statement), with no effect argument.
−
    Very useful with for example rings / items possessing magical abilities.
 
  
−
integer cast_spell( i : integer, caster : unitptr, medium : unitptr, target : unitptr, effect : string )
+
== Parameters ==
−
    i : Spell index to cast. See SPL_* in values.h and/or vme.h.
+
{| class="wikitable"
−
    caster : The caster of the spell.
+
! Name !! Type !! Meaning
−
    medium : The medium, with which the spell is cast, might be caster.
+
|-
−
    target : The target of the spell.
+
| spell || integer || The spell, a <code>SPL_*</code> constant from <code>vme/include/values.h</code> (such as <code>SPL_CURE_WOUNDS_1</code>, <code>SPL_BLESS</code>).
−
    effect : A symbolic DIL program which takes no arguments. This will
+
|-
−
            cause all effects to be suppressed and leave this to the program
+
| caster || unitptr || The character who casts it; the spell's messages treat it as the caster.
−
            specified. A string of "" will cause the ordinary messages to
+
|-
−
            appear.
+
| medium || unitptr || What the magic comes from: the object (potion, ring, wand) or the caster itself.
−
    returns: The result of the spell.
+
|-
 +
| 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 <code>"name@zone"</code> that shows the effect instead. It must take three arguments <code>(unitptr, unitptr, integer)</code>: the two units of the spell and the amount (-1 or less when the spell failed). It runs on the caster.
 +
|}
  
−
    Use this to cast spells without performing all the usual mana stuff, etc.
+
== Returns ==
−
    Very useful with for example rings / items possessing magical abilities.
+
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 <code>spell</code> 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 <code>caster</code> is null or not a character, or <code>medium</code> or <code>tgt</code> is null.
−
    Please note that in the two programs below the variable 'hm' represents
 
−
    the number of hitpoints that will be deducted from the target.
 
  
−
    '''Example:'''
+
== Notes ==
 +
* The spell must allow being cast as a spell (<code>MEDIA_SPELL</code> in its <code>mediums</code> in <code>vme/etc/spells.def</code>); 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 <code>caster</code> for 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 <code>cast</code> command.
 +
* The spell can kill the target. Afterwards the program's secures are checked at once.
  
−
    %dil
+
== Example ==
 +
<pre>
 +
dilbegin ring_glow(medi : unitptr, targ : unitptr, hm : integer);
 +
code
 +
{
 +
  act("Your $2N glows softly.", A_ALWAYS, self, medi, targ, TO_CHAR);
 +
  return;
 +
}
 +
dilend
  
−
<nowiki>
+
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
 +
</pre>
 +
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 <code>ex</code>.
  
−
    dilbegin myeffect(medi : unitptr, targ : unitptr, hm : integer);
+
== See also ==
−
    code
+
* [[Manual:DIL Manual/attack spell()|attack spell()]]
−
dilend</nowiki>
+
* [[Manual:DIL Manual/spellindex()|spellindex()]]
−
 
+
* [[Manual:DIL Manual/spellinfo()|spellinfo()]]
−
    .....
+
* [[Manual:DIL Manual/meleeattack()|meleeattack()]]
−
 
 
−
    %...
 
−
 
 
−
<nowiki>
 
−
 
 
−
    dilbegin test();
 
−
    var
 
−
      n : integer;
 
−
    code
 
−
dilend</nowiki>
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
<span id="bpcast_s"></span>
 
−
cast_spell( i : integer, caster : unitptr, medium : unitptr, target : unitptr )
 
−
 
 
−
    WILL EVENTUALLY BE OBSOLETE AND REPLACED BY THE CAST_SPELL BELOW.
 
−
 
 
−
    i : Spell index to cast. See SPL_* in values.h and/or vme.h.
 
−
    caster : The caster of the spell.
 
−
    medium : The medium, with which the spell is cast, might be caster.
 
−
    target : The target of the spell.
 
−
 
 
−
    Use this to cast spells without performing all the usual mana stuff, etc.
 
−
    Very useful with for example rings / items possessing magical abilities.
 
−
 
 
−
integer cast_spell( i : integer, caster : unitptr, medium : unitptr, target : unitptr, effect : string )
 
−
    i : Spell index to cast. See SPL_* in values.h and/or vme.h.
 
−
    caster : The caster of the spell.
 
−
    medium : The medium, with which the spell is cast, might be caster.
 
−
    target : The target of the spell.
 
−
    effect : A symbolic DIL program which takes no arguments. This will
 
−
            cause all effects to be suppressed and leave this to the program
 
−
            specified. A string of "" will cause the ordinary messages to
 
−
            appear.
 
−
    returns: The result of the spell.
 
−
 
 
−
    Use this to cast spells without performing all the usual mana stuff, etc.
 
−
    Very useful with for example rings / items possessing magical abilities.
 
−
    Please note that in the two programs below the variable 'hm' represents
 
−
    the number of hitpoints that will be deducted from the target.
 
−
 
 
−
    '''Example:'''
 
−
 
 
−
    %dil
 
−
 
 
−
<nowiki>
 
−
 
 
−
    dilbegin myeffect(medi : unitptr, targ : unitptr, hm : integer);
 
−
    code
 
−
dilend</nowiki>
 
−
 
 
−
    .....
 
−
 
 
−
    %...
 
−
 
 
−
<nowiki>
 
−
 
 
−
    dilbegin test();
 
−
    var
 
−
      n : integer;
 
−
    code
 
−
dilend</nowiki>
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 

Latest revision as of 23:17, 14 November 2026

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_SPELL in its mediums in vme/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 caster for 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 cast command.
  • 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.

See also