Difference between revisions of "Manual:DIL Manual/SFB COM"
Jump to navigation
Jump to search
(checked against the compiler and the interpreter; example compiles) |
|||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
= SFB_COM = | = SFB_COM = | ||
| + | '''Constant''' (integer, vme.h: 0x0020). | ||
| − | SFB_COM | + | wait(SFB_COM, condition) |
| − | + | The combat event. It is sent every time a character makes a melee attack, after the attack is rolled and before its damage is worked out (a fumble sends none). A program waiting with <code>SFB_COM</code> wakes for every attack made near it; its unit doesn't have to be in the fight. | |
| − | |||
| − | it | ||
| − | |||
| − | + | == What the event holds == | |
| − | + | {| class="wikitable" | |
| + | ! Variable !! Value | ||
| + | |- | ||
| + | | activator || the character making the attack | ||
| + | |- | ||
| + | | argument || empty | ||
| + | |- | ||
| + | | command(CMD_AUTO_COMBAT) || TRUE | ||
| + | |- | ||
| + | | medium, target || null: the one attacked is <code>activator.fighting</code> | ||
| + | |} | ||
| − | + | == Notes == | |
| − | + | * The event reaches the same units as a command (see [[Manual:DIL Manual/SFB CMD|SFB_CMD]]): the attacker's room, what the attacker carries and wears, and the others in the room. | |
| + | * A program doesn't get the attacks of its own unit unless it is declared <code>aware</code>. A monster that wants to act on its own attacks needs <code>aware</code>; to act when it is attacked, check <code>self.fighting</code> or <code>self.position == POSITION_FIGHTING</code>. | ||
| + | * In a fight of several rounds the event comes often: keep the condition of the <code>wait()</code> narrow. | ||
| + | * To change the damage of a hit, use <code>SFB_PRE</code> with <code>command(CMD_AUTO_DAMAGE)</code> instead. | ||
| − | + | == Example == | |
| + | <pre> | ||
| + | dilbegin nokill(); | ||
| + | var | ||
| + | pc : unitptr; | ||
| + | room : unitptr; | ||
| + | code | ||
| + | { | ||
| + | heartbeat := PULSE_SEC * 3; | ||
| − | + | :start: | |
| − | + | wait(SFB_COM, self.position == POSITION_FIGHTING); | |
| − | + | pc := self.fighting; | |
| − | + | room := self.outside.exit_to[SOUTH]; | |
| + | if ((pc == null) or (room == null)) | ||
| + | goto start; | ||
| + | if (pc.level >= IMMORTAL_LEVEL) | ||
| + | goto start; | ||
| − | + | act("Black-covered shapes drag $1n out of the guild.", | |
| − | + | A_SOMEONE, pc, null, null, TO_ROOM); | |
| − | + | act("Black-covered shapes drag you out of the guild!", | |
| − | + | A_SOMEONE, pc, null, null, TO_CHAR); | |
| + | stop_fighting(pc, null); | ||
| + | link(pc, room); | ||
| + | goto start; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | A guild master whose guards throw out anyone who fights him, after nokill in assassin.zon. | ||
| − | See also: | + | == See also == |
| − | + | * [[Manual:DIL Manual/wait()|wait()]] | |
| + | * [[Manual:DIL Manual/fighting|fighting]] | ||
| + | * [[Manual:DIL Manual/SFB PRE|SFB_PRE]] | ||
| + | * [[Manual:DIL Manual/SFB DEAD|SFB_DEAD]] | ||
| + | * [[Manual:DIL Manual/aware|aware]] | ||
Latest revision as of 23:24, 14 November 2026
SFB_COM
Constant (integer, vme.h: 0x0020).
wait(SFB_COM, condition)
The combat event. It is sent every time a character makes a melee attack, after the attack is rolled and before its damage is worked out (a fumble sends none). A program waiting with SFB_COM wakes for every attack made near it; its unit doesn't have to be in the fight.
What the event holds
| Variable | Value |
|---|---|
| activator | the character making the attack |
| argument | empty |
| command(CMD_AUTO_COMBAT) | TRUE |
| medium, target | null: the one attacked is activator.fighting
|
Notes
- The event reaches the same units as a command (see SFB_CMD): the attacker's room, what the attacker carries and wears, and the others in the room.
- A program doesn't get the attacks of its own unit unless it is declared
aware. A monster that wants to act on its own attacks needsaware; to act when it is attacked, checkself.fightingorself.position == POSITION_FIGHTING. - In a fight of several rounds the event comes often: keep the condition of the
wait()narrow. - To change the damage of a hit, use
SFB_PREwithcommand(CMD_AUTO_DAMAGE)instead.
Example
dilbegin nokill();
var
pc : unitptr;
room : unitptr;
code
{
heartbeat := PULSE_SEC * 3;
:start:
wait(SFB_COM, self.position == POSITION_FIGHTING);
pc := self.fighting;
room := self.outside.exit_to[SOUTH];
if ((pc == null) or (room == null))
goto start;
if (pc.level >= IMMORTAL_LEVEL)
goto start;
act("Black-covered shapes drag $1n out of the guild.",
A_SOMEONE, pc, null, null, TO_ROOM);
act("Black-covered shapes drag you out of the guild!",
A_SOMEONE, pc, null, null, TO_CHAR);
stop_fighting(pc, null);
link(pc, room);
goto start;
}
dilend
A guild master whose guards throw out anyone who fights him, after nokill in assassin.zon.