Manual:DIL Manual/moneystring()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:03, 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

moneystring()

Function (string). Writes an amount of money out in coins.

moneystring(amt : integer, verbose : integer)

Turns amt, in the game's base units, into the fewest coins of the default currency, largest coins first: moneystring(1230, TRUE) is a silver piece, 7 copper pieces and 3 iron pieces; moneystring(1230, FALSE) is 1 sp, 7 cp and 3 ip.

Parameters

Name Type Meaning
amt integer The amount in base units: an iron piece is 10, copper 80, silver 640, gold 5120, platinum 40960 (IRON_MULT ... PLATINUM_MULT in vme.h).
verbose integer TRUE for the coins' names (7 copper pieces, an iron piece), FALSE for their abbreviations (7 cp).

Returns

String: the coins, separated by commas and with and before the last.

Notes

  • The amount is rounded to whole iron pieces (to the nearest 10).
  • Anything under one iron piece, 0 and negative amounts included, comes out as
 an iron piece (1 ip), never as nothing: test for 0 yourself.
  • Always the default currency (the coins in vme/etc/money).
  • Use TRUE or FALSE for verbose.

Example

dilbegin quote_price(price : integer);
code
{
   :start:
   wait(SFB_CMD, command("value") and (activator.type == UNIT_ST_PC));
   block;
   act("$1n says, 'That costs " + moneystring(price, TRUE) + " (" +
       moneystring(price, FALSE) + ").'", A_ALWAYS, self, null, null, TO_ROOM);
   goto start;
}
dilend

A shopkeeper that tells the price when someone types value, written out both ways, as the shops in midgaard.zon quote their prices.

See also