Difference between revisions of "Manual:DIL Manual/transfermoney()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = transfermoney() = | |
| − | + | '''Function''' (integer). Moves money from one character to another, or creates or destroys it. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | transfermoney(from : unitptr, to : unitptr, amount : integer) | |
| − | |||
| − | + | The amount is a value, not a number of coins: one iron piece is worth <code>IRON_MULT</code> (10), a copper piece <code>COPPER_MULT</code> (80) and so on up to <code>PLATINUM_MULT</code> (all in <code>vme/include/vme.h</code>). The server picks the coins and gives change, so a character with a gold piece can pay 3 copper. | |
| − | < | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | * Both units given: the money moves from <code>from</code> to <code>to</code>, if <code>from</code> can afford it. | |
| − | + | * <code>from</code> null: new money is made and given to <code>to</code>. vme.log gets a line "<name> was given ... by DIL <unit>". | |
| + | * <code>to</code> null: the money is taken from <code>from</code> and destroyed, if <code>from</code> can afford it. | ||
| − | + | == Parameters == | |
| + | {| class="wikitable" | ||
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | from || unitptr || The character who pays, or null to make new money. | ||
| + | |- | ||
| + | | to || unitptr || The character who gets the money, or null to destroy it. | ||
| + | |- | ||
| + | | amount || integer || The value to move. | ||
| + | |} | ||
| + | |||
| + | == Returns == | ||
| + | TRUE when the money was moved. FALSE when <code>from</code> can't afford it, or both units are null (nothing happens then). It fails when a unit is not a character (an object or a room). | ||
| + | |||
| + | == Notes == | ||
| + | * '''The amount is rounded''' to the nearest iron piece (10), and is at least one iron piece. An amount of 0 or less therefore moves one iron piece. Test <code>amount > 0</code> first, as the pick pocket skill in skills.zon does. | ||
| + | * Only the coins a character carries directly count; money in a bag doesn't. | ||
| + | * With <code>from</code> null, check the amount: the money is real and players keep it. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin integer charge(pc : unitptr, price : integer); | ||
| + | code | ||
| + | { | ||
| + | if (price <= 0) | ||
| + | return (TRUE); | ||
| + | if (not transfermoney(pc, self, price)) | ||
| + | { | ||
| + | exec("say That costs " + moneystring(price, TRUE) + ", which you don't have.", self); | ||
| + | return (FALSE); | ||
| + | } | ||
| + | exec("say Thank you, " + pc.name + ".", self); | ||
| + | return (TRUE); | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | An NPC takes a price from a player, as the repair shops in midgaard.zon do. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/purse()|purse()]] | ||
| + | * [[Manual:DIL Manual/moneystring()|moneystring()]] | ||
Latest revision as of 23:08, 14 November 2026
transfermoney()
Function (integer). Moves money from one character to another, or creates or destroys it.
transfermoney(from : unitptr, to : unitptr, amount : integer)
The amount is a value, not a number of coins: one iron piece is worth IRON_MULT (10), a copper piece COPPER_MULT (80) and so on up to PLATINUM_MULT (all in vme/include/vme.h). The server picks the coins and gives change, so a character with a gold piece can pay 3 copper.
- Both units given: the money moves from
fromtoto, iffromcan afford it. fromnull: new money is made and given toto. vme.log gets a line "<name> was given ... by DIL <unit>".tonull: the money is taken fromfromand destroyed, iffromcan afford it.
Parameters
| Name | Type | Meaning |
|---|---|---|
| from | unitptr | The character who pays, or null to make new money. |
| to | unitptr | The character who gets the money, or null to destroy it. |
| amount | integer | The value to move. |
Returns
TRUE when the money was moved. FALSE when from can't afford it, or both units are null (nothing happens then). It fails when a unit is not a character (an object or a room).
Notes
- The amount is rounded to the nearest iron piece (10), and is at least one iron piece. An amount of 0 or less therefore moves one iron piece. Test
amount > 0first, as the pick pocket skill in skills.zon does. - Only the coins a character carries directly count; money in a bag doesn't.
- With
fromnull, check the amount: the money is real and players keep it.
Example
dilbegin integer charge(pc : unitptr, price : integer);
code
{
if (price <= 0)
return (TRUE);
if (not transfermoney(pc, self, price))
{
exec("say That costs " + moneystring(price, TRUE) + ", which you don't have.", self);
return (FALSE);
}
exec("say Thank you, " + pc.name + ".", self);
return (TRUE);
}
dilend
An NPC takes a price from a player, as the repair shops in midgaard.zon do.