Class TimbnPlayer
Reads where the player is in the loaded save and what they know, and makes the one shot changes that need no undo, such as giving money, changing a resource, unlocking a craft or moving them. See the plugin's Player property for changes that have to be undone, such as holding the player still.
public static class TimbnPlayer
- Inheritance
-
TimbnPlayer
- Inherited Members
Properties
Carried
The item the player carries over their head, such as a log, or null when they carry nothing or at the main menu. A player with extra carry slots can carry several, and this is the one on top, the one the interaction key puts down first. See the plugin's Player.Carry to hand them one.
public static Item? Carried { get; }
Property Value
- Item
Examples
if (TimbnPlayer.Carried?.id == "wood")
Logger.LogInfo("The player carries a log.");
Energy
The player's energy, which the game caps at its maximum. 0 at the main menu.
public static float Energy { get; }
Property Value
Examples
if (TimbnPlayer.Energy < 20f)
return;
HandsFree
Whether the player's hands are free, with nothing over their head in any carry slot and nothing held out in front of them the way they hold seeds. False at the main menu.
public static bool HandsFree { get; }
Property Value
Examples
if (TimbnPlayer.HandsFree)
_mug = Player.Carry(new Item("my_mod_mug"));
IsTired
Whether the player has the game's tired debuff. False at the main menu.
public static bool IsTired { get; }
Property Value
Examples
if (TimbnPlayer.IsTired)
return;
Money
The player's money in the game's raw units, where 100 is one silver coin. 0 at the main menu.
public static int Money { get; }
Property Value
Examples
if (TimbnPlayer.Money >= 500)
Logger.LogInfo("The player has 5 silver.");
Position
The player's position in their current scene, or zero at the main menu.
public static Vector3 Position { get; }
Property Value
- Vector3
Scene
The scene the player is in, holding its world objects and the items dropped on its ground, or null at the main menu.
public static GameSceneData? Scene { get; }
Property Value
- GameSceneData
SceneId
The id of the scene the player is in, such as the graveyard or an interior, or null at the main menu.
public static string? SceneId { get; }
Property Value
Zone
The zone the player stands in, such as the garden or the morgue, or null at the main menu and in the open between zones. Zones are the game's named areas, each with its own build area and workers.
public static WorldZoneData? Zone { get; }
Property Value
- WorldZoneData
ZoneId
The id of the zone the player stands in, such as garden, or null when they stand in none.
public static string? ZoneId { get; }
Property Value
Examples
var atHome = TimbnPlayer.ZoneId is "garden" or "inquisitions_base";
Methods
AddPerk(string)
Gives the player a perk, such as the tired debuff or a food buff, the way an item or a script does. A perk the player already has is refreshed by its own add rule. The perk is saved with the game, so use it for the game's own perks and for effects that should stay, and use Potions for a buff of your own that must end with the mod.
public static bool AddPerk(string id)
Parameters
idstringThe perk's id from the balance, such as lack_of_sleep_debuff.
Returns
- bool
False at the main menu or when no perk has that id.
Examples
TimbnPlayer.AddPerk(TimbnGameIds.Buffs.LackOfSleepDebuff);
AddResource(string, float)
Adds to one of the player's resources, or takes from it with a negative amount, the way a quest reward or a buff does. The game's own limits apply, so energy never goes past its maximum. For money prefer GiveMoney(int) and TakeMoney(int), which show the game's coin toast.
public static bool AddResource(string id, float amount)
Parameters
Returns
- bool
False at the main menu, when there is no player.
Examples
TimbnPlayer.AddResource("insanity", -10f);
CountItem(string)
How many of an item the player carries in their inventory and bags. Storage in the world does not count.
public static int CountItem(string id)
Parameters
idstringThe item id.
Returns
GameHasControl(params TakenControlType[])
Whether the game itself has taken the player's control, such as for a cutscene, sleep, or a teleport. Control taken by mods with the plugin's Player.TakeControl does not count, so a mod holding the player can use it to notice the game stepping in.
public static bool GameHasControl(params TakenControlType[] ignored)
Parameters
ignoredTakenControlType[]The game's reasons that should not count, such as TakenControlType.ByUI for open windows.
Returns
- bool
True when the game has taken control for any other reason. False at the main menu.
Examples
Stop meditating when the game takes control for anything but an open window.
if (TimbnPlayer.GameHasControl(TakenControlType.ByUI))
meditation.Stop();
GetResource(string)
One of the player's resources, the string keyed numbers the game keeps on them, such as energy, insanity, a reputation (see ReputationOf(string)) or money. 0 for a resource they do not have and at the main menu.
public static float GetResource(string id)
Parameters
idstringThe resource's id, such as insanity.
Returns
- float
Its value, or 0.
Examples
if (TimbnPlayer.GetResource("insanity") > 50f)
Logger.LogInfo("The keeper is losing it.");
GiveItem(Item)
Puts an item in the player's inventory, dropping whatever does not fit in front of them.
public static int GiveItem(Item item)
Parameters
itemItemThe item and how many.
Returns
- int
How many went into the inventory.
GiveMoney(int)
Gives the player money, such as a customer paying, with the game's coin sound and the notice it shows for any money the player gets.
public static void GiveMoney(int amount)
Parameters
amountintHow much to give, in the game's raw units. Nothing happens for 0 or less.
Examples
TimbnPlayer.GiveMoney(45);
HasBuilt(string)
Whether the player has built one of the buildings the game only allows once, such as the choir or the organ. The game marks such a building as locked once it is built, so this reads that list.
public static bool HasBuilt(string buildingId)
Parameters
buildingIdstringThe building's id from the balance, such as zmb_choir_unlock_s.
Returns
- bool
True when it has been built. False at the main menu.
Examples
if (TimbnPlayer.HasBuilt("zmb_choir_unlock_s"))
TimbnQuests.FireStoryTrigger(GlobalEventsSystem.Event.Type.BuildBuilding, "zmb_choir_unlock");
HasCraft(string)
Whether the player can make a recipe, either one the game gives from the start or one they have unlocked, such as a dish learned from a cookbook or a tech. It reads the craft's isNeedsUnlock and the save's unlocked crafts, the way a station does before it offers the recipe.
public static bool HasCraft(string craftId)
Parameters
craftIdstringThe recipe's id from the balance.
Returns
- bool
True when it needs no unlock or is unlocked. False at the main menu.
Examples
if (TimbnPlayer.HasCraft(craft.id))
dishes.Add(craft.id);
HasInspiration(string)
Whether the player has bought a level of an inspiration, such as the second graveyard expansion.
public static bool HasInspiration(string inspirationId)
Parameters
inspirationIdstringThe level's id, such as cemetery_expander_2.
Returns
- bool
False when it is not bought, the inspiration is missing, or at the main menu.
Examples
if (TimbnPlayer.HasInspiration("cemetery_expander_2"))
Logger.LogInfo("The graveyard has grown twice.");
HasItem(string, int)
Whether the player carries at least some of an item in their inventory and bags.
public static bool HasItem(string id, int count = 1)
Parameters
Returns
HasPerk(string)
Whether the player has a perk.
public static bool HasPerk(string id)
Parameters
idstringThe perk's id, such as perk_green_thumb.
Returns
- bool
True when the player has it. False at the main menu.
Examples
var greenThumb = TimbnPlayer.HasPerk("perk_green_thumb");
HasTech(string)
Whether the player has researched a technology.
public static bool HasTech(string id)
Parameters
idstringThe technology's id, such as wood_basic.
Returns
- bool
True when it is researched. False at the main menu.
Examples
if (TimbnPlayer.HasTech("wood_basic"))
Logger.LogInfo("Wood basics are researched.");
KnownCrafts(params string[])
Every recipe the player can make right now, the ones the game gives from the start and the ones they have unlocked, the same set HasCraft(string) says yes to. Pass station ids to keep only recipes made at any of them, or none for every station. The result is a snapshot, so call it again after the player learns something.
public static CraftDef[] KnownCrafts(params string[] stationIds)
Parameters
stationIdsstring[]Station ids such as KitchenOven, or none for all.
Returns
- CraftDef[]
The recipes themselves, empty at the main menu.
Examples
var dishes = TimbnPlayer.KnownCrafts(
TimbnGameIds.Workstations.Placed.KitchenOven,
TimbnGameIds.Workstations.Placed.KitchenTable);
RemovePerk(string)
Takes a perk away from the player and runs what the perk does when it ends, such as giving back a resource. A perk the player does not have is left alone.
public static bool RemovePerk(string id)
Parameters
idstringThe perk's id from the balance.
Returns
- bool
True when the player had the perk. False at the main menu or when they did not.
Examples
TimbnPlayer.RemovePerk(TimbnGameIds.Buffs.LackOfSleepDebuff);
SetResource(string, float)
Sets one of the player's resources to a value, such as filling their energy. The game's own limits apply.
public static bool SetResource(string id, float value)
Parameters
Returns
- bool
False at the main menu, when there is no player.
Examples
TimbnPlayer.SetResource("insanity", 0f);
TakeItem(string, int)
Removes an item from the player's inventory and bags, up to the count asked for.
public static int TakeItem(string id, int count)
Parameters
Returns
- int
How many were taken.
TakeMoney(int)
Takes money from the player, as much as they have up to the amount, such as a fine. The game shows the loss the way it shows any change to the player's money.
public static int TakeMoney(int amount)
Parameters
amountintHow much to take, in the game's raw units.
Returns
- int
How much was taken, less than the amount when the player had less. 0 at the main menu.
Examples
var paid = TimbnPlayer.TakeMoney(250);
TeleportTo(Vector3)
Moves the player to a spot in their current scene, the way the game moves them. Pair it with TryFindWalkable(Vector3, float, out Vector3) so they land on open ground.
public static bool TeleportTo(Vector3 position)
Parameters
positionVector3Where to put the player.
Returns
- bool
False at the main menu, when there is no player to move.
Examples
if (TimbnWorld.TryFindWalkable(TimbnPlayer.Position, 5f, out var ground))
TimbnPlayer.TeleportTo(ground);
UnlockCraft(string)
Unlocks a recipe for the player the way a cookbook or a study does, so its station offers it from now on. A recipe already unlocked stays as it is.
public static bool UnlockCraft(string craftId)
Parameters
craftIdstringThe recipe's id from the balance.
Returns
- bool
False at the main menu, when there is no player to teach.
Examples
TimbnPlayer.UnlockCraft("my_mod_fish_pie");