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

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="bfpurse"></span>
+
= purse() =
−
integer purse(u : unitptr, coinage : integer)
+
'''Function''' (integer). Counts the coins of one kind that a unit carries.
−
    u : The unit to check
 
−
    coinage: The money type (e.g. gold, silver), one of IRON_PIECE, etc.
 
−
    Returns: The number of such units found.
 
−
    Example: if (purse(self, PLATINUM_PIECE) > 10)
 
−
              exec("say I am loaded with platinum!", self);
 
  
−
  ---~---~---~---~---~---~---~---~---
+
  purse(u : unitptr, coin : string)
−
<span id="bfpurse"></span>
 
−
integer purse(u : unitptr, coinage : integer)
 
−
    u : The unit to check
 
−
    coinage: The money type (e.g. gold, silver), one of IRON_PIECE, etc.
 
−
    Returns: The number of such units found.
 
−
    Example: if (purse(self, PLATINUM_PIECE) > 10)
 
−
              exec("say I am loaded with platinum!", self);
 
  
−
---~---~---~---~---~---~---~---~---
+
The coin kind is given by its abbreviation from <code>vme/etc/money</code>. <code>vme/include/vme.h</code> has a name for each:
 +
 
 +
{| class="wikitable"
 +
! Constant !! Abbreviation !! Value of one coin
 +
|-
 +
| <code>IRON_PIECE</code> || "ip" || <code>IRON_MULT</code> (10)
 +
|-
 +
| <code>COPPER_PIECE</code> || "cp" || <code>COPPER_MULT</code> (80)
 +
|-
 +
| <code>SILVER_PIECE</code> || "sp" || <code>SILVER_MULT</code> (640)
 +
|-
 +
| <code>GOLD_PIECE</code> || "gp" || <code>GOLD_MULT</code> (5120)
 +
|-
 +
| <code>PLATINUM_PIECE</code> || "pp" || <code>PLATINUM_MULT</code> (40960)
 +
|}
 +
 
 +
== Parameters ==
 +
{| class="wikitable"
 +
! 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. <code>GOLD_PIECE</code>.
 +
|}
 +
 
 +
== Returns ==
 +
The number of coins (not their value). 0 when <code>u</code> has none, or the abbreviation is unknown. It fails when <code>u</code> is null or <code>coin</code> 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 <code>u</code> count, not coins inside a bag it carries.
 +
* To take a price from a character, use [[Manual:DIL Manual/transfermoney()|transfermoney()]]: it works with values, picks the coins and gives change.
 +
 
 +
== Example ==
 +
<pre>
 +
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
 +
</pre>
 +
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 ==
 +
* [[Manual:DIL Manual/transfermoney()|transfermoney()]]
 +
* [[Manual:DIL Manual/moneystring()|moneystring()]]

Latest revision as of 23:08, 14 November 2026

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