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.

Prerequisites
How-To: Get the Building Blocks.

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.

Verify
Play. Dev Tools -> Currency shows 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.

Verify
Add 50, remove 70: the second call returns false and the amount stays 50.

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.

Verify
Play As Client; add gold on the server. The client's Get Currency Views shows the new amount and the Messages tab shows CurrencyChanged.

See also

  • How-To: Drop and Pick Up Items (currency pickups and GrantCurrency items)
  • How-To: Save and Restore