Class Events
Provides easy hooks to various things happening in the game.
Namespace: Modding
Assembly: Assembly-CSharp.dll
Syntax
public class Events : SingleInstance<Events>
Constructors
Events()
Declaration
public Events()
Properties
Name
Declaration
public override string Name { get; }
Property Value
Type | Description |
---|---|
String |
Overrides
Methods
SetUp()
Declaration
public override void SetUp()
Overrides
Events
OnBlockInit
Called while a new block is being initialized.
This is called for new blocks placed in building mode but also for block clones being created for simulation.
Blocks will not have loaded their mapper type data yet at this point, which means it is possible to add mapper types to the blocks here.
MP: Always called on all connected instances.
Declaration
public static event Action<Block> OnBlockInit
Event Type
Type | Description |
---|---|
Action<Block> |
OnBlockPlaced
Called when a block was placed on a machine.
This is called for blocks placed in build mode and only once the block has been completely initialized.
Adding Mapper Types to blocks here does not work correctly,
use OnBlockInit
for that.
MP: Called only on the instance that places the block.
Declaration
public static event Action<Block> OnBlockPlaced
Event Type
Type | Description |
---|---|
Action<Block> |
OnBlockRemoved
Called when a block is removed from a machine.
The passed block will be destroyed immediately after the event handlers for this were executed.
MP: Called only on the instance that removes the block.
Declaration
public static event Action<Block> OnBlockRemoved
Event Type
Type | Description |
---|---|
Action<Block> |
OnConnect
Called when connecting to a multiplayer session.
Also called when starting up a server.
Declaration
public static event Action OnConnect
Event Type
Type | Description |
---|---|
Action |
OnDisconnect
Called when disconnecting from a multiplayer session.
Also called when shutting down a server.
Declaration
public static event Action OnDisconnect
Event Type
Type | Description |
---|---|
Action |
OnEntityPlaced
Called when an entity (level object) is placed.
MP: Always called on all connected instances.
Declaration
public static event Action<Entity> OnEntityPlaced
Event Type
Type | Description |
---|---|
Action<Entity> |
OnEntityRemoved
Called when an entity is removed.
The passed entity will be destroyed immediately after the event handlers for this were executed.
MP: Always called on all connected instances.
Declaration
public static event Action<Entity> OnEntityRemoved
Event Type
Type | Description |
---|---|
Action<Entity> |
OnLevelDeleted
Called when a level is cleared (deleted).
Called on all connected instances, because the level is always the same for everyone. Also called in the preparation for joining or loading a level.
Declaration
public static event Action OnLevelDeleted
Event Type
Type | Description |
---|---|
Action |
OnLevelLoaded
Called when a level was loaded.
Always called on all connected instances when the loaded level of the session actually changed, because the level is always the same for everyone. Also called when joining a server and loading the current level, but only on the joining instance.
Declaration
public static event Action<Level> OnLevelLoaded
Event Type
Type | Description |
---|---|
Action<Level> |
OnLevelSave
Called when the current level is being saved.
Called only on the instance that saves the level.
Declaration
public static event Action<Level> OnLevelSave
Event Type
Type | Description |
---|---|
Action<Level> |
Remarks
The host may automatically save the level to send it to joining players.
OnLevelSetupChanged
Called when the settings of the current level were edited.
Called on all connected instances.
Declaration
public static event Action<LevelSetup> OnLevelSetupChanged
Event Type
Type | Description |
---|---|
Action<LevelSetup> |
OnLevelWonMP
Called when a multiplayer level is won.
Called on the server and all clients that have global sim toggled on when in global sim. If a client has global sim off, but is in building mode, this event does not fire. Called only on the instance that's simulating when in local sim.
Parameter: The list of teams that have won (can also be MPTeam.None).
Declaration
public static event Action<List<MPTeam>> OnLevelWonMP
Event Type
Type | Description |
---|---|
Action<List<MPTeam>> |
OnLogicChainTriggered
Called when a logic chain is triggered.
MP: Called only on the instance running the simulation.
Declaration
public static event Action<LogicChain> OnLogicChainTriggered
Event Type
Type | Description |
---|---|
Action<LogicChain> |
OnLogicEventExecuted
Called when a logic event is executed.
MP: Called only on the instance running the simulation.
Declaration
public static event Action<LogicEvent> OnLogicEventExecuted
Event Type
Type | Description |
---|---|
Action<LogicEvent> |
OnMachineDestroyed
Called when a machine is destroyed (deleted).
MP: Only called on the instance deleting its machine.
Declaration
public static event Action OnMachineDestroyed
Event Type
Type | Description |
---|---|
Action |
OnMachineLoaded
Called when a machine was loaded.
Custom data that was saved will have been put back into PlayerMachineInfo.MachineData.
MP: Called only on the instance that loaded.
Declaration
public static event Action<PlayerMachineInfo> OnMachineLoaded
Event Type
Type | Description |
---|---|
Action<PlayerMachineInfo> |
OnMachineSave
Called when a machine is being saved.
Custom data can be saved into PlayerMachineInfo.MachineData here, it will then be saved in the machine.
MP: Called only on the instance that saves.
Declaration
public static event Action<PlayerMachineInfo> OnMachineSave
Event Type
Type | Description |
---|---|
Action<PlayerMachineInfo> |
See Also
OnMachineSimulationToggle
Called when the simulation for a machine is toggled on or off.
Declaration
public static event Action<PlayerMachine, bool> OnMachineSimulationToggle
Event Type
Type | Description |
---|---|
Action<PlayerMachine, Boolean> |
Remarks
In singleplayer, this works like OnSimulationToggle
. It is called whenever simulation is
started or stopped.
In multiplayer, the event is always called for every machine entering or exiting simulation, on all connected instances. This includes when machines enter or exit local simulation.
OnPlayerJoin
Called when a player joins a multiplayer session.
Only called on the host.
Declaration
public static event Action<Player> OnPlayerJoin
Event Type
Type | Description |
---|---|
Action<Player> |
OnPlayerLeave
Called when a player leaves a multiplayer session.
Only called on the host.
Declaration
public static event Action<Player> OnPlayerLeave
Event Type
Type | Description |
---|---|
Action<Player> |
OnProgressAddedMP
Called when level progress is added in multiplayer.
Called on the server and all clients that have global sim toggled on when in global sim. If a client has global sim off, but is in building mode, this event does not fire. Called only on the instance that's simulating when in local sim.
Declaration
public static event Action<MPTeam, float> OnProgressAddedMP
Event Type
Type | Description |
---|---|
Action<MPTeam, Single> |
OnSceneWithModsCameraInitialised
Called when the camera has finished its initialization in a scene where mods should be active (singleplayer levels and multiplayer scene).
Camera initialization is the fade-in / rotate-in effect when loading a level.
Declaration
public static event Action OnSceneWithModsCameraInitialised
Event Type
Type | Description |
---|---|
Action |
OnSceneWithModsLoaded
Called when a scene is loaded in which mods should be active.
These scenes are all singleplayer levels (including sandboxes) and the multiverse scene.
The event is not fired when loading the title screen or a level select screen.
Declaration
public static event Action OnSceneWithModsLoaded
Event Type
Type | Description |
---|---|
Action |
OnSimulationToggle
Called when the simulation for the level is toggled on or off.
Declaration
public static event Action<bool> OnSimulationToggle
Event Type
Type | Description |
---|---|
Action<Boolean> |
Remarks
In singleplayer, this is functionally equivalent to the OnMachineSimulationToggle
and called whenever simulation is started or stopped.
In multiplayer, behaviour depends on whether the local instance is set to local or global simulation.
For global simulation, this event is called when the level overall starts or stops simulating. It is called on the instance causing the simulation to start and all other instances that are in build mode and set to global simulation.
When an instance is set to local simulation, the event works like in singleplayer. It does not get called when global simulation is started or stopped, but it gets called when the local player starts or stops simulation.
The result of these rules is that the last value given by the even always reflects whether the local instance is currently involved in a simulation.