Difference between revisions of "Manual:DIL Manual/meleeattack()"
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = meleeattack() = | |
| − | + | '''Function''' (integer). Makes a character attack another once in melee, starting a fight. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | meleeattack(att : unitptr, def : unitptr, bonus : integer, wtype : integer, primary : integer) : integer | |
| − | |||
| − | |||
| − | + | <code>att</code> makes one ordinary melee attack on <code>def</code>: hit roll, armour, shield, damage and the usual combat messages, exactly as a round of combat does. It's how skills like kick and bash do their damage. If <code>att</code> isn't fighting yet, the attack starts the fight, and <code>att</code> is set to the fighting position. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | < | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| − | + | ! Name !! Type !! Meaning | |
| + | |- | ||
| + | | att || unitptr || The attacking character. | ||
| + | |- | ||
| + | | def || unitptr || The character attacked. | ||
| + | |- | ||
| + | | bonus || integer || Added to the attack's hit roll (negative for a penalty). | ||
| + | |- | ||
| + | | wtype || integer || A weapon type <code>WPN_*</code> from <code>vme/include/values.h</code> (such as <code>WPN_KICK</code>, <code>WPN_BITE</code>, <code>WPN_FIST</code>) to attack with that type and the attacker's skill in it, ignoring any weapon. Any other value, such as 0 (<code>WPN_ROOT</code>) or -1, attacks with the weapon (see <code>primary</code>). | ||
| + | |- | ||
| + | | primary || integer || When <code>wtype</code> isn't a weapon type: TRUE uses the weapon in <code>WEAR_WIELD</code>, FALSE the one in <code>WEAR_HOLD</code> (an off-hand attack). Without that weapon, the character's natural attack is used. | ||
| + | |} | ||
| − | + | == Returns == | |
| − | + | The damage done; 0 for a miss, a fumble or a blow the shield took. -1 when no attack happened: <code>att</code> is incapacitated (below sleeping), <code>def</code> is dead, they are the same unit, or they aren't in the same place. When either unit is null or not a character, the call fails and the variable assigned keeps its old value. | |
| − | + | ||
| − | + | == Notes == | |
| − | + | * A weapon type is a value from 7 (<code>WPN_GROUP_MAX</code>) to 199. The group values 0 to 6 (<code>WPN_ROOT</code>, <code>WPN_UNARMED</code>, <code>WPN_SPECIAL</code>...) are not weapon types: <code>meleeattack(self, u, 0, WPN_UNARMED, TRUE)</code> hits with the wielded weapon. | |
| − | + | * The attack costs combat time like an ordinary blow (the weapon's speed), and the dual-wield penalty applies. | |
| − | + | * A sleeping victim is always hit. | |
| + | * It doesn't check whether the attack is allowed, such as in a peaceful room; skills in skills.zon call <code>provoked_attack</code> first. When neither may attack the other under the player-killing rules, the blow does 0 damage. | ||
| + | * The blow can kill <code>def</code>. Afterwards the program's secures are checked at once, so a secure on the victim can jump to its label. | ||
| + | * The draft and older manual versions show four arguments; <code>primary</code> is required. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin bite_foe(); | ||
| + | var | ||
| + | u : unitptr; | ||
| + | i : integer; | ||
| + | code | ||
| + | { | ||
| + | heartbeat := PULSE_SEC * 6; | ||
| + | :loop: | ||
| + | wait(SFB_TICK, self.fighting != null); | ||
| + | u := self.fighting; | ||
| + | if (rnd(1, 100) <= 25) | ||
| + | { | ||
| + | act("$1n bares $1s teeth!", A_SOMEONE, self, null, null, TO_ROOM); | ||
| + | i := meleeattack(self, u, 75, WPN_BITE, TRUE); | ||
| + | } | ||
| + | goto loop; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | An NPC that sometimes bites its opponent as an extra attack; the spiders in haon_dor.zon bite the same way. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/meleedamage()|meleedamage()]] | ||
| + | * [[Manual:DIL Manual/equipment()|equipment()]] | ||
| + | * [[Manual:DIL Manual/set fighting()|set fighting()]] | ||
| + | * [[Manual:DIL Manual/fighting|fighting]] | ||
| + | * [[Manual:DIL Manual/weapons|weapons]] | ||
Latest revision as of 23:17, 14 November 2026
meleeattack()
Function (integer). Makes a character attack another once in melee, starting a fight.
meleeattack(att : unitptr, def : unitptr, bonus : integer, wtype : integer, primary : integer) : integer
att makes one ordinary melee attack on def: hit roll, armour, shield, damage and the usual combat messages, exactly as a round of combat does. It's how skills like kick and bash do their damage. If att isn't fighting yet, the attack starts the fight, and att is set to the fighting position.
Parameters
| Name | Type | Meaning |
|---|---|---|
| att | unitptr | The attacking character. |
| def | unitptr | The character attacked. |
| bonus | integer | Added to the attack's hit roll (negative for a penalty). |
| wtype | integer | A weapon type WPN_* from vme/include/values.h (such as WPN_KICK, WPN_BITE, WPN_FIST) to attack with that type and the attacker's skill in it, ignoring any weapon. Any other value, such as 0 (WPN_ROOT) or -1, attacks with the weapon (see primary).
|
| primary | integer | When wtype isn't a weapon type: TRUE uses the weapon in WEAR_WIELD, FALSE the one in WEAR_HOLD (an off-hand attack). Without that weapon, the character's natural attack is used.
|
Returns
The damage done; 0 for a miss, a fumble or a blow the shield took. -1 when no attack happened: att is incapacitated (below sleeping), def is dead, they are the same unit, or they aren't in the same place. When either unit is null or not a character, the call fails and the variable assigned keeps its old value.
Notes
- A weapon type is a value from 7 (
WPN_GROUP_MAX) to 199. The group values 0 to 6 (WPN_ROOT,WPN_UNARMED,WPN_SPECIAL...) are not weapon types:meleeattack(self, u, 0, WPN_UNARMED, TRUE)hits with the wielded weapon. - The attack costs combat time like an ordinary blow (the weapon's speed), and the dual-wield penalty applies.
- A sleeping victim is always hit.
- It doesn't check whether the attack is allowed, such as in a peaceful room; skills in skills.zon call
provoked_attackfirst. When neither may attack the other under the player-killing rules, the blow does 0 damage. - The blow can kill
def. Afterwards the program's secures are checked at once, so a secure on the victim can jump to its label. - The draft and older manual versions show four arguments;
primaryis required.
Example
dilbegin bite_foe();
var
u : unitptr;
i : integer;
code
{
heartbeat := PULSE_SEC * 6;
:loop:
wait(SFB_TICK, self.fighting != null);
u := self.fighting;
if (rnd(1, 100) <= 25)
{
act("$1n bares $1s teeth!", A_SOMEONE, self, null, null, TO_ROOM);
i := meleeattack(self, u, 75, WPN_BITE, TRUE);
}
goto loop;
}
dilend
An NPC that sometimes bites its opponent as an extra attack; the spiders in haon_dor.zon bite the same way.