Sanity Events
The Sanity System in Distorted Vigil is built with modularity at its core. Instead of manually registering every hallucination or effect, the system uses Reflection to automatically discover and execute your custom events.
To add a new insanity effect, you simply need to create a new C# class that inherits from
SanityEvent.
🛠 The Base Class
Every sanity event must inherit from the
SanityEvent abstract class. This class defines the lifecycle and the triggering conditions of your effect.
📋 Parameters
These properties define when and how often your event will occur. You can override them in your custom class:
A unique string ID (e.g., "hallucination_whisper"). Used for internal cooldown tracking.
The minimum sanity value required for the event to be eligible.
The maximum sanity value required for the event to be eligible.
Percentage chance (0-100) to trigger during the system's check interval.
How long the event stays active (in seconds).
How long to wait before this specific event can trigger again.
🔄 Lifecycle Methods
Each event has three main stages. Understanding these is key to creating smooth effects:
1. onStart(SanitySystem system)
Triggered exactly once when the event begins.
Use for: Initializing visual effects, playing a "start" sound, or spawning a temporary object.
Tip: Always check
if (system.IsOwner)to ensure effects only apply to the local player.
2. onUpdate(SanitySystem system)
Runs every frame while the event is active.
Use for: Fading out a screen overlay, shaking the camera, or moving a "shadow person" closer to the player.
3. onStop(SanitySystem system)
Triggered exactly once after the duration ends.
Use for: Cleanup. Resetting the camera rotation, hiding UI, or stopping looping audio.
💻 Code Example
Here is a complete template for a "Screen Tilt" event:
💡 Best Practices
Check Ownership: Since this is a multiplayer game using FishNet, always use
system.IsOwnerinside your methods. You don't want a local hallucination to affect other players' cameras!
Cleanup is Key: Always ensure onStop reverts any changes you made during onStart or onUpdate.
Unique IDs: Make sure your
eventIDis unique. If two mods use the same ID, their cooldowns will interfere with each other.
Last updated