TaskItems
A task item is a quest item the player carries, such as a key or a recipe. TaskItems lists what the player holds, adds and removes them, and tells you when a count changes. It covers only the counts of these items. The quest list and its goals are on the Quests page.
TaskItems the task items the player holds
This is the class you start from. All(), Has and Amount read what the player holds, Add and Remove change it, and Changed tells you when a count moves.
public static class TaskItems
{
public static event Action<TaskItemChangedArgs> Changed;
public static List<TaskItemCount> All();
public static bool Has(string id);
public static int Amount(string id);
public static bool Add(string id, int amount);
public static bool Remove(string id, int amount);
}
| Method | Returns | What it does |
|---|---|---|
All() | List<TaskItemCount> | Every task item the player holds. |
Has(id) | bool | true when the player holds this item. |
Amount(id) | int | How many the player holds. 0 for none or an unknown id. |
Add(id, amount) | bool | Gives the player some. true when the count went up. |
Remove(id, amount) | bool | Takes some away. true when the count went down. |
| Event | Gives you | When it fires |
|---|---|---|
Changed | TaskItemChangedArgs | Once for each item whose count changes, and once when an item is added or removed. |
TaskItemCount one task item the player holds
TaskItems.All() gives you one of these for each item the player holds. Amount is how many the player has.
public sealed class TaskItemCount
{
public string Id { get; }
public string Name { get; }
public int Amount { get; }
public string Type { get; }
public string Details { get; }
}
| Property | Type | What it means |
|---|---|---|
Id | string | The item’s id. |
Name | string | The item’s name. |
Amount | int | How many the player holds. |
Type | string | The kind of item, for example "Keys". |
Details | string | The item’s description. "" when the game has none. |
TaskItemChangedArgs what Changed tells you
Changed gives you this, once for each change. OldAmount and NewAmount give the count before and after, and Held says whether the player still has the item.
public sealed class TaskItemChangedArgs
{
public string Id { get; }
public string Name { get; }
public string Type { get; }
public int OldAmount { get; }
public int NewAmount { get; }
public bool Held { get; }
}
| Property | Type | What it means |
|---|---|---|
Id | string | The item’s id. |
Name | string | The item’s name. |
Type | string | The kind of item. |
OldAmount | int | The count before the change. |
NewAmount | int | The count after the change. |
Held | bool | true when the player still holds the item after the change. |
Things to know
- A task item’s id is its own
id, or its asset path, or its name. The game picks the first one it has. (IdisTaskItem.Id: theidfield, else the addressable asset path, elseitemName. Task items are theTaskItemrecords held byTaskItemsManager, the list that the console’sadd_task_itemcommand fills.) Add(id, amount)gives the player the item, andRemove(id, amount)takes it away.amountmust be above 0. (They callTaskItemsManager.AddTaskItem(taskItem, amount)andTaskItemsManager.RemoveItem(taskItem, amount).)Addgives backtrueonly when the count for that id went up.Removegives backtruewhen the count went down or the entry was removed. (Removegives backtruewhen the first record with that id lost count or was removed, so a record at count 0 that the game removes also counts.)Removeworks from what the player already holds, so the item does not need to be loaded.AddandRemoveonly change the count. They do not run the item’s give-item or send-mail steps, the same as the console’sadd_task_itemcommand. (They skip the item’sGiveItemandSendMail.)Has(id)istruewhen the player holds a record with that id, even at count 0. It gives backfalsefor a null or empty id.TypeandDetailsare for information.Typeis the name of the kind of item the game gives it, such asKeysorRecipes.Detailsis its description text. (Typeis the name of the game’sTaskItem.Typemember (Keys,Recipes,TaskItemsand so on).DetailsisitemDetails.)Changedfires for every change, whether it comes from this API or from the game itself. Recipes are added at count 0, so they fireChangedtoo, withTypeset to the recipe’s type name. (It comes from any source that goes through the game’sAddTaskItemorRemoveItem.)Heldtells you whether the player still has the item after the change. A new item hasOldAmount0. An item whose count reaches 0 but stays on the list hasNewAmount0 andHeldtrue.Heldisfalseonly when the item was removed from the list, and thenNewAmountis 0.- A handler may call
AddorRemove. A change made inside a handler fires its own event before the rest of the first change’s events. This can go eight levels deep, the same asCash.MoneyChanged. - The quest list is on another page.
TaskControlleris the same system asQuests, so this page does not cover it again.TaskPanelis the task list screen and holds no game state a mod needs. Adddoes not give a blueprint. A blueprint also needs to be registered with the game’s building system, which this API does not do. To give the player a blueprint for your mod’s furniture, useFurnitureRegistry.DefineBlueprintandFurnitureRegistry.GiveBlueprinton the custom furniture page. (The item is aTaskItemBlueprint, and the game’s add also registers it withBuildingSystem.)
Limits
- Both
AddandRemovegive backfalsewhile a save is loading or being written, and when the game’s task item list is not loaded. (The list check isTaskItemsManager.instancebeing null.) - You can only add an item the game has already loaded. A mod can’t create a new task item, and an item the game has not loaded yet is not found, so
Addgives backfalse. Changeddoes not fire while a save is loading.- An
AddorRemovemade while the eighth event runs does not fire another event, and that is logged once.