Difference between revisions of "Manual:DIL Manual/SFB PRE"

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="sfbpre"></span>
+
= SFB_PRE =
 +
'''Constant''' (integer, vme.h: 0x0400).
  
−
  SFB_PRE           Command preprocessing
+
  wait(SFB_PRE, condition)
  
−
  When this flag is set, the program is activated by a few special events
+
The "about to happen" event. It is sent just before a spell takes effect and just before damage is dealt, and the programs that get it can change it: set <code>power</code> to change how strong it is, or <code>block</code> to stop it.
−
  which can then be blocked or changed. Currently, this event is triggered
 
−
  just prior to a spell being cast, and just prior to any sort of damage
 
−
  being given to a target.
 
  
−
  PRE "command(CMD_CAST)"
+
== Before a spell: command("cast") ==
 +
{| class="wikitable"
 +
! Variable !! Value
 +
|-
 +
| activator || the caster
 +
|-
 +
| medium || the caster, or the scroll, wand or staff the spell comes from
 +
|-
 +
| target || the target of the spell
 +
|-
 +
| argument || the spell number (<code>SPL_*</code> in values.h), followed by the spell's own argument, which is usually empty
 +
|-
 +
| power || how well the spell succeeds (its "hm"); read and write
 +
|}
 +
<code>block</code> stops the spell: nothing happens, and the caster's <code>cast_spell()</code> gets the value of <code>power</code> back, so set it to -1 as well.
  
−
  Assume a a spell is cast from player A on player B with a scroll C.
+
== Before damage: command(CMD_AUTO_DAMAGE) ==
 +
{| class="wikitable"
 +
! Variable !! Value
 +
|-
 +
| activator || the one who deals the damage
 +
|-
 +
| medium || the weapon, or what the damage comes from
 +
|-
 +
| target || the one who takes it
 +
|-
 +
| argument || three numbers: the attack group (<code>MSG_TYPE_WEAPON</code>, <code>MSG_TYPE_SPELL</code>, <code>MSG_TYPE_SKILL</code> or <code>MSG_TYPE_OTHER</code>, vme.h), the attack within the group (for weapons a <code>WPN_*</code>), and the body part hit (in melee one of <code>WEAR_HEAD</code>, <code>WEAR_HANDS</code>, <code>WEAR_ARMS</code>, <code>WEAR_BODY</code>, <code>WEAR_LEGS</code> or <code>WEAR_FEET</code>)
 +
|-
 +
| power || the damage; read and write. Don't set it below 0.
 +
|}
 +
<code>block</code> cancels the damage completely.
  
−
      'activator'... is a unitptr to A.
+
== Notes ==
−
      'medium'  ... is a unitptr to C.
+
* The event reaches the activator's surroundings, as a command does (see [[Manual:DIL Manual/SFB CMD|SFB_CMD]]), and the target too when it is somewhere else.
−
      'target'  ... is a unitptr to B.
+
* A program doesn't get the events of its own unit unless it is declared <code>aware</code>: a monster that changes the damage of its own blows needs <code>aware</code>, as comb_poison in function.zon does.
 +
* <code>send_pre()</code> sends this event from DIL.
 +
* Take the numbers out of <code>argument</code> with <code>getword()</code> and <code>atoi()</code>.
  
−
      command(CMD_CAST) will evaluate to TRUE.
+
== Example ==
 +
<pre>
 +
dilbegin fireward();
 +
var
 +
  s : string;
 +
  spl : integer;
 +
code
 +
{
 +
  heartbeat := PULSE_SEC;
  
−
      'argument'.... will contain a number followed by any
+
  :start:
−
                    argument to the spell itself. You should
+
  wait(SFB_PRE, command("cast") and (target == self));
−
                    parse this number, it equals the spell number SPL_XXX.
 
−
      'power' ....  is set to 'HM', i.e. how powerful the spell cast
 
−
                    is going to be. YOu can change this number at will.
 
−
                    If you decide to block the spell, you ought to set it
 
−
                    to -1.
 
  
−
Example:
+
  s := getword(argument);
−
    wait(SFB_PRE, command(CMD_CAST));
+
  spl := atoi(s);
  
−
    s := getword(argument);
+
  if (spl == SPL_FIREBALL_3)
−
    splno := atoi(s);
+
  {
 +
      act("The flames die around $1n.", A_SOMEONE, self, null, null, TO_ROOM);
 +
      power := -1;
 +
      block;
 +
  }
 +
  goto start;
 +
}
 +
dilend
  
−
    if (splno == SPL_FIREBALL_3)
+
dilbegin dmghalf();
−
      power := 0; /* No damage */
+
code
−
    ...
+
{
 +
  heartbeat := PULSE_SEC;
  
 +
  :start:
 +
  wait(SFB_PRE, command(CMD_AUTO_DAMAGE) and (target == self.outside));
  
−
   PRE "command(CMD_AUTO_DAMAGE)"
+
   if (power > 1)
 +
      power := power / 2;
 +
  goto start;
 +
}
 +
dilend
 +
</pre>
 +
fireward makes a monster immune to the strongest fireball; dmghalf on an item halves the damage its carrier takes.
  
−
  Assume that damage is given from player A to player B with a sword C.
+
== See also ==
−
 
+
* [[Manual:DIL Manual/send pre()|send_pre()]]
−
      'activator'... is a unitptr to A.
+
* [[Manual:DIL Manual/power|power]]
−
      'medium'  ... is a unitptr to C.
+
* [[Manual:DIL Manual/block|block]]
−
      'target'  ... is a unitptr to B.
+
* [[Manual:DIL Manual/cast spell()|cast_spell()]]
−
 
+
* [[Manual:DIL Manual/getword()|getword()]]
−
      command(CMD_AUTO_DAMAGE) will evaluate to TRUE.
+
* [[Manual:DIL Manual/SFB DONE|SFB_DONE]]
−
 
 
−
      'power' ....  is set to how much damage will be given. You can change
 
−
                    this number at will, but you should not set it to less
 
−
                    than zero.
 
−
 
 
−
      'argument'.... will contain three numbers that you must parse to
 
−
                    determine what kind of damage we're talking about.
 
−
 
 
−
                    First number is the attack group, this can be one of
 
−
                    MSG_TYPE_XXX from values.h and/or vme.h.
 
−
 
 
−
                    Second number is dependant on the attack group and
 
−
                    identifies what damage compared to the group. For
 
−
                    example WPN_XXX for weapon group.
 
−
 
 
−
                    Third number is the body hit location, one of WEAR_XXX,
 
−
                    (but not all of them, just hands, feet, legs, body, head,
 
−
                      arms, i.e. the armour positions, not positions like finger
 
−
                      or ear).
 
−
 
 
−
 
 
−
Example:
 
−
    wait(SFB_PRE, command(CMD_AUTO_DAMAGE));
 
−
 
 
−
    s1 := getword(argument);
 
−
    grpno := atoi(s1);
 
−
 
 
−
    s2 := getword(argument);
 
−
    atkno := atoi(s2);
 
−
 
 
−
    s3 := getword(argument);
 
−
    hitloc := atoi(s3);
 
−
 
 
−
    if (grpno == MSG_TYPE_SPELL)
 
−
...
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
'''<i>A note upon activating a DIL program</i>'''
 
−
 
 
−
This is what you can't do:
 
−
 
 
−
  If a DIL program is already active, e.g. it is sending a message or
 
−
  perhaps using "exec" to perform an action, then it can not be activated.
 
−
  Thus, any active DIL program is unable to catch further messages.
 
−
  Imagine this setting:
 
−
 
 
−
  You have five program P1..P5. P1 sends a message, which is intercepted
 
−
  by P2. P2 now sends a message, but since P1 is busy it can not process
 
−
  the message. P3..P5 are however possible candidates.
 
−
  Assume P3 sends a message, and P4 acts upon it. P4 now sends a message
 
−
  and the ONLY program which can catch it is P5, since all the other programs
 
−
  are "busy". If P5 sends a message no-one can act upon it. When P5
 
−
  returns, so does P4, P3, P2 and finally P1.
 
−
<span id="sfbpre"></span>
 
−
 
 
−
SFB_PRE            Command preprocessing
 
−
 
 
−
  When this flag is set, the program is activated by a few special events
 
−
  which can then be blocked or changed. Currently, this event is triggered
 
−
  just prior to a spell being cast, and just prior to any sort of damage
 
−
  being given to a target.
 
−
 
 
−
  PRE "command(CMD_CAST)"
 
−
 
 
−
  Assume a a spell is cast from player A on player B with a scroll C.
 
−
 
 
−
      'activator'... is a unitptr to A.
 
−
      'medium'  ... is a unitptr to C.
 
−
      'target'  ... is a unitptr to B.
 
−
 
 
−
      command(CMD_CAST) will evaluate to TRUE.
 
−
 
 
−
      'argument'.... will contain a number followed by any
 
−
                    argument to the spell itself. You should
 
−
                    parse this number, it equals the spell number SPL_XXX.
 
−
      'power' ....  is set to 'HM', i.e. how powerful the spell cast
 
−
                    is going to be. YOu can change this number at will.
 
−
                    If you decide to block the spell, you ought to set it
 
−
                    to -1.
 
−
 
 
−
Example:
 
−
    wait(SFB_PRE, command(CMD_CAST));
 
−
 
 
−
    s := getword(argument);
 
−
    splno := atoi(s);
 
−
 
 
−
    if (splno == SPL_FIREBALL_3)
 
−
      power := 0; /* No damage */
 
−
    ...
 
−
 
 
−
 
 
−
  PRE "command(CMD_AUTO_DAMAGE)"
 
−
 
 
−
  Assume that damage is given from player A to player B with a sword C.
 
−
 
 
−
      'activator'... is a unitptr to A.
 
−
      'medium'  ... is a unitptr to C.
 
−
      'target'  ... is a unitptr to B.
 
−
 
 
−
      command(CMD_AUTO_DAMAGE) will evaluate to TRUE.
 
−
 
 
−
      'power' ....  is set to how much damage will be given. You can change
 
−
                    this number at will, but you should not set it to less
 
−
                    than zero.
 
−
 
 
−
      'argument'.... will contain three numbers that you must parse to
 
−
                    determine what kind of damage we're talking about.
 
−
 
 
−
                    First number is the attack group, this can be one of
 
−
                    MSG_TYPE_XXX from values.h and/or vme.h.
 
−
 
 
−
                    Second number is dependant on the attack group and
 
−
                    identifies what damage compared to the group. For
 
−
                    example WPN_XXX for weapon group.
 
−
 
 
−
                    Third number is the body hit location, one of WEAR_XXX,
 
−
                    (but not all of them, just hands, feet, legs, body, head,
 
−
                      arms, i.e. the armour positions, not positions like finger
 
−
                      or ear).
 
−
 
 
−
 
 
−
Example:
 
−
    wait(SFB_PRE, command(CMD_AUTO_DAMAGE));
 
−
 
 
−
    s1 := getword(argument);
 
−
    grpno := atoi(s1);
 
−
 
 
−
    s2 := getword(argument);
 
−
    atkno := atoi(s2);
 
−
 
 
−
    s3 := getword(argument);
 
−
    hitloc := atoi(s3);
 
−
 
 
−
    if (grpno == MSG_TYPE_SPELL)
 
−
...
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
'''<i>A note upon activating a DIL program</i>'''
 
−
 
 
−
This is what you can't do:
 
−
 
 
−
  If a DIL program is already active, e.g. it is sending a message or
 
−
  perhaps using "exec" to perform an action, then it can not be activated.
 
−
  Thus, any active DIL program is unable to catch further messages.
 
−
  Imagine this setting:
 
−
 
 
−
  You have five program P1..P5. P1 sends a message, which is intercepted
 
−
  by P2. P2 now sends a message, but since P1 is busy it can not process
 
−
  the message. P3..P5 are however possible candidates.
 
−
  Assume P3 sends a message, and P4 acts upon it. P4 now sends a message
 
−
  and the ONLY program which can catch it is P5, since all the other programs
 
−
  are "busy". If P5 sends a message no-one can act upon it. When P5
 
−
  returns, so does P4, P3, P2 and finally P1.
 

Latest revision as of 23:24, 14 November 2026

SFB_PRE

Constant (integer, vme.h: 0x0400).

wait(SFB_PRE, condition)

The "about to happen" event. It is sent just before a spell takes effect and just before damage is dealt, and the programs that get it can change it: set power to change how strong it is, or block to stop it.

Before a spell: command("cast")

Variable Value
activator the caster
medium the caster, or the scroll, wand or staff the spell comes from
target the target of the spell
argument the spell number (SPL_* in values.h), followed by the spell's own argument, which is usually empty
power how well the spell succeeds (its "hm"); read and write

block stops the spell: nothing happens, and the caster's cast_spell() gets the value of power back, so set it to -1 as well.

Before damage: command(CMD_AUTO_DAMAGE)

Variable Value
activator the one who deals the damage
medium the weapon, or what the damage comes from
target the one who takes it
argument three numbers: the attack group (MSG_TYPE_WEAPON, MSG_TYPE_SPELL, MSG_TYPE_SKILL or MSG_TYPE_OTHER, vme.h), the attack within the group (for weapons a WPN_*), and the body part hit (in melee one of WEAR_HEAD, WEAR_HANDS, WEAR_ARMS, WEAR_BODY, WEAR_LEGS or WEAR_FEET)
power the damage; read and write. Don't set it below 0.

block cancels the damage completely.

Notes

  • The event reaches the activator's surroundings, as a command does (see SFB_CMD), and the target too when it is somewhere else.
  • A program doesn't get the events of its own unit unless it is declared aware: a monster that changes the damage of its own blows needs aware, as comb_poison in function.zon does.
  • send_pre() sends this event from DIL.
  • Take the numbers out of argument with getword() and atoi().

Example

dilbegin fireward();
var
   s : string;
   spl : integer;
code
{
   heartbeat := PULSE_SEC;

   :start:
   wait(SFB_PRE, command("cast") and (target == self));

   s := getword(argument);
   spl := atoi(s);

   if (spl == SPL_FIREBALL_3)
   {
      act("The flames die around $1n.", A_SOMEONE, self, null, null, TO_ROOM);
      power := -1;
      block;
   }
   goto start;
}
dilend

dilbegin dmghalf();
code
{
   heartbeat := PULSE_SEC;

   :start:
   wait(SFB_PRE, command(CMD_AUTO_DAMAGE) and (target == self.outside));

   if (power > 1)
      power := power / 2;
   goto start;
}
dilend

fireward makes a monster immune to the strongest fireball; dmghalf on an item halves the damage its carrier takes.

See also