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)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
= 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);
  
−
<span id="bpcast_s"></span>
+
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.
−
cast_spell( i : integer, caster : unitptr, medium : unitptr, target : unitptr )
 
  
−
    WILL EVENTUALLY BE OBSOLETE AND REPLACED BY THE CAST_SPELL BELOW.
+
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.
  
−
    i : Spell index to cast. See SPL_* in values.h and/or vme.h.
+
== Parameters ==
−
    caster : The caster of the spell.
+
{| class="wikitable"
−
    medium : The medium, with which the spell is cast, might be caster.
+
! Name !! Type !! Meaning
−
    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>).
 +
|-
 +
| 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 <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.
  
−
integer cast_spell( i : integer, caster : unitptr, medium : unitptr, target : unitptr, effect : string )
+
== Notes ==
−
    i : Spell index to cast. See SPL_* in values.h and/or vme.h.
+
* 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.
−
    caster : The caster of the spell.
+
* A target the spell can't take gets "The magic disappears when cast on ...".
−
    medium : The medium, with which the spell is cast, might be caster.
+
* An offensive spell counts as an attack by <code>caster</code> for the law.
−
    target : The target of the spell.
+
* 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.
−
    effect : A symbolic DIL program which takes no arguments. This will
+
* Programs on the units can block the cast as they block an ordinary <code>cast</code> command.
−
            cause all effects to be suppressed and leave this to the program
+
* The spell can kill the target. Afterwards the program's secures are checked at once.
−
            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.
+
== Example ==
−
    Very useful with for example rings / items possessing magical abilities.
+
<pre>
−
    Please note that in the two programs below the variable 'hm' represents
+
dilbegin ring_glow(medi : unitptr, targ : unitptr, hm : integer);
−
    the number of hitpoints that will be deducted from the target.
+
code
 +
{
 +
  act("Your $2N glows softly.", A_ALWAYS, self, medi, targ, TO_CHAR);
 +
  return;
 +
}
 +
dilend
  
−
    '''Example:'''
+
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>.
  
−
    %dil
+
== See also ==
−
 
+
* [[Manual:DIL Manual/attack spell()|attack spell()]]
−
<nowiki>
+
* [[Manual:DIL Manual/spellindex()|spellindex()]]
−
 
+
* [[Manual:DIL Manual/spellinfo()|spellinfo()]]
−
    dilbegin myeffect(medi : unitptr, targ : unitptr, hm : integer);
+
* [[Manual:DIL Manual/meleeattack()|meleeattack()]]
−
    code
 
−
    {
 
−
      act("The caster is $1N medium is $2N and target is $3N",
 
−
          A_ALWAYS, self, medi, targ, TO_ALL);
 
−
      act("The spell result is $2d", A_ALWAYS, self, hm, null, TO_ALL);
 
−
      quit;
 
−
    }
 
−
    dilend</nowiki>
 
−
 
 
−
    .....
 
−
 
 
−
    %...
 
−
 
 
−
<nowiki>
 
−
 
 
−
    dilbegin test();
 
−
    var
 
−
      n : integer;
 
−
    code
 
−
    {
 
−
      wait(SFB_DONE, command("beg"));
 
−
 
 
−
      n := cast_spell(SPL_FIREBALL_1, self, self, activator, "myeffect@wiz");
 
−
 
 
−
      exec("say Result of spell was "+itoa(n), self);
 
−
    }
 
−
    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