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

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:
 +
= moneystring() =
 +
'''Function''' (string). Writes an amount of money out in coins.
  
 +
moneystring(amt : integer, verbose : integer)
  
−
<span id="bfmonstr"></span>
+
Turns <code>amt</code>, in the game's base units, into the fewest coins of the default currency,
−
string moneystring(amt : integer, verbose : integer)
+
largest coins first: <code>moneystring(1230, TRUE)</code> is
−
    amt    : The amount of money
+
''a silver piece, 7 copper pieces and 3 iron pieces''; <code>moneystring(1230, FALSE)</code> is
−
    verbose: True if an expanded string (copper pieces) or false
+
''1 sp, 7 cp and 3 ip''.
−
            if abbreviated money types (cp).
 
−
    result : The moneystring for the given currency.
 
  
−
---~---~---~---~---~---~---~---~---
+
== Parameters ==
 +
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| amt || integer || The amount in base units: an iron piece is 10, copper 80, silver 640, gold 5120, platinum 40960 (<code>IRON_MULT</code> ... <code>PLATINUM_MULT</code> in <code>vme.h</code>).
 +
|-
 +
| verbose || integer || <code>TRUE</code> for the coins' names (''7 copper pieces'', ''an iron piece''), <code>FALSE</code> 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 <code>vme/etc/money</code>).
 +
* Use <code>TRUE</code> or <code>FALSE</code> for <code>verbose</code>.
 +
 
 +
== Example ==
 +
<pre>
 +
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
 +
</pre>
 +
A shopkeeper that tells the price when someone types <code>value</code>, written out both ways,
 +
as the shops in midgaard.zon quote their prices.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/transfermoney()|transfermoney()]]
 +
* [[Manual:DIL Manual/purse()|purse()]]
 +
* [[Manual:DIL Manual/acc modify()|acc modify()]]

Latest revision as of 23:03, 14 November 2026

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