Manual:DIL Manual/purse()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:08, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

purse()

Function (integer). Counts the coins of one kind that a unit carries.

purse(u : unitptr, coin : string)

The coin kind is given by its abbreviation from vme/etc/money. vme/include/vme.h has a name for each:

Constant Abbreviation Value of one coin
IRON_PIECE "ip" IRON_MULT (10)
COPPER_PIECE "cp" COPPER_MULT (80)
SILVER_PIECE "sp" SILVER_MULT (640)
GOLD_PIECE "gp" GOLD_MULT (5120)
PLATINUM_PIECE "pp" PLATINUM_MULT (40960)

Parameters

Name Type Meaning
u unitptr The unit whose inventory is searched: a character, a container or a room.
coin string The coin abbreviation, e.g. GOLD_PIECE.

Returns

The number of coins (not their value). 0 when u has none, or the abbreviation is unknown. It fails when u is null or coin is empty.

Notes

  • The second argument is a string. The old page said integer; vmc refuses one ("Arg 2 of 'purse' not a string").
  • Only coins directly in u count, not coins inside a bag it carries.
  • To take a price from a character, use transfermoney(): it works with values, picks the coins and gives change.

Example

dilbegin integer coin_value(u : unitptr);
code
{
   return (purse(u, PLATINUM_PIECE) * PLATINUM_MULT +
           purse(u, GOLD_PIECE) * GOLD_MULT +
           purse(u, SILVER_PIECE) * SILVER_MULT +
           purse(u, COPPER_PIECE) * COPPER_MULT +
           purse(u, IRON_PIECE) * IRON_MULT);
}
dilend

Adds up the value of the coins a unit carries, as the pick pocket skill in skills.zon reckons a victim's purse.

See also