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

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="bfeq"></span>
+
= equipment() =
−
  unitptr equipment ( u : unitptr , i : integer )
+
'''Function''' (unitptr). The object a character wears or wields in a given position.
−
    u : The character to search.
+
 
−
    i : What equipment to find, any of the WEAR_XXX macros.
+
  equipment(ch : unitptr, pos : integer) : unitptr
−
    result: Returns the unit on 'u' which is equipped on position 'i'.
+
 
−
            See WEAR_* in values.h and/or vme.h
+
Looks through what <code>ch</code> carries and returns the first object that is equipped in position <code>pos</code>, or null when nothing is there.
−
<span id="bfeq"></span>
+
 
−
unitptr equipment ( u : unitptr , i : integer )
+
== Parameters ==
−
    u : The character to search.
+
{| class="wikitable"
−
    i : What equipment to find, any of the WEAR_XXX macros.
+
! Name !! Type !! Meaning
−
    result: Returns the unit on 'u' which is equipped on position 'i'.
+
|-
−
            See WEAR_* in values.h and/or vme.h
+
| ch || unitptr || The character (player or NPC) to look at.
 +
|-
 +
| pos || integer || A <code>WEAR_*</code> position from <code>vme/include/vme.h</code>, such as <code>WEAR_WIELD</code>, <code>WEAR_HOLD</code>, <code>WEAR_SHIELD</code>, <code>WEAR_BODY</code> or <code>WEAR_FINGER_R</code>.
 +
|}
 +
 
 +
== Returns ==
 +
The equipped object, or null when that position is empty. When <code>ch</code> is null or not a character, the call fails: a variable it is assigned to keeps its old value.
 +
 
 +
== Notes ==
 +
* The position is read as a number from 0 to 255. Position 0 means "not equipped", so <code>equipment(ch, 0)</code> returns the first object in the inventory that isn't worn. Use <code>WEAR_*</code> values only.
 +
* It doesn't check the object's type: <code>equipment(ch, WEAR_WIELD)</code> can be something other than a weapon.
 +
* The position of an object itself is its <code>equip</code> field.
 +
 
 +
== Example ==
 +
<pre>
 +
dilbegin show_wielded();
 +
var
 +
  wpn : unitptr;
 +
code
 +
{
 +
  wpn := equipment(self, WEAR_WIELD);
 +
  if (wpn == null)
 +
      sendtext("You wield nothing.<br/>", self);
 +
  else
 +
      act("You wield $2n.", A_ALWAYS, self, wpn, null, TO_CHAR);
 +
  quit;
 +
}
 +
dilend
 +
</pre>
 +
Tells the character what it is wielding.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/equip|equip]]
 +
* [[Manual:DIL Manual/addequip()|addequip()]]
 +
* [[Manual:DIL Manual/unequip()|unequip()]]
 +
* [[Manual:DIL Manual/meleeattack()|meleeattack()]]

Latest revision as of 23:17, 14 November 2026

equipment()

Function (unitptr). The object a character wears or wields in a given position.

equipment(ch : unitptr, pos : integer) : unitptr

Looks through what ch carries and returns the first object that is equipped in position pos, or null when nothing is there.

Parameters

Name Type Meaning
ch unitptr The character (player or NPC) to look at.
pos integer A WEAR_* position from vme/include/vme.h, such as WEAR_WIELD, WEAR_HOLD, WEAR_SHIELD, WEAR_BODY or WEAR_FINGER_R.

Returns

The equipped object, or null when that position is empty. When ch is null or not a character, the call fails: a variable it is assigned to keeps its old value.

Notes

  • The position is read as a number from 0 to 255. Position 0 means "not equipped", so equipment(ch, 0) returns the first object in the inventory that isn't worn. Use WEAR_* values only.
  • It doesn't check the object's type: equipment(ch, WEAR_WIELD) can be something other than a weapon.
  • The position of an object itself is its equip field.

Example

dilbegin show_wielded();
var
   wpn : unitptr;
code
{
   wpn := equipment(self, WEAR_WIELD);
   if (wpn == null)
      sendtext("You wield nothing.<br/>", self);
   else
      act("You wield $2n.", A_ALWAYS, self, wpn, null, TO_CHAR);
   quit;
}
dilend

Tells the character what it is wielding.

See also