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

From DikuMUD Wiki
Jump to navigation Jump to search
(checked against the compiler and the interpreter; example compiles)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
= SFB_COM =
 
= SFB_COM =
 +
'''Constant''' (integer, vme.h: 0x0020).
  
−
SFB_COM is a combat message that is sent during combat.
+
wait(SFB_COM, condition)
  
−
When this flag is used in a wait() statement, it will trigger on combat messages.
+
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.
−
The unit containing the DIL program needs not be involved in the combat itself,
 
−
it will react to any combat in it's local environment. The combat message is sent
 
−
just prior to the hit.
 
  
−
Only the following global value is set in a SFB_COM combat message:
+
== What the event holds ==
−
  'activator' : is a unitptr to the PC/NPC about to hit someone else.
+
{| 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>
 +
|}
  
−
Note that:
+
== Notes ==
−
  command(CMD_AUTO_COMBAT)  
+
* 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.
  
−
will evaluate to TRUE.
+
== Example ==
 +
<pre>
 +
dilbegin nokill();
 +
var
 +
  pc : unitptr;
 +
  room : unitptr;
 +
code
 +
{
 +
  heartbeat := PULSE_SEC * 3;
  
−
Example:
+
  :start:
−
  wait(SFB_COM, activator == self);
+
  wait(SFB_COM, self.position == POSITION_FIGHTING);
  
−
Example:
+
  pc := self.fighting;
−
  wait(SFB_COM, activator == self.fighting);
+
  room := self.outside.exit_to[SOUTH];
 +
  if ((pc == null) or (room == null))
 +
      goto start;
 +
  if (pc.level >= IMMORTAL_LEVEL)
 +
      goto start;
  
−
Example:
+
  act("Black-covered shapes drag $1n out of the guild.",
−
  wait(SFB_ALL, TRUE);
+
      A_SOMEONE, pc, null, null, TO_ROOM);
−
  if (command(CMD_AUTO_COMBAT))
+
  act("Black-covered shapes drag you out of the guild!",
−
    exec("flee", self);
+
      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.
  
−
You may want to take a look at the DIL vorpalweapon() in one of the distribution zones.
+
== See also ==
−
 
+
* [[Manual:DIL Manual/wait()|wait()]]
−
See also:
+
* [[Manual:DIL Manual/fighting|fighting]]
−
  > wait
+
* [[Manual:DIL Manual/SFB PRE|SFB_PRE]]
−
  > SFB_PRE
+
* [[Manual:DIL Manual/SFB DEAD|SFB_DEAD]]
−
  > CMD_AUTO_DAMAGE
+
* [[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 needs aware; to act when it is attacked, check self.fighting or self.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_PRE with command(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.

See also