Events
Surveillance the three surveillance events
This is the class to start from. PlayerSpotted tells you when a camera or a person spots the player, and TrespassEntered and TrespassLeft tell you when the player enters or leaves a trespassing area.
public static class Surveillance
{
public static event Action<PlayerSpottedArgs> PlayerSpotted;
public static event Action<TrespassArgs> TrespassEntered;
public static event Action<TrespassArgs> TrespassLeft;
}
| Event | Gives you | When it fires |
|---|---|---|
PlayerSpotted | PlayerSpottedArgs | A camera or a person has just spotted the player. |
TrespassEntered | TrespassArgs | The player has just entered a trespassing area. |
TrespassLeft | TrespassArgs | The player has just left a trespassing area. |
SurveillanceSource who spotted the player
PlayerSpottedArgs.Source gives you one of these.
public enum SurveillanceSource
{
Camera = 0,
Witness = 1
}
| Value | Meaning |
|---|---|
Camera | A security camera spotted the player. |
Witness | A person or another watcher spotted the player. |
PlayerSpottedArgs what PlayerSpotted tells you
The PlayerSpotted event gives you one of these. Source says whether a camera or a person spotted the player, and NpcId is the person’s number, or 0 for a camera.
public sealed class PlayerSpottedArgs
{
public SurveillanceSource Source { get; }
public string Id { get; }
public int NpcId { get; }
}
| Property | Type | What it means |
|---|---|---|
Source | SurveillanceSource | Whether a camera or a person spotted the player. |
Id | string | The camera’s id, or the watcher’s id. The same form as in Cameras(). |
NpcId | int | The number of the person who spotted the player. 0 for a camera, or for a watcher that is not a person. |
TrespassArgs what TrespassEntered and TrespassLeft tell you
The TrespassEntered and TrespassLeft events give you one of these, with the AreaId of the trespassing area.
public sealed class TrespassArgs
{
public string AreaId { get; }
}
| Property | Type | What it means |
|---|---|---|
AreaId | string | The id of the trespassing area. |
Things to know
PlayerSpottedfires when a camera or a person spots the player during a check the game runs. That is a check for a theft or another crime. It fires at most once per watcher per frame. Only crime checks make the game react, but the plain sight checks fire the event too. (It is raised when a witness check passes withinvokeon. For a person,Idis the id of the witness component.)PlayerSpottedis not the camera’s alarm. The game’s own camera alarm, which goes off after the camera has watched the player for a while, is not available to mods. (The game’sDetectionTimer, afterdetectionTimein-game seconds, is private.)Law.Spottedis a different event fromPlayerSpotted.Law.Spottedonly fires when a crime was seen and has no source. Use it for “a crime was seen”. Both can fire for the same check, andPlayerSpottedfires first. Do not add or remove watchers from inside aPlayerSpottedhandler. (PlayerSpottedfires inside the game’s witness loop, so handlers must not add or remove witnesses synchronously.)TrespassEnteredfires once when the player first stands in a trespassing area that is switched on. An area that is turned off for the player does not raise it.TrespassLeftfires when the player walks out of an area whose entry the framework saw. It fires at the moment of leaving, before the game’s one second cooldown ends. It also fires when a scene change destroys an area the player was in. Trespass crimes are not raised here: they appear inLaw.CommittedasCrimeKind.Trespassing. (It is raised from the game’sOnTriggerExit. For a destroyed area, it is raised with the area id seen at entry.)- A sudden move inside an area can raise a leave and an enter. If the player is moved more than 3 metres inside an area without the game reporting an exit, for example by a teleport,
TrespassLeftfires and thenTrespassEnteredagain, because the next report counts as a new entry. A move of 3 metres or less is not noticed. Neither is a move out and back when the game reports no exit in between. (The framework sees the player only on the game’sOnTriggerStayandOnTriggerExitreports, so these misses cannot be closed.) - The framework only watches trespassing while someone is listening. Entry tracking starts when you add a
TrespassEnteredorTrespassLefthandler. If you add a handler while the player is already inside an area, you getTrespassEnteredon the next physics frame in the area.TrespassLeftis only raised for areas whose entry the framework saw. IsAvailableisfalsewhen any of the surveillance events could not be set up. Each event depends only on its own part:PlayerSpottedon the witness part, andTrespassEnteredandTrespassLefton the trespass part. The reads andSetCameraActivekeep working. See “If something fails to set up” on the Details page.