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

  • TrySpend and Give never throw an error. If something is wrong, you get false.
  • TrySpend and Give refuse an amount that is not a whole number from 1 to 16,000,000. You also get false when 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.)
  • TrySpend and Give return false while the game is loading or saving, the same as Cash.Give and Cash.TrySpend. Try again later.
  • On the main menu the balance is 0, and Has, TrySpend and Give return false. There is no player money yet. (This is when Money.instance is null.)
  • Rarely, a call can return false even though the balance did change. If the game fails right after it changes the money, the call returns false, but the new balance stays. (The failure is in the game’s UpdateInteractableMoney step, which runs after the balance is set.)