Difference between revisions of "Manual:DIL Manual/set fighting()"
Jump to navigation
Jump to search
(XML import) |
(corrected from the DIL keyword tests (T029-T043)) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | + | = set_fighting() = | |
| − | + | '''Procedure.''' Starts a fight between two characters. | |
| − | |||
| − | |||
| − | + | set_fighting(u : unitptr, t : unitptr) | |
| − | |||
| − | |||
| − | + | 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 |
| − | + | fighting already, <code>t</code> joins its opponents, but <code>u</code> goes on hitting the one | |
| − | + | it was hitting. No blow is struck now: the combat rounds that follow do that. | |
| − | |||
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| − | + | ! 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()]] | ||
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
uist, 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.