Manual:DIL Manual/transfermoney()
Jump to navigation
Jump to search
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.