Difference between revisions of "Manual:DIL Manual/SFB PRE"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = SFB_PRE = | |
| + | '''Constant''' (integer, vme.h: 0x0400). | ||
| − | SFB_PRE | + | 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 <code>power</code> to change how strong it is, or <code>block</code> to stop it. | |
| − | |||
| − | |||
| − | |||
| − | + | == 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. | ||
| − | + | == 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. | ||
| − | + | == Notes == | |
| − | + | * 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. | |
| − | + | * 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>. | ||
| − | + | == Example == | |
| + | <pre> | ||
| + | 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 | ||
| + | </pre> | ||
| + | fireward makes a monster immune to the strongest fireball; dmghalf on an item halves the damage its carrier takes. | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/send pre()|send_pre()]] | |
| − | + | * [[Manual:DIL Manual/power|power]] | |
| − | + | * [[Manual:DIL Manual/block|block]] | |
| − | + | * [[Manual:DIL Manual/cast spell()|cast_spell()]] | |
| − | + | * [[Manual:DIL Manual/getword()|getword()]] | |
| − | + | * [[Manual:DIL Manual/SFB DONE|SFB_DONE]] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 23:24, 14 November 2026
Contents
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 needsaware, as comb_poison in function.zon does. send_pre()sends this event from DIL.- Take the numbers out of
argumentwithgetword()andatoi().
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.