Wallet
Wallet reads and spends the player’s OC (Open Sewer Coins, the game’s everyday money, see OC). It is the older API, kept so old mods keep working. For new code use Cash, which handles OC and RM (Real Money, see RM), and it is described on the economy page.
Wallet read and spend OC
Read Balance, and use Has, TrySpend or Give to check and change the player’s OC.
public static class Wallet
{
public static int Balance { get; }
public static bool Has(int amount);
public static bool TrySpend(int amount);
public static bool Give(int amount);
}
| Method | Returns | What it does |
|---|---|---|
Has(amount) | bool | true when the player has at least this much OC. |
TrySpend(amount) | bool | Takes the OC away. Returns false when it could not be done. See Things to know. |
Give(amount) | bool | Gives the OC to the player. Returns false when it could not be done. See Things to know. |
| Property | Type | What it means |
|---|---|---|
Balance | int | How much OC the player has. |
Putting it together
Takes 50 OC when the mod starts, and logs the new balance if the payment worked.
using BepInEx;
using BepInEx.Unity.Mono;
using ObenseuerCore;
public class Toll : BaseUnityPlugin
{
private void Start()
{
if (Wallet.TrySpend(50))
{
Logger.LogInfo("paid 50 OC, balance " + Wallet.Balance);
}
}
}
| Step | What it does |
|---|---|
Wallet.TrySpend(50) | Takes 50 OC, and returns false if it could not. |
Wallet.Balance | Reads the balance after the payment. |
Things to know
TrySpendandGivenever throw an error. If something is wrong, you getfalse.TrySpendandGiverefuse an amount that is not a whole number from 1 to 16,000,000. You also getfalsewhen the player does not have enough OC to spend, or when the game’s money is not ready. (The cap of 16,000,000 stays below 2^24 (16,777,216), the largest whole number a float holds exactly. The game passes amounts as float, so larger values could be rounded.)TrySpendandGivereturnfalsewhile the game is loading or saving, the same asCash.GiveandCash.TrySpend. Try again later.- On the main menu the balance is
0, andHas,TrySpendandGivereturnfalse. There is no player money yet. (This is whenMoney.instanceis null.) - Rarely, a call can return
falseeven though the balance did change. If the game fails right after it changes the money, the call returnsfalse, but the new balance stays. (The failure is in the game’sUpdateInteractableMoneystep, which runs after the balance is set.)