Difference between revisions of "Manual:DIL Manual/set fighting()"

From DikuMUD Wiki
Jump to navigation Jump to search
(checked against the compiler and the interpreter; example compiles)
(corrected from the DIL keyword tests (T029-T043))
 
Line 4: Line 4:
 
  set_fighting(u : unitptr, t : unitptr)
 
  set_fighting(u : unitptr, t : unitptr)
  
−
Makes <code>u</code> fight <code>t</code>, and <code>t</code> fight <code>u</code>. If
+
Makes <code>u</code> fight <code>t</code>. <code>t</code> gets <code>u</code> as an opponent (its <code>opponentcount</code> and <code>opponent()</code> show it), but its own <code>fighting</code> stays null, and its position unchanged, until its first combat round picks whom to hit. If
 
<code>u</code> isn't fighting yet, <code>t</code> becomes the one it hits. If <code>u</code> is
 
<code>u</code> isn't fighting yet, <code>t</code> becomes the one it hits. If <code>u</code> is
 
fighting already, <code>t</code> joins its opponents, but <code>u</code> goes on hitting the one
 
fighting already, <code>t</code> joins its opponents, but <code>u</code> goes on hitting the one

Latest revision as of 07:21, 15 November 2026

set_fighting()

Procedure. Starts a fight between two characters.

set_fighting(u : unitptr, t : unitptr)

Makes u fight t. t gets u as an opponent (its opponentcount and opponent() show it), but its own fighting stays null, and its position unchanged, until its first combat round picks whom to hit. If u isn't fighting yet, t becomes the one it hits. If u is fighting already, t joins its opponents, but u goes on hitting the one it was hitting. No blow is struck now: the combat rounds that follow do that.

Parameters

Name Type Meaning
u unitptr The attacker.
t unitptr The one attacked.

Notes

  • Both must be characters (players or NPCs). Otherwise, or when either is null, or u is t, nothing happens.
  • u's position becomes fighting, even if it was asleep. t's position isn't changed.
  • It checks nothing else: not whether the two are in the same room, can see each other, or may fight at all (player killing, CHAR_PEACEFUL). Check that first.
  • It gives no message; use act().

Example

dilbegin no_backstab();
var
   pc : unitptr;
code
{
   :start:
   wait(SFB_CMD, command("backstab") and (activator.type == UNIT_ST_PC) and
                 (self.position >= POSITION_RESTING));
   pc := activator;
   secure(pc, start);
   block;
   act("$3n turns around just in time!", A_SOMEONE, pc, null, self, TO_CHAR);
   act("$3n turns around and catches $1n!", A_SOMEONE, pc, null, self, TO_REST);
   set_fighting(self, pc);
   unsecure(pc);
   goto start;
}
dilend

An NPC that can't be backstabbed: it blocks the command and attacks the player, as command_block in basis.zon does.

See also