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

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import of LLM wiki pages)
(checked against the compiler and the interpreter; example compiles)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
= SFB_COM =
 +
'''Constant''' (integer, vme.h: 0x0020).
  
 +
wait(SFB_COM, condition)
  
−
<span id="sfbcom"></span>
+
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.
−
SFB_COM            Combat message
 
  
−
  When this flag is set, the routine gets activated whenever a combat is in
+
== What the event holds ==
−
  progress. The unit containing the DIL program needs not be involved in the
+
{| class="wikitable"
−
  combat itself:
+
! 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>
 +
|}
  
−
      'activator'... is a unitptr to the PC/NPC about to hit someone else.
+
== Notes ==
−
      'argument'.... is empty.
+
* 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.
  
−
      command(CMD_AUTO_COMBAT) will evaluate to TRUE.
+
== 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 ==
 +
* [[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 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