Manual:DIL Manual/meleeattack()
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.