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

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_name"></span>
+
= weapon name() =
 +
'''Function''' (string). Gives the name of a weapon type from its number.
  
−
  '''Function:'''  <i><!--CODE-->string weapon_name( i : integer ) ;</i><!--ENDCODE-->
+
  weapon_name(i : integer)
  
−
<!--TERM--> '''i'''
+
The weapon numbers are the <code>WPN_</code> constants in <code>vme/include/values.h</code>, for example <code>WPN_DAGGER</code> (20). A weapon object's type is its <code>value[0]</code>. The names come from the <code>name</code> lines in <code>vme/etc/weapons.def</code>, in lower case: <code>weapon_name(WPN_DAGGER)</code> is "dagger". Numbers 0 to 6 are the weapon groups (<code>WPN_ROOT</code> to <code>WPN_SPECIAL</code> in <code>vme/include/vme.h</code>), with names like "category sword".
−
<!--DEFINITION-->         Weapon to get the name of ass defined in 'values.h' and 'weapons.def'
 
−
<!--TERM--> '''returns'''
 
−
<!--DEFINITION-->         The name of the weapon that corresponds with the integer value
 
  
−
'''example:'''
+
== Parameters ==
−
<i><!--CODE-->
+
{| class="wikitable"
−
---~---~---~---~---~---~---~---~---
+
! Name !! Type !! Meaning
 +
|-
 +
| i || integer || The weapon number.
 +
|}
  
−
myweap:=weapon_name(5);
+
== Returns ==
 +
The weapon's name; "" when the number is in range but has no weapon. Outside 0 to 199 (<code>WPN_TREE_MAX</code> - 1) it gives null.
  
−
---~---~---~---~---~---~---~---~---
+
== Notes ==
 +
* The null outside the range is how the weapons list in commands.zon finds the end: <code>while (weapon_name(i) != null)</code>. Assigned to a string variable, null makes it "".
 +
* Don't put a number that may be out of range straight into <code>+</code>: <code>"a " + weapon_name(i)</code> with a null makes an error that stops the program. [[Manual:DIL Manual/skill name()|skill name()]] gives "" instead and has no such trap.
  
−
</i><!--ENDCODE-->
+
== Example ==
−
<span id="bfweapon_name"></span>
+
<pre>
 +
dilbegin string weapon_kind(item : unitptr);
 +
code
 +
{
 +
  if (item.objecttype != ITEM_WEAPON)
 +
      return ("");
 +
  return (weapon_name(item.value[0]));
 +
}
 +
dilend
 +
</pre>
 +
Gives the weapon type of an object, as the look code in baselook.zon does.
  
−
'''Function:'''  <i><!--CODE-->string weapon_name( i : integer ) ;</i><!--ENDCODE-->
+
== See also ==
−
 
+
* [[Manual:DIL Manual/skill name()|skill name()]]
−
<!--TERM-->  '''i'''
+
* [[Manual:DIL Manual/weapon info()|weapon info()]]
−
<!--DEFINITION-->        Weapon to get the name of ass defined in 'values.h' and 'weapons.def'
+
* [[Manual:DIL Manual/weapons|weapons]]
−
<!--TERM-->  '''returns'''
+
* [[Manual:DIL Manual/value|value]]
−
<!--DEFINITION-->        The name of the weapon that corresponds with the integer value
+
* [[Manual:DIL Manual/objecttype|objecttype]]
−
 
 
−
'''example:'''
 
−
<i><!--CODE-->
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
myweap:=weapon_name(5);
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
</i><!--ENDCODE-->
 

Latest revision as of 23:08, 14 November 2026

weapon name()

Function (string). Gives the name of a weapon type from its number.

weapon_name(i : integer)

The weapon numbers are the WPN_ constants in vme/include/values.h, for example WPN_DAGGER (20). A weapon object's type is its value[0]. The names come from the name lines in vme/etc/weapons.def, in lower case: weapon_name(WPN_DAGGER) is "dagger". Numbers 0 to 6 are the weapon groups (WPN_ROOT to WPN_SPECIAL in vme/include/vme.h), with names like "category sword".

Parameters

Name Type Meaning
i integer The weapon number.

Returns

The weapon's name; "" when the number is in range but has no weapon. Outside 0 to 199 (WPN_TREE_MAX - 1) it gives null.

Notes

  • The null outside the range is how the weapons list in commands.zon finds the end: while (weapon_name(i) != null). Assigned to a string variable, null makes it "".
  • Don't put a number that may be out of range straight into +: "a " + weapon_name(i) with a null makes an error that stops the program. skill name() gives "" instead and has no such trap.

Example

dilbegin string weapon_kind(item : unitptr);
code
{
   if (item.objecttype != ITEM_WEAPON)
      return ("");
   return (weapon_name(item.value[0]));
}
dilend

Gives the weapon type of an object, as the look code in baselook.zon does.

See also