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

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
Line 1: Line 1:
−
<span id="bpsetfight"></span>
+
= set_fighting() =
−
set_fighting( u : unitptr, t : unitptr )
+
'''Procedure.''' Starts a fight between two characters.
−
    u : the unit on which attacks.
 
−
    t : the unit being attacked.
 
  
−
    This is used to set two characters fighting. If the attacker is
+
set_fighting(u : unitptr, t : unitptr)
−
    fighting already, the target will simply be inserted into the
 
−
    opponent list and perhaps killed a little later.
 
  
−
---~---~---~---~---~---~---~---~---
+
Makes <code>u</code> fight <code>t</code>, and <code>t</code> fight <code>u</code>. If
−
<span id="bpsetfight"></span>
+
<code>u</code> isn't fighting yet, <code>t</code> becomes the one it hits. If <code>u</code> is
−
set_fighting( u : unitptr, t : unitptr )
+
fighting already, <code>t</code> joins its opponents, but <code>u</code> goes on hitting the one
−
    u : the unit on which attacks.
+
it was hitting. No blow is struck now: the combat rounds that follow do that.
−
    t : the unit being attacked.
 
  
−
    This is used to set two characters fighting. If the attacker is
+
== Parameters ==
−
    fighting already, the target will simply be inserted into the
+
{| class="wikitable"
−
    opponent list and perhaps killed a little later.
+
! 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 <code>u</code> is <code>t</code>, nothing happens.
 +
* <code>u</code>'s position becomes fighting, even if it was asleep. <code>t</code>'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, <code>CHAR_PEACEFUL</code>). Check that first.
 +
* It gives no message; use [[Manual:DIL Manual/act()|act()]].
 +
 
 +
== Example ==
 +
<pre>
 +
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
 +
</pre>
 +
An NPC that can't be backstabbed: it blocks the command and attacks the player, as <code>command_block</code> in basis.zon does.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/stop fighting()|stop_fighting()]]
 +
* [[Manual:DIL Manual/fighting|fighting]]
 +
* [[Manual:DIL Manual/opponent()|opponent()]]
 +
* [[Manual:DIL Manual/opponentcount|opponentcount]]
 +
* [[Manual:DIL Manual/change speed()|change_speed()]]

Revision as of 23:21, 14 November 2026

set_fighting()

Procedure. Starts a fight between two characters.

set_fighting(u : unitptr, t : unitptr)

Makes u fight t, and t fight u. 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