How-To: Manage Currency
Goal: define a currency in a data table, have every inventory carry it as a replicated handler, and add, remove, and display it.
1. Define the currency table
Row type FCrimsonCurrencyDefinition: CurrencyType (a UCrimsonInventoryCurrency class - use UCrimsonBasicCurrency), CurrencyTag, DisplayName, Icon, bUserFacing.
right-click -> Miscellaneous -> Data Table, row structure CrimsonCurrencyDefinition, name it DT_Currencies. Add row Gold: Currency Type = CrimsonBasicCurrency, Currency Tag = Currency.Gold. Then add the table to Project Settings -> Crimson Inventory -> Currency Definition Tables so every manager loads it on InitializeComponent, or pass it per inventory in Initialize Inventory -> In Currency Data Tables.
Gold = 0 on the PlayerState inventory.2. Add and remove
Server: Add Currency (Currency Type = row handle DT_Currencies / Gold, Amount) and Remove Currency (returns false when insufficient). Remove Currency By Tag and Remove Currency By Name are the tag and display-name variants.
3. Display
Get Currency Views returns FCrimsonInventoryCurrencyView (Tag, Name, Amount, Currency) for every loaded currency. Listen on Crimson.Inventory.Message.CurrencyChanged (FCrimsonInventoryCurrencyChangeMessage: Currency, NewCount, Delta) to refresh.
CurrencyChanged.See also
- How-To: Drop and Pick Up Items (currency pickups and
GrantCurrencyitems) - How-To: Save and Restore