π° Economy API¶
Pier offers economy functions through LegacyMoney. Without it these APIs return "unavailable" errors, and Pier itself keeps running.
Identify accounts by XUID
After a player renames, someone else can register the old name; an account kept by name would pass its balance to that newcomer. Every economy operation uses the XUID.
Balances¶
Reading a balance¶
Rust: money::balance(xuid)
Go: levilamina.Money(xuid)
Zig: levilamina.slot("get_money")
- Parameters:
- xuid : string
the player's XUID
- xuid : string
- Return value: the balance
- Return type: Rust
Result<i64>, Go(int64, error), Zigi64- When it cannot be read, an empty XUID or no backend, the call returns an error, and code that adds to the balance stops there instead of starting from 0. Calling the slot from Zig, a negative value means unreadable.
- Slot:
get_money -
Example:
- Rust
Rust - Go
Go - Zig
Adding to a balance¶
Rust: money::add(xuid, delta)
Go: levilamina.AddMoney(xuid, delta)
Zig: levilamina.slot("add_money")
Taking and setting: Rust reduce, set, Go ReduceMoney, SetMoney. Taking more than the balance fails.
- Parameters:
- xuid : string
the player's XUID - delta : integer
the amount to add
- xuid : string
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror, Zigbool - Slot:
add_money,reduce_money,set_money -
Example:
- Rust
Rust - Go
Go - Zig
Transferring¶
Rust: money::transfer(from, to, value, note)
Go: levilamina.TransferMoney(from, to, value, note)
Zig: levilamina.slot("trans_money")
- Parameters:
- from, to : string
the payer's and recipient's XUID - value : integer
the amount - note : string
a note for the history
- from, to : string
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror, Zigbool- What the recipient receives may be taxed, depending on LegacyMoney's settings.
- Slot:
trans_money -
Example:
- Rust
Rust - Go
Go
Transaction listeners¶
Before a transaction¶
Rust: money::on_before_with(handler)
Go: levilamina.OnMoneyBefore(handler)
Zig: levilamina.slot("money_listen_before_event")
- Parameters:
- handler : function
called before every transaction; returningfalsestops it
- handler : function
- Return value: nothing on success
- Return type: Rust
Result<()>, Goerror- The kind of transaction, set, add, reduce or transfer, is in the event's kind; refuse a kind you do not know. To record after: Rust
on_after, GoOnMoneyAfter.
- The kind of transaction, set, add, reduce or transfer, is in the event's kind; refuse a kind you do not know. To record after: Rust
- Slot:
money_listen_before_event,money_listen_after_event -
Example:
- Rust
Rust - Go