Manual:DIL Manual/opponent()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:08, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

opponent()

Function (integer). Tells whether two characters are fighting each other.

opponent(ch : unitptr, vict : unitptr)

A character in a fight has a list of opponents: everyone fighting it and everyone it fights. It melee-attacks only one of them, the one in its fighting field. opponent() looks in the whole list, so it is also true for an opponent that is not the melee target.

Parameters

Name Type Meaning
ch unitptr The character whose opponents are checked.
vict unitptr The character looked for among them.

Returns

TRUE when vict is among ch's opponents, FALSE when it isn't or ch is not fighting. It fails when either unit is null or not a character (false in an if).

Notes

  • Opponents always come in pairs: when one character gets the other as an opponent, the other gets it too. So opponent(a, b) and opponent(b, a) give the same answer.
  • The number of opponents is opponentcount; getopponent() gets each of them.

Example

dilbegin hit_back(victim : unitptr, ch : unitptr);
code
{
   if (victim.position <= POSITION_SLEEPING)
      return;
   if (opponent(victim, ch))
      return;
   set_fighting(victim, ch);
}
dilend

Makes a victim who is awake fight back, unless the two are already fighting, as provoked_attack does in skills.zon.

See also