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)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 +
= fits() =
 +
'''Function''' (string). Tells whether an object is the right size for a character.
  
 +
fits(ch : unitptr, obj : unitptr, pos : integer)
  
−
<span id="bffits"></span>
+
Compares the size (<code>height</code>) of <code>obj</code> with that of <code>ch</code> for
−
string fits( char : unitptr, obj : unitptr, pos : integer );
+
wearing it in position <code>pos</code>, and returns <code>""</code> when it fits or a few words
−
    char: Character which we want to test if obj can be fitted upon
+
saying why not.
−
    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
+
== Parameters ==
−
    pos is -1, then fits automatically figures out the default worn
+
{| class="wikitable"
−
    position for "obj".
+
! Name !! Type !! Meaning
 +
|-
 +
| ch || unitptr || The character (PC or NPC) who would wear it.
 +
|-
 +
| obj || unitptr || The object.
 +
|-
 +
| 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).
 +
|}
  
−
    Example:
+
== Returns ==
 +
String: <code>""</code> 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
 +
<code>ch</code> is null or not a character, or <code>obj</code> is null or not an object.
  
−
      s := fits(self, obj, -1);
+
== Notes ==
−
      if (s != "")
+
* The object's height is taken as a percentage of the character's. For most positions it fits
−
        exec("say Don't buy it, its "+s, self);
+
  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.
 +
 
 +
== Example ==
 +
<pre>
 +
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