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

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="bffits"></span>
+
= fits() =
−
string fits( char : unitptr, obj : unitptr, pos : integer );
+
'''Function''' (string). Tells whether an object is the right size for a character.
−
    char: Character which we want to test if obj can be fitted upon
 
−
    obj:  The object we want to see if fits char.
 
−
    pos:  -1 or WEAR_XXX
 
−
    Returns: Empty string if ok, or a textual description of the size problem.
 
  
−
    Fits tests if "obj" can be worn by "char" in position "pos". If
+
fits(ch : unitptr, obj : unitptr, pos : integer)
−
    pos is -1, then fits automatically figures out the default worn
 
−
    position for "obj".
 
  
−
    Example:
+
Compares the size (<code>height</code>) of <code>obj</code> with that of <code>ch</code> for
 +
wearing it in position <code>pos</code>, and returns <code>""</code> when it fits or a few words
 +
saying why not.
  
−
      s := fits(self, obj, -1);
+
== Parameters ==
−
      if (s != "")
+
{| class="wikitable"
−
        exec("say Don't buy it, its "+s, self);
+
! Name !! Type !! Meaning
−
<span id="bffits"></span>
+
|-
−
string fits( char : unitptr, obj : unitptr, pos : integer );
+
| ch || unitptr || The character (PC or NPC) who would wear it.
−
    char: Character which we want to test if obj can be fitted upon
+
|-
−
    obj:  The object we want to see if fits char.
+
| obj || unitptr || The object.
−
    pos:  -1 or WEAR_XXX
+
|-
−
    Returns: Empty string if ok, or a textual description of the size problem.
+
| pos || integer || A <code>WEAR_*</code> position from <code>vme.h</code>, or -1 for the position the object is made for (from its <code>manipulate</code> flags).
 +
|}
  
−
    Fits tests if "obj" can be worn by "char" in position "pos". If
+
== Returns ==
−
    pos is -1, then fits automatically figures out the default worn
+
String: <code>""</code> when it fits, otherwise ''way too small'', ''too small'', ''too large''
−
    position for "obj".
+
or ''way too large'' (and ''error'' when the character's height is 0). It fails when
 +
<code>ch</code> is null or not a character, or <code>obj</code> is null or not an object.
  
−
    Example:
+
== Notes ==
 +
* The object's height is taken as a percentage of the character's. For most positions it fits
 +
  from 50% to 150%: below 25% is ''way too small'', above 225% ''way too large''. Body armour
 +
  (<code>WEAR_BODY</code>) is stricter: 60% to 140%, ''way'' below 30% or above 210%.
 +
* An object with no height (0) is ''way too small'' for everyone.
 +
* Always <code>""</code> for something not worn in that position: an object that can't be
 +
  worn with -1, a held object that isn't a weapon (<code>WEAR_HOLD</code>), or a
 +
  <code>pos</code> that isn't a <code>WEAR_*</code> value.
 +
* It only checks the size, not whether the position is free or the character may use it.
  
−
      s := fits(self, obj, -1);
+
== Example ==
−
      if (s != "")
+
<pre>
−
        exec("say Don't buy it, its "+s, self);
+
dilbegin string fit_note(pc : unitptr, item : unitptr);
 +
var
 +
  s : string;
 +
code
 +
{
 +
  s := fits(pc, item, -1);
 +
  if (s == "")
 +
      return("");
 +
  return("(" + s + " for you) ");
 +
}
 +
dilend
 +
</pre>
 +
A note for a shop list when an item doesn't fit the customer, as the shops in function.zon
 +
show it.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/height|height]]
 +
* [[Manual:DIL Manual/equipment()|equipment()]]
 +
* [[Manual:DIL Manual/addequip()|addequip()]]
 +
* [[Manual:DIL Manual/manipulate|manipulate]]

Latest revision as of 23:04, 14 November 2026

fits()

Function (string). Tells whether an object is the right size for a character.

fits(ch : unitptr, obj : unitptr, pos : integer)

Compares the size (height) of obj with that of ch for wearing it in position pos, and returns "" when it fits or a few words saying why not.

Parameters

Name Type Meaning
ch unitptr The character (PC or NPC) who would wear it.
obj unitptr The object.
pos integer A WEAR_* position from vme.h, or -1 for the position the object is made for (from its manipulate flags).

Returns

String: "" when it fits, otherwise way too small, too small, too large or way too large (and error when the character's height is 0). It fails when ch is null or not a character, or obj is null or not an object.

Notes

  • The object's height is taken as a percentage of the character's. For most positions it fits
 from 50% to 150%: below 25% is way too small, above 225% way too large. Body armour
 (WEAR_BODY) is stricter: 60% to 140%, way below 30% or above 210%.
  • An object with no height (0) is way too small for everyone.
  • Always "" for something not worn in that position: an object that can't be
 worn with -1, a held object that isn't a weapon (WEAR_HOLD), or a
 pos that isn't a WEAR_* value.
  • It only checks the size, not whether the position is free or the character may use it.

Example

dilbegin string fit_note(pc : unitptr, item : unitptr);
var
   s : string;
code
{
   s := fits(pc, item, -1);
   if (s == "")
      return("");
   return("(" + s + " for you) ");
}
dilend

A note for a shop list when an item doesn't fit the customer, as the shops in function.zon show it.

See also