Table of Contents

Class TimbnPluginEvents

Namespace
Timbn.GraveyardKeeperTwo.Core.Framework
Assembly
Timbn.GraveyardKeeperTwo.Core.dll

Subscribes a plugin to the game's events without any cleanup code. Every subscription is owned by the plugin and removed when it unloads, so an F6 hot reload never leaves an old handler firing. The named events are the ones Core adds something to and the ones mods commonly need, such as a new day or the player using an item, and those that belong to a save follow every save the player loads. Any other game event is one line of GameEvent(Action, Action<Action>, Action<Action>), or of SaveEvent(Action, Action<Action>, Action<Action>) for an event on an object that belongs to the loaded save. Each handler is wrapped so a throw is logged instead of reaching the game. Reach it through the plugin's Events property.

public sealed class TimbnPluginEvents
Inheritance
TimbnPluginEvents
Inherited Members

Methods

AfterSave(Action)

Runs once the save has been written, or has failed to write, after Core has put its own content back. Use it to redo what you undid in BeforeSave(Action). It runs for every write the handlers of BeforeSave(Action) ran for.

public IDisposable AfterSave(Action handler)

Parameters

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Events.AfterSave(visits.Return);

BalanceLoaded(Action<GameBalance>)

Runs with the game's balance, where it keeps every item, craft, perk, and tech, each time it loads. It runs straight away when the balance is already loaded, then after every later load, once Core has put in the definitions plugins added. Use it to read the game's definitions. To change one, Balance.Edit also puts it back when the plugin unloads.

public IDisposable BalanceLoaded(Action<GameBalance> handler)

Parameters

handler Action<GameBalance>

Gets the loaded balance.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Events.BalanceLoaded(balance => Logger.LogInfo($"{balance.itemDefs.Count} items"));

BeforeSave(Action)

Runs just before the game writes the save you are playing, ahead of Core taking out the mod content it keeps out of the file. Use it to put back what a mod changed in the world that the save would otherwise keep, such as a visitor standing in the graveyard, and bring it back in AfterSave(Action). Core strips its own content after every plugin's handler has run, so nothing a handler leaves behind reaches the file. It runs for every write of the live save.

public IDisposable BeforeSave(Action handler)

Parameters

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Events.BeforeSave(visits.SendAway);

EveryRealSeconds(float, Action)

Runs at most once every seconds while a save is loaded and the game is not paused, and it starts on the first frame after it is added. The seconds are real time, so they do not speed up while the player sleeps. It never runs on the main menu. If the handler throws, the error is logged once and the handler is stopped.

public IDisposable EveryRealSeconds(float seconds, Action handler)

Parameters

seconds float

The shortest time between runs. Zero or less runs on every frame.

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Events.EveryRealSeconds(0.5f, () => stuckCarriers.Tick());

FixedUpdate(Action)

Runs on every physics step while a save is loaded, paused or not. Forces and velocities belong here, since the physics engine reads them at that moment. Otherwise it works like Update(Action).

public IDisposable FixedUpdate(Action handler)

Parameters

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

GameEvent(Action, Action<Action>, Action<Action>)

Subscribes to a static game event that has no named method here. The handler is wrapped so a throw is logged instead of reaching the game, the subscription is owned by the plugin, and it is removed when the plugin unloads, so there is nothing to clean up. It hooks the event once, so use it only for static events. An event on an object that belongs to a save (quests, the player's data) needs SaveEvent(Action, Action<Action>, Action<Action>), which hooks it again for each save.

public IDisposable GameEvent(Action handler, Action<Action> add, Action<Action> remove)

Parameters

handler Action

Your handler.

add Action<Action>

Subscribes a handler to the event, such as h => KnowledgeSystem.OnTechUnlocked += h.

remove Action<Action>

Unsubscribes it again, such as h => KnowledgeSystem.OnTechUnlocked -= h.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Log every tech the player unlocks, using the game's static KnowledgeSystem.OnTechUnlocked event, which passes the tech id and whether the unlock was silent.

Events.GameEvent<string, bool>(
    (techId, silent) => Logger.LogInfo($"Unlocked {techId}"),
    h => KnowledgeSystem.OnTechUnlocked += h,
    h => KnowledgeSystem.OnTechUnlocked -= h);

GameEvent(Type, string, Action)

Subscribes to a static game event by naming it, so Core does the += and -=. Name the event with nameof, so a game update that renames it fails the build. The handler has to take exactly the parameters the event passes, which is checked straight away, and otherwise it works like GameEvent(Action, Action<Action>, Action<Action>).

public IDisposable GameEvent(Type type, string eventName, Action handler)

Parameters

type Type

The game type that declares the event, such as typeof(KnowledgeSystem).

eventName string

The event's name, such as nameof(KnowledgeSystem.OnTechUnlocked).

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Log every tech the player unlocks.

Events.GameEvent(typeof(KnowledgeSystem), nameof(KnowledgeSystem.OnTechUnlocked),
    (string techId, bool silent) => Logger.LogInfo($"Unlocked {techId}"));

GameEvent<T>(Action<T>, Action<Action<T>>, Action<Action<T>>)

Subscribes to a static game event that has no named method here. The handler is wrapped so a throw is logged instead of reaching the game, the subscription is owned by the plugin, and it is removed when the plugin unloads, so there is nothing to clean up. It hooks the event once, so use it only for static events. An event on an object that belongs to a save (quests, the player's data) needs SaveEvent(Action, Action<Action>, Action<Action>), which hooks it again for each save.

public IDisposable GameEvent<T>(Action<T> handler, Action<Action<T>> add, Action<Action<T>> remove)

Parameters

handler Action<T>

Your handler.

add Action<Action<T>>

Subscribes a handler to the event, such as h => KnowledgeSystem.OnTechUnlocked += h.

remove Action<Action<T>>

Unsubscribes it again, such as h => KnowledgeSystem.OnTechUnlocked -= h.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Type Parameters

T

Examples

Log every tech the player unlocks, using the game's static KnowledgeSystem.OnTechUnlocked event, which passes the tech id and whether the unlock was silent.

Events.GameEvent<string, bool>(
    (techId, silent) => Logger.LogInfo($"Unlocked {techId}"),
    h => KnowledgeSystem.OnTechUnlocked += h,
    h => KnowledgeSystem.OnTechUnlocked -= h);

GameEvent<T>(Type, string, Action<T>)

Subscribes to a static game event by naming it, so Core does the += and -=. Name the event with nameof, so a game update that renames it fails the build. The handler has to take exactly the parameters the event passes, which is checked straight away, and otherwise it works like GameEvent(Action, Action<Action>, Action<Action>).

public IDisposable GameEvent<T>(Type type, string eventName, Action<T> handler)

Parameters

type Type

The game type that declares the event, such as typeof(KnowledgeSystem).

eventName string

The event's name, such as nameof(KnowledgeSystem.OnTechUnlocked).

handler Action<T>

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Type Parameters

T

Examples

Log every tech the player unlocks.

Events.GameEvent(typeof(KnowledgeSystem), nameof(KnowledgeSystem.OnTechUnlocked),
    (string techId, bool silent) => Logger.LogInfo($"Unlocked {techId}"));

GameEvent<T1, T2>(Action<T1, T2>, Action<Action<T1, T2>>, Action<Action<T1, T2>>)

Subscribes to a static game event that has no named method here. The handler is wrapped so a throw is logged instead of reaching the game, the subscription is owned by the plugin, and it is removed when the plugin unloads, so there is nothing to clean up. It hooks the event once, so use it only for static events. An event on an object that belongs to a save (quests, the player's data) needs SaveEvent(Action, Action<Action>, Action<Action>), which hooks it again for each save.

public IDisposable GameEvent<T1, T2>(Action<T1, T2> handler, Action<Action<T1, T2>> add, Action<Action<T1, T2>> remove)

Parameters

handler Action<T1, T2>

Your handler.

add Action<Action<T1, T2>>

Subscribes a handler to the event, such as h => KnowledgeSystem.OnTechUnlocked += h.

remove Action<Action<T1, T2>>

Unsubscribes it again, such as h => KnowledgeSystem.OnTechUnlocked -= h.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Type Parameters

T1
T2

Examples

Log every tech the player unlocks, using the game's static KnowledgeSystem.OnTechUnlocked event, which passes the tech id and whether the unlock was silent.

Events.GameEvent<string, bool>(
    (techId, silent) => Logger.LogInfo($"Unlocked {techId}"),
    h => KnowledgeSystem.OnTechUnlocked += h,
    h => KnowledgeSystem.OnTechUnlocked -= h);

GameEvent<T1, T2>(Type, string, Action<T1, T2>)

Subscribes to a static game event by naming it, so Core does the += and -=. Name the event with nameof, so a game update that renames it fails the build. The handler has to take exactly the parameters the event passes, which is checked straight away, and otherwise it works like GameEvent(Action, Action<Action>, Action<Action>).

public IDisposable GameEvent<T1, T2>(Type type, string eventName, Action<T1, T2> handler)

Parameters

type Type

The game type that declares the event, such as typeof(KnowledgeSystem).

eventName string

The event's name, such as nameof(KnowledgeSystem.OnTechUnlocked).

handler Action<T1, T2>

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Type Parameters

T1
T2

Examples

Log every tech the player unlocks.

Events.GameEvent(typeof(KnowledgeSystem), nameof(KnowledgeSystem.OnTechUnlocked),
    (string techId, bool silent) => Logger.LogInfo($"Unlocked {techId}"));

GamePaused(Action)

Runs when the game pauses, such as when the pause menu opens.

public IDisposable GamePaused(Action handler)

Parameters

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

GameUnpaused(Action)

Runs when the game unpauses.

public IDisposable GameUnpaused(Action handler)

Parameters

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

LanguageChanged(Action)

Runs when the player changes the game's language, so a plugin can drop text it looked up earlier.

public IDisposable LanguageChanged(Action handler)

Parameters

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Events.LanguageChanged(_itemNames.Clear);

LateUpdate(Action)

Runs on every frame after the game's own Update code, while a save is loaded, paused or not. Camera work belongs here, since the game moves the player during Update and a camera that follows them has to run afterwards. Otherwise it works like Update(Action).

public IDisposable LateUpdate(Action handler)

Parameters

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

MainMenuOpened(Action)

Runs when the main menu opens, both when the game starts and each time the player leaves a save.

public IDisposable MainMenuOpened(Action handler)

Parameters

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Events.MainMenuOpened(ReloadMyFiles);

NewDayStarted(Action<int>)

Runs when the clock wraps into a new day.

public IDisposable NewDayStarted(Action<int> handler)

Parameters

handler Action<int>

Gets the day number, counting up from 1 for the whole save.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Events.NewDayStarted(_ => tally.Current.DaysPassed++);

NewWeekdayStarted(Action<TimbnWeekday>)

Runs at the same moment as NewDayStarted, with the day's place in the week instead.

public IDisposable NewWeekdayStarted(Action<TimbnWeekday> handler)

Parameters

handler Action<TimbnWeekday>

Gets the day's place in the six day week.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

PlayerDropCollected(Action<List<Item>>)

Runs when the player picks up drops. Subscribe once, and it follows every save the player loads.

public IDisposable PlayerDropCollected(Action<List<Item>> handler)

Parameters

handler Action<List<Item>>

Gets the items picked up.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

PlayerItemUsed(Action<Item>)

Runs when the player uses an item, such as drinking a potion. Subscribe once, and it follows every save the player loads.

public IDisposable PlayerItemUsed(Action<Item> handler)

Parameters

handler Action<Item>

Gets the item used.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

PlayerItemsAdded(Action<List<Item>>)

Runs when items go into the player's inventory. Subscribe once, and it follows every save the player loads.

public IDisposable PlayerItemsAdded(Action<List<Item>> handler)

Parameters

handler Action<List<Item>>

Gets the items added.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

PlayerItemsRemoved(Action<List<Item>>)

Runs when items leave the player's inventory. Subscribe once, and it follows every save the player loads.

public IDisposable PlayerItemsRemoved(Action<List<Item>> handler)

Parameters

handler Action<List<Item>>

Gets the items removed.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

PlayerResourceChanged(Action)

Runs when any of the player's resources changes, money, energy, sanity and reputation included. Subscribe once, and it follows every save the player loads.

public IDisposable PlayerResourceChanged(Action handler)

Parameters

handler Action

Your handler. Read the values you care about with GetResource(string) or Money.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

PlayerTeleported(Action)

Runs when the player is moved by a teleport, which is also how every scene change happens.

public IDisposable PlayerTeleported(Action handler)

Parameters

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

QuestCanceled(Action<QuestData>)

Runs when a quest is canceled in the loaded save. Subscribe once, and it follows every save the player loads.

public IDisposable QuestCanceled(Action<QuestData> handler)

Parameters

handler Action<QuestData>

Gets the quest's save data. Its id is the quest id.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

QuestCompleted(Action<QuestData>)

Runs when a quest completes in the loaded save. Subscribe once, and it follows every save the player loads.

public IDisposable QuestCompleted(Action<QuestData> handler)

Parameters

handler Action<QuestData>

Gets the quest's save data. Its id is the quest id.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

QuestStarted(Action<QuestData>)

Runs when a quest starts in the loaded save. Subscribe once, and it follows every save the player loads.

public IDisposable QuestStarted(Action<QuestData> handler)

Parameters

handler Action<QuestData>

Gets the quest's save data. Its id is the quest id.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

SaveClosed(Action)

Runs when the player stops playing a save, whether they return to the main menu or the plugin unloads mid game, such as on a hot reload. It is the one place to put back what the plugin changed in the world for that save. On unload it runs after OnUnload and before Core removes the plugin's other registrations.

public IDisposable SaveClosed(Action handler)

Parameters

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed, without running the handler. You don't need to keep it.

Examples

Events.SaveClosed(meditation.Stop);

SaveEvent(Action, Action<Action>, Action<Action>)

Subscribes to an event on an object that belongs to the loaded save, such as the player's data or the save's quests. Subscribe once in OnAwake. Core hooks the event on every save the player loads, straight away when a save is already loaded, and unhooks it when the player leaves the save. Otherwise it works like GameEvent(Action, Action<Action>, Action<Action>). Add and remove read the save's object each time they run.

public IDisposable SaveEvent(Action handler, Action<Action> add, Action<Action> remove)

Parameters

handler Action

Your handler.

add Action<Action>

Subscribes a handler to the save's event, such as h => MainGame.PlayerData.OnItemUsed += h.

remove Action<Action>

Unsubscribes it again, such as h => MainGame.PlayerData.OnItemUsed -= h.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Log every item the player uses, in every save.

Events.SaveEvent<Item>(
    item => Logger.LogInfo($"Used {item.id}"),
    h => MainGame.PlayerData.OnItemUsed += h,
    h => MainGame.PlayerData.OnItemUsed -= h);

SaveEvent<T>(Action<T>, Action<Action<T>>, Action<Action<T>>)

Subscribes to an event on an object that belongs to the loaded save, such as the player's data or the save's quests. Subscribe once in OnAwake. Core hooks the event on every save the player loads, straight away when a save is already loaded, and unhooks it when the player leaves the save. Otherwise it works like GameEvent(Action, Action<Action>, Action<Action>). Add and remove read the save's object each time they run.

public IDisposable SaveEvent<T>(Action<T> handler, Action<Action<T>> add, Action<Action<T>> remove)

Parameters

handler Action<T>

Your handler.

add Action<Action<T>>

Subscribes a handler to the save's event, such as h => MainGame.PlayerData.OnItemUsed += h.

remove Action<Action<T>>

Unsubscribes it again, such as h => MainGame.PlayerData.OnItemUsed -= h.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Type Parameters

T

Examples

Log every item the player uses, in every save.

Events.SaveEvent<Item>(
    item => Logger.LogInfo($"Used {item.id}"),
    h => MainGame.PlayerData.OnItemUsed += h,
    h => MainGame.PlayerData.OnItemUsed -= h);

SaveEvent<TSource>(Func<TSource>, string, Action)

Subscribes to an event on an object that belongs to the loaded save by naming it, so Core does the += and -=. The object is read from source each time the event is hooked, and otherwise it works like SaveEvent(Action, Action<Action>, Action<Action>) and GameEvent(Type, string, Action).

public IDisposable SaveEvent<TSource>(Func<TSource> source, string eventName, Action handler)

Parameters

source Func<TSource>

Reads the save's object, such as () => MainGame.PlayerData.

eventName string

The event's name, such as nameof(PlayerData.OnItemUsed).

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Type Parameters

TSource

Examples

Log every item the player uses, in every save.

Events.SaveEvent(() => MainGame.PlayerData, nameof(PlayerData.OnItemUsed),
    (Item item) => Logger.LogInfo($"Used {item.id}"));

SaveEvent<T1, T2>(Action<T1, T2>, Action<Action<T1, T2>>, Action<Action<T1, T2>>)

Subscribes to an event on an object that belongs to the loaded save, such as the player's data or the save's quests. Subscribe once in OnAwake. Core hooks the event on every save the player loads, straight away when a save is already loaded, and unhooks it when the player leaves the save. Otherwise it works like GameEvent(Action, Action<Action>, Action<Action>). Add and remove read the save's object each time they run.

public IDisposable SaveEvent<T1, T2>(Action<T1, T2> handler, Action<Action<T1, T2>> add, Action<Action<T1, T2>> remove)

Parameters

handler Action<T1, T2>

Your handler.

add Action<Action<T1, T2>>

Subscribes a handler to the save's event, such as h => MainGame.PlayerData.OnItemUsed += h.

remove Action<Action<T1, T2>>

Unsubscribes it again, such as h => MainGame.PlayerData.OnItemUsed -= h.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Type Parameters

T1
T2

Examples

Log every item the player uses, in every save.

Events.SaveEvent<Item>(
    item => Logger.LogInfo($"Used {item.id}"),
    h => MainGame.PlayerData.OnItemUsed += h,
    h => MainGame.PlayerData.OnItemUsed -= h);

SaveEvent<TSource, T>(Func<TSource>, string, Action<T>)

Subscribes to an event on an object that belongs to the loaded save by naming it, so Core does the += and -=. The object is read from source each time the event is hooked, and otherwise it works like SaveEvent(Action, Action<Action>, Action<Action>) and GameEvent(Type, string, Action).

public IDisposable SaveEvent<TSource, T>(Func<TSource> source, string eventName, Action<T> handler)

Parameters

source Func<TSource>

Reads the save's object, such as () => MainGame.PlayerData.

eventName string

The event's name, such as nameof(PlayerData.OnItemUsed).

handler Action<T>

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Type Parameters

TSource
T

Examples

Log every item the player uses, in every save.

Events.SaveEvent(() => MainGame.PlayerData, nameof(PlayerData.OnItemUsed),
    (Item item) => Logger.LogInfo($"Used {item.id}"));

SaveEvent<TSource, T1, T2>(Func<TSource>, string, Action<T1, T2>)

Subscribes to an event on an object that belongs to the loaded save by naming it, so Core does the += and -=. The object is read from source each time the event is hooked, and otherwise it works like SaveEvent(Action, Action<Action>, Action<Action>) and GameEvent(Type, string, Action).

public IDisposable SaveEvent<TSource, T1, T2>(Func<TSource> source, string eventName, Action<T1, T2> handler)

Parameters

source Func<TSource>

Reads the save's object, such as () => MainGame.PlayerData.

eventName string

The event's name, such as nameof(PlayerData.OnItemUsed).

handler Action<T1, T2>

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Type Parameters

TSource
T1
T2

Examples

Log every item the player uses, in every save.

Events.SaveEvent(() => MainGame.PlayerData, nameof(PlayerData.OnItemUsed),
    (Item item) => Logger.LogInfo($"Used {item.id}"));

SaveReady(Action)

Runs for every save the player plays, once the scene is loaded and MainGame.Instance, PlayerData and WorldData are live. It runs straight away when a save is already loaded, which covers a plugin started by a hot reload mid game, and then each time a save finishes loading.

public IDisposable SaveReady(Action handler)

Parameters

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Events.SaveReady(() => ZombieTint.PaintAll(reset: false));

SleepEnded(Action)

Runs when the player wakes up, as the screen starts to fade back in and right after the game writes its wake up save.

public IDisposable SleepEnded(Action handler)

Parameters

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

SleepRefused(Action<bool>)

Runs when the player tries to sleep with full energy and the bed turns them away, just before the game's own refusal handling runs.

public IDisposable SleepRefused(Action<bool> handler)

Parameters

handler Action<bool>

Gets whether the game would have saved when this sleep ended, which it does unless the sleep was started with its skip save flag.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Events.SleepRefused(wouldSave => { if (wouldSave) TimbnGame.SaveNow(); });

SleepStarted(Action)

Runs when the player falls asleep, right after the game has gathered the loose resources around them and as the sleep fade begins. It does not run when the bed turns the player away for being rested, see SleepRefused(Action<bool>).

public IDisposable SleepStarted(Action handler)

Parameters

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

StoryTrigger(Type, Action<string>)

Runs when the game fires one of its story triggers, the signals its quests and cutscenes wait on, such as a building being built, an answer being picked, or a fight being won. The game has no event of its own for these, so Core raises it.

public IDisposable StoryTrigger(GlobalEventsSystem.Event.Type type, Action<string> handler)

Parameters

type GlobalEventsSystem.Event.Type

The kind of trigger to listen for.

handler Action<string>

Gets the trigger's id, such as the building or the answer, empty for triggers that have none.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Events.StoryTrigger(GlobalEventsSystem.Event.Type.BuildBuilding, building => Logger.LogInfo($"Built {building}"));

TechUnlocked(Action<string, bool>)

Runs when the player researches a technology, or the game unlocks one for them, such as the ones every save starts with. A mod's own craft or station needs no handler, since UnlockedBy(string) and UnlockedBy(string) put it on the tech, which also covers a save that had the tech already.

public IDisposable TechUnlocked(Action<string, bool> handler)

Parameters

handler Action<string, bool>

Gets the technology's id and whether the game unlocked it silently, with no popup, which it does for the ones a save starts with and for ones it puts back on load.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Events.TechUnlocked((techId, silent) => { if (!silent) Logger.LogInfo($"The player researched {techId}."); });

TimeOfDayChanged(Action<float, bool>)

Runs on every clock tick.

public IDisposable TimeOfDayChanged(Action<float, bool> handler)

Parameters

handler Action<float, bool>

Gets the time of day, running from 0 to 1 over a day, and whether it is a preview time that is not saved.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Update(Action)

Runs on every frame while a save is loaded, paused or not. It never runs on the main menu. Prefer EveryRealSeconds(float, Action) for work that does not need every frame or should stop while the game is paused. If the handler throws, the error is logged once and the handler is stopped instead of failing again every frame.

public IDisposable Update(Action handler)

Parameters

handler Action

Your handler.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Events.Update(() => stuckCarriers.Tick());

WindowOpened(Action<LazyWidgetBase>)

Runs when any of the game's windows opens, such as the inventory, a vendor or the main menu.

public IDisposable WindowOpened(Action<LazyWidgetBase> handler)

Parameters

handler Action<LazyWidgetBase>

Gets the window that opened.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Events.WindowOpened(window => Logger.LogInfo($"{window.GetType().Name} opened"));

WorldObjectDestroyed(Action<Wgo>)

Runs when a world object's view is destroyed.

public IDisposable WorldObjectDestroyed(Action<Wgo> handler)

Parameters

handler Action<Wgo>

Gets the view that is going away.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

WorldObjectSpawned(Action<Wgo>)

Runs when a world object's view is created, for every object of a scene as it loads and for any object added to the scene later.

public IDisposable WorldObjectSpawned(Action<Wgo> handler)

Parameters

handler Action<Wgo>

Gets the spawned object's view. Its Data property is the world object.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

ZombieViewReady(Action<WgoPart, ZombieWgoData>)

Runs when a zombie's view has been given its body, head, and skin, right after the view spawns and again whenever the zombie is restyled. Use it to change how a zombie looks, since the game redraws the view from its data and would undo a change made at any other time.

public IDisposable ZombieViewReady(Action<WgoPart, ZombieWgoData> handler)

Parameters

handler Action<WgoPart, ZombieWgoData>

Gets the part of the view that draws the zombie, whose Wgo is the view, and the zombie.

Returns

IDisposable

A handle that unsubscribes early when disposed. You don't need to keep it.

Examples

Events.ZombieViewReady((part, zombie) => ZombieTint.Paint(part, ZombieTint.Read(zombie)));