Manual:DIL Manual/can carry()

From DikuMUD Wiki
Jump to navigation Jump to search

can carry()

Function (integer). Tells whether a character can carry more of something, and if not, why.

can_carry(ch : unitptr, u : unitptr, n : integer)

Checks whether ch could take n units like u on top of what it carries: first the number of items, then the weight. It doesn't move anything; link() doesn't check these limits, so check before you hand something over.

Parameters

Name Type Meaning
ch unitptr The character (PC or NPC) that would carry it.
u unitptr The unit it would carry; its weight counts.
n integer How many such units, 1 or more.

Returns

Integer:

  • 0: it can carry them;
  • 1: too many items (the hands are full);
  • 2: too heavy.

It fails when ch is null or not a character, u is null, or n is below 1: i := can_carry(...) then leaves i as it was.

Notes

  • 0 means yes, so if (can_carry(pc, item, 1)) is true when the character can't
 take it.
  • The item limit is 10 + Dex/10 items. Equipped items and money don't count.
  • The weight limit is 50 + the larger of 50 and half the character's
 baseweight, + 2 × Str. It is compared with the weight the character carries
 (the contents, not its own body) plus n × u.weight.

Example

dilbegin integer hand_over(pc : unitptr, item : unitptr);
var
   i : integer;
code
{
   i := can_carry(pc, item, 1);
   if (i == 1)
   {
      act("Your hands are full.", A_ALWAYS, pc, null, null, TO_CHAR);
      return(FALSE);
   }
   if (i == 2)
   {
      act("$2n is too heavy for you.", A_ALWAYS, pc, item, null, TO_CHAR);
      return(FALSE);
   }

   link(item, pc);
   act("$3n hands you $2n.", A_ALWAYS, pc, item, self, TO_CHAR);
   return(TRUE);
}
dilend

A helper that hands an item to a player only if they can take it, like the clan chest in clans.zon.

See also