Manual:DIL Manual/weapon name()
Jump to navigation
Jump to search
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.