Difference between revisions of "Manual:DIL Manual/meleeattack()"

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="bfmelee"></span>
+
= meleeattack() =
−
integer meleeattack ( ch : unitptr, vict : unitptr,
+
'''Function''' (integer). Makes a character attack another once in melee, starting a fight.
−
                      bonus : integer, wtype : integer )
 
−
    ch    : The character which should make an additional attack.
 
−
    vict  : The victim of the attack.
 
−
    bonus : Any penalty or bonus added to the attack.
 
−
    wtype : The weapon type of the attack, if a valid type then that is
 
−
            used for the attack purpose, otherwise the default weapon/hand
 
−
            attack is used.
 
  
−
    result: 'ch' performs a melee attack (using whatever weapon is wielded
+
meleeattack(att : unitptr, def : unitptr, bonus : integer, wtype : integer, primary : integer) : integer
−
            or his bare hands) against 'vict'. Returns the amount of damage
 
−
            given (-1 is failed).
 
  
−
    If wtype is within a valid weapon range (WPN_XXX) any weapon will
+
<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.
−
    be bypassed, and the value will be used as the attacktype. Good
 
−
    for things like "meleeattack(ch, vict, bonus, WPN_CIRCLE_KICK)"
 
−
    if you want person to be able to perform an extra attack even
 
−
    though wielding a weapon or something. Note that this will require
 
−
    BOTH a weapon type WPN_CIRCLE_KICK and a skill "kick" in order for
 
−
    it to work.
 
−
<span id="bfmelee"></span>
 
−
integer meleeattack ( ch : unitptr, vict : unitptr,
 
−
                      bonus : integer, wtype : integer )
 
−
    ch    : The character which should make an additional attack.
 
−
    vict  : The victim of the attack.
 
−
    bonus : Any penalty or bonus added to the attack.
 
−
    wtype : The weapon type of the attack, if a valid type then that is
 
−
            used for the attack purpose, otherwise the default weapon/hand
 
−
            attack is used.
 
  
−
    result: 'ch' performs a melee attack (using whatever weapon is wielded
+
== Parameters ==
−
            or his bare hands) against 'vict'. Returns the amount of damage
+
{| class="wikitable"
−
            given (-1 is failed).
+
! 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.
 +
|}
  
−
    If wtype is within a valid weapon range (WPN_XXX) any weapon will
+
== Returns ==
−
    be bypassed, and the value will be used as the attacktype. Good
+
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.
−
    for things like "meleeattack(ch, vict, bonus, WPN_CIRCLE_KICK)"
+
 
−
    if you want person to be able to perform an extra attack even
+
== Notes ==
−
    though wielding a weapon or something. Note that this will require
+
* 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.
−
    BOTH a weapon type WPN_CIRCLE_KICK and a skill "kick" in order for
+
* The attack costs combat time like an ordinary blow (the weapon's speed), and the dual-wield penalty applies.
−
    it to work.
+
* 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_attack first. 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; primary is 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.

See also