Reading a trader
This is the full list of what the API gives you. Text in brackets at the end of a note is extra detail for experienced modders, and you can skip it on a first read.
Traders.Get(shopId) gives a TraderInfo, a snapshot of one trader at the moment you asked. The snapshot does not update by itself, so ask again for fresh values.
Traders reads and checks traders
Use Get to read one trader by its shop id.
public static class Traders
{
public static bool IsAvailable { get; }
public static bool PriceFactorsAvailable { get; }
public static TraderInfo Get(string shopId);
}
| Method | Returns | What it does |
|---|---|---|
Get(shopId) | TraderInfo | The trader with this shop id. null when not found. |
| Property | Type | What it means |
|---|---|---|
IsAvailable | bool | true when reading a trader and changing its money work. |
PriceFactorsAvailable | bool | true when price factors work. |
TraderInfo a snapshot of one trader
Traders.Get(shopId) gives you one of these, or null when there is no such trader. It is a snapshot, so ask again for fresh values. (It reads the game’s Trade for the shop.)
public sealed class TraderInfo
{
public string Id { get; }
public bool Open { get; }
public float Money { get; }
public MoneyCurrency Currency { get; }
public float BuyFactor { get; }
public float SellFactor { get; }
public bool BuysStolen { get; }
public string[] AllowedCategories { get; }
public string[] ForbiddenCategories { get; }
}
| Property | Type | What it means |
|---|---|---|
Id | string | The trader’s shop id. |
Open | bool | true when the trader is open. You can only read this. |
Money | float | How much money the trader has to pay the player with. |
Currency | MoneyCurrency | The currency that money is in, OC or RM. |
BuyFactor | float | All mods’ buy price factors multiplied together. 1 when none. |
SellFactor | float | All mods’ sell price factors multiplied together. 1 when none. |
BuysStolen | bool | true when the trader buys stolen goods. |
AllowedCategories | string[] | The kinds of item the trader buys. Empty means no limit. |
ForbiddenCategories | string[] | The kinds of item the trader refuses to buy. |
Things to know
- A trader is found by its shop id, the same id that
Shops.All()andShops.Stockuse. (it is theGUIDof theTrade;Getgivesnullfor an empty or unknown id, and whenIsAvailableisfalse) Moneyis in the trader’s own currency, which is OC or RM. OC is Open Sewer Coins and RM is Real Money (see the glossary).- You can only read
Open. The game opens and closes a trader by the clock, and it would undo anything your mod set, so there is no way to set it. (the game setsTrade.openfrom the trader’s opening hours every in-game minute whenautoOpenCloseis on; the game’s own buy and sell checks do not read it. See Shop hours to read the opening times) BuysStolen,AllowedCategoriesandForbiddenCategoriessay what the trader will take from the player.Sellfollows them.
Limits
BuyandSellrefuse withClosedwhen the trader is closed.