Difference between revisions of "Manual:DIL Manual/weapon info()"

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="bfweapon_info"></span>
+
= weapon_info() =
 +
'''Function''' (intlist). The figures etc/weapons.def gives a weapon type.
  
−
  '''Function:'''  <i><!--CODE-->intlist weapon_info( i : integer ) ;</i><!--ENDCODE-->
+
  weapon_info(i : integer) : intlist
  
−
<!--TERM--> '''i'''
+
== Parameters ==
−
<!--DEFINITION-->         Weapon to get the info of ass defined in 'values.h' and 'weapons.def'
+
{| class="wikitable"
−
<!--TERM--> '''returns'''
+
! Name !! Type !! Meaning
−
<!--DEFINITION-->         Intlist containing 4 values:
+
|-
 +
| i || integer || A weapon type: one of the <code>WPN_</code> numbers in values.h. A weapon object (<code>ITEM_WEAPON</code>) holds its type in <code>value[0]</code>.
 +
|}
  
−
<!--TERM--> '''0'''
+
== Returns ==
−
<!--DEFINITION-->         Number of hands
+
A new intlist of 20 numbers:
−
<!--TERM--> '''1'''
+
{| class="wikitable"
−
<!--DEFINITION-->         weapon speed
+
! Index !! Meaning
−
<!--TERM--> '''2'''
+
|-
−
<!--DEFINITION-->         weapon type
+
| 0 || Hands: 1 for a one-handed weapon, 2 for a two-handed one.
−
<!--TERM--> '''3'''
+
|-
−
<!--DEFINITION-->         shield block value
+
| 1 || Speed (the <code>SPEED_</code> values defined in weapons.def).
 +
|-
 +
| 2 || Kind of damage: <code>WPNT_SLASH</code> 0, <code>WPNT_BLUDGEON</code> 1, <code>WPNT_PIERCE</code> 2, <code>WPNT_NONE</code> -1 for the weapon groups (spelldef.h).
 +
|-
 +
| 3 || What a shield does against it: <code>SHIELD_M_BLOCK</code> 0, <code>SHIELD_M_REDUCE</code> 1, <code>SHIELD_M_USELESS</code> 2 (vme.h).
 +
|-
 +
| 4 || The group it belongs to (its <code>sphere</code>), such as <code>WPN_AXE_HAM</code>.
 +
|-
 +
| 5 to 19 || Its <code>attack</code> lines: three numbers (offset, base damage, alpha) for each armour type in the order <code>ARM_CLOTHES</code>, <code>ARM_LEATHER</code>, <code>ARM_HLEATHER</code>, <code>ARM_CHAIN</code>, <code>ARM_PLATE</code> (vme.h). The offset for armour type a is at <code>5 + 3*a</code>.
 +
|}
 +
For a number below 0 or from <code>WPN_TREE_MAX</code> (200) up, it returns null: an empty list.
  
 +
== Notes ==
 +
* A number in range that weapons.def doesn't define gives the defaults: one hand, <code>WPNT_SLASH</code>, speed 0, <code>SHIELD_M_BLOCK</code>, group <code>WPN_ROOT</code>, and 100, 0, 100 for every armour type.
 +
* The list is a copy: changing it changes nothing in the game.
 +
* A weapon's abilities and fumble chance from weapons.def are not in the list.
 +
* The usual use is the hands: baselook.zon shows "two hand wielded" when <code>weapon_info(item.value[0]).[0]</code> is 2 (through a variable: a field or index can't follow a call directly).
  
−
This function gives you access to the values in the weapons.def file.
+
== Example ==
−
With this things like 'wear' equipment' and 'look' are much easier to
+
<pre>
−
write in Dil.
+
dilbegin integer two_handed(wpn : unitptr);
−
'''Example'''
+
var
−
<i><!--CODE-->
+
   il : intlist;
−
---~---~---~---~---~---~---~---~---
+
code
−
 
+
{
−
dilcopy id_weap (arg:string);
+
  if (wpn == null)
−
var
+
      return (FALSE);
−
   i:integer;
+
  if (wpn.objecttype != ITEM_WEAPON)
−
   il:intlist;
+
      return (FALSE);
−
code
+
   il := weapon_info(wpn.value[0]);
 +
  if (length(il) == 0)
 +
      return (FALSE);
 +
  return (il.[0] == 2);
 +
}
 
dilend
 
dilend
 +
</pre>
 +
Tells whether a unit is a two-handed weapon, as two_handed in commands.zon.
  
−
 
+
== See also ==
−
---~---~---~---~---~---~---~---~---
+
* [[Manual:DIL Manual/weapon name()|weapon name()]]
−
 
+
* [[Manual:DIL Manual/value|value]]
−
</i><!--ENDCODE-->
+
* [[Manual:DIL Manual/objecttype|objecttype]]
−
<span id="bfweapon_info"></span>
+
* [[Manual:DIL Manual/intlist|intlist]]
−
 
+
* [[Manual:DIL Manual/length()|length()]]
−
'''Function:'''  <i><!--CODE-->intlist weapon_info( i : integer ) ;</i><!--ENDCODE-->
 
−
 
 
−
<!--TERM-->  '''i'''
 
−
<!--DEFINITION-->        Weapon to get the info of ass defined in 'values.h' and 'weapons.def'
 
−
<!--TERM-->  '''returns'''
 
−
<!--DEFINITION-->        Intlist containing 4 values:
 
−
 
 
−
<!--TERM-->  '''0'''
 
−
<!--DEFINITION-->        Number of hands
 
−
<!--TERM-->  '''1'''
 
−
<!--DEFINITION-->        weapon speed
 
−
<!--TERM-->  '''2'''
 
−
<!--DEFINITION-->        weapon type
 
−
<!--TERM-->  '''3'''
 
−
<!--DEFINITION-->        shield block value
 
−
 
 
−
 
 
−
This function gives you access to the values in the weapons.def file.
 
−
With this things like 'wear' equipment' and 'look' are much easier to
 
−
write in Dil.
 
−
'''Example'''
 
−
<i><!--CODE-->
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
dilcopy id_weap (arg:string);
 
−
var
 
−
  i:integer;
 
−
  il:intlist;
 
−
code
 
−
dilend
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
</i><!--ENDCODE-->
 

Latest revision as of 23:19, 14 November 2026

weapon_info()

Function (intlist). The figures etc/weapons.def gives a weapon type.

weapon_info(i : integer) : intlist

Parameters

Name Type Meaning
i integer A weapon type: one of the WPN_ numbers in values.h. A weapon object (ITEM_WEAPON) holds its type in value[0].

Returns

A new intlist of 20 numbers:

Index Meaning
0 Hands: 1 for a one-handed weapon, 2 for a two-handed one.
1 Speed (the SPEED_ values defined in weapons.def).
2 Kind of damage: WPNT_SLASH 0, WPNT_BLUDGEON 1, WPNT_PIERCE 2, WPNT_NONE -1 for the weapon groups (spelldef.h).
3 What a shield does against it: SHIELD_M_BLOCK 0, SHIELD_M_REDUCE 1, SHIELD_M_USELESS 2 (vme.h).
4 The group it belongs to (its sphere), such as WPN_AXE_HAM.
5 to 19 Its attack lines: three numbers (offset, base damage, alpha) for each armour type in the order ARM_CLOTHES, ARM_LEATHER, ARM_HLEATHER, ARM_CHAIN, ARM_PLATE (vme.h). The offset for armour type a is at 5 + 3*a.

For a number below 0 or from WPN_TREE_MAX (200) up, it returns null: an empty list.

Notes

  • A number in range that weapons.def doesn't define gives the defaults: one hand, WPNT_SLASH, speed 0, SHIELD_M_BLOCK, group WPN_ROOT, and 100, 0, 100 for every armour type.
  • The list is a copy: changing it changes nothing in the game.
  • A weapon's abilities and fumble chance from weapons.def are not in the list.
  • The usual use is the hands: baselook.zon shows "two hand wielded" when weapon_info(item.value[0]).[0] is 2 (through a variable: a field or index can't follow a call directly).

Example

dilbegin integer two_handed(wpn : unitptr);
var
   il : intlist;
code
{
   if (wpn == null)
      return (FALSE);
   if (wpn.objecttype != ITEM_WEAPON)
      return (FALSE);
   il := weapon_info(wpn.value[0]);
   if (length(il) == 0)
      return (FALSE);
   return (il.[0] == 2);
}
dilend

Tells whether a unit is a two-handed weapon, as two_handed in commands.zon.

See also