# scriptedEventsKit.overlay
This peer's own screen effects for cues: full-screen flashes and fades (to black and back, red pulses) and on-screen text in four styles (subtitle, whisper, title, objective), drawn on one UI screen above the game. Only the targeted players' engines call it. Used by the flash, fade and message beats.
# scriptedEventsKit.net
The multiplayer plumbing: who is host, who may write an entity (canWrite), the session clock, and the cue channels (cue:req, cue:run, cue:flag, cue:reset, cue:hello, cue:snap). Used by scriptedEventsKit.api and scriptedEventsKit.beats; tests drive it with _deliver and _tap.
# LightBehavior
Drives the point `Light`, spot `Light` or `SpotLight` on its entity. `style` picks the behaviour (16: dyingFluorescent, fluorescent, candle, fireplace, swingingBulb, emergencyRed, alarmBeacon, strobe, lightning, sparking, breathing, brownout, sodiumWarmup, tvGlow, neonStutter, steady). The synced `state` (on, off, flicker, short, restore) with `stateAt` is what triggers set; `group` tags and `circuit` names address lights for `eerieLightsKit.api`. Meshes on the entity and under it get the light's colour x level in shader-data lane 2 (wear `eerieLightsKit.fixtureGlow` to glow). Options: `intensity`, `styleColor`, `sound`, `volume`, `hang` (swing cord length), `shadows` (auto / always / never), `thunderDelay`, `seed`.
# scriptedEventsKit.targets
Resolves what designers write into entities and points (names, ids, globs, lists, parents with descendants, {x,y,z}), lists player bodies with their peers and reads the camera on screen. Used by every scriptedEventsKit module and by scaresKit.
# scriptedEventsKit.links
The optional kits scriptedEventsKit works with: interactKit.api, inventoryKit.inventory, tensionKit.api, saveKit.save, pickupsKit.api, soundstage.sfx, juiceKit.juice. scriptedEventsKit does not require them by name (a literal require is recorded as a dependency when the kit is published, which would make every optional kit a hard requirement of every install), so the game hands each module over:
```lua
local Links = require("~scriptedEventsKit.links")
Links.link("<kit>.<module>", require("~<kit>.<module>"))
```
- `Links.link(name, mod)`: link a module under its dotted name; `nil` unlinks it.
- `Links.get(name)`: the linked module, or nil.
- `Links.linked()`: the names linked now.
Links live in module state, so a hot reload keeps them. `require("~horrorKit.api")` links every kit it installs, so a horrorKit game needs no calls of its own.
# scriptedEventsKit
Named **scriptedEventsKit** since 1.0.1 (it was published as cueKit in 1.0.0). Search for either name.
**Scripted events for level designers: a trigger in the world plays an ordered list of beats.** Walk into the hall and the lights short out, a door swings shut two seconds later, a whisper, a flash, a subtitle. Write it as data, place it as a component, and it works the same for every player in a multiplayer world.
Version **1.0.4** (`Cues.VERSION`). The version, this README and `package.yaml` move together.
## Install
1. Install `scriptedEventsKit.package` from ZeroMind (search **scriptedEventsKit**), or copy the folder into `/source`. It depends on nothing, so the install brings no other kit. The optional kits it works with (interactKit, inventoryKit, tensionKit, saveKit, pickupsKit, soundstage, juiceKit) are handed over by the game through `scriptedEventsKit.links`, by their dotted module names: `require("~scriptedEventsKit.links").link("interactKit.api", require("~interactKit.api"))`. `require("~horrorKit.api")` links every one it installs. A trigger or beat whose kit is not linked does nothing. eerieLightsKit lights are found by entity name and group tag, with no link.
2. `local Cues = require("~scriptedEventsKit.api")` from any component, module or scene entrypoint.
3. Define cues when play starts (a scene `entrypoint.luau`, or a component's `start`), or place a **Cue** component on an entity.
## First example
```lua
local Cues = require("~scriptedEventsKit.api")
Cues.define("lightsOut", {
trigger = { kind = "area", entity = "hallTrigger", size = { 4, 3, 2 } },
once = true,
beats = {
{ "light", "hallLight*", "short" }, -- every light named hallLight...
{ "wait", 2 },
{ "show", "shape" },
{ "sound", "sk_sting", at = "shape" }, -- heard by everyone near it (a name scaresKit registers; without scaresKit pass a soundClip ref)
{ "flash", "red", alpha = 0.4 }, -- only the player who walked in
{ "message", "It is in here with you.", style = "whisper" },
{ "wait", 1.5 },
{ "hide", "shape" },
{ "light", "hallLight*", "restore" },
},
})
```
Or with no code: add `scriptedEventsKit.Cue` to an empty entity, set `size`, and fill `beats` with the same list. The editor draws its trigger box.
## Triggers
A cue takes one trigger or a list of them (any one fires it). `local` triggers are watched by each player's own engine for that player; `host` triggers by the host. Either way the host decides.
| kind | where | fields | fires when |
|---|---|---|---|
| `area` | local | `entity` or `at`, `size = {x,y,z}`, `shape = box/sphere`, `radius`, `on = enter/exit/inside`, `seconds` | a player enters / leaves / stays inside a box or sphere (uses an interactKit TriggerVolume's size if the entity has one) |
| `proximity` | local | `entity`, `radius = 3`, `on` | a player gets within `radius` of an entity, which may move |
| `look` | local | `entity` or `at`, `angle = 12`, `range = 25`, `seconds = 0.4`, `los = true` | the player keeps it inside a view cone for N seconds, with line of sight |
| `timer` | host | `after`, `from = "start"` or a cue id, `every` | N seconds after level start or after another cue fired; `every` repeats |
| `cue` | host | `after = "cueA"`, `delay` | chain: right after (or `delay` s after) cue A fires |
| `pickup` | host | `item`, `entity` | an item is picked up (interactKit Item collect, pickupsKit, or `Cues.notify("pickup", {item, peer})`) |
| `interact` / `door` | host | `entity`, `event = use/open/close/on/off/unlock/...` | an interactKit device is used, a door opens |
| `dread` | local | `above = 0.7` | the player's dread (tensionKit) rises past a level; nothing happens without tensionKit |
| `event` | host | `name` | your code calls `Cues.notify(name, { peer, at })` |
| `manual` | host | | only `Cues.fire(id)` |
Add your own with `Cues.registerTrigger(kind, { where, setup, tick })`.
## Beats
Beats run in order; only `wait` (and any beat with `wait = true` or `wait = seconds`) holds the timeline. `{"kind", main, second, field = ...}`: the first entry after the kind fills the main field.
| beat | scope | main, second | other fields |
|---|---|---|---|
| `wait` | time | seconds (or `{min,max}`) | |
| `sound` | world | clip | `at` (point/entity: 3D for everyone; none: 2D for the targeted players), `volume`, `maxDistance`, `pitch`, `loop`, `duration`. Clip = a soundClip ref, a name registered with `Cues.registerSound`, or a soundstage `"bank.sound"` |
| `light` | world | target, state | `on / off / flicker / short / restore / dim`; eerieLightsKit `LightBehavior.state` when present, else `Light.intensity`; `duration`, `level`, `intensity`, `style` |
| `animate` | world | target | `to = {pos, rot, scale}` or `by = {...}`, `duration`, `ease` (linear, inQuad, outQuad, inOutQuad, inCubic, outCubic, inOutSine, outBack, outBounce, slam, snap), `space = local/world` |
| `move` | world | target | `to` (point/entity), `rot` |
| `show` / `hide` | world | target | entity and all its children (models and lights) |
| `spawn` | host | model | `at`, `rot`, `scale`, `material`, `asset`, `physics = dynamic`, `mass`, `collider`, `light`, `lifetime`, `name` |
| `despawn` | world | target | |
| `impulse` | world | target | `force = {x,y,z}` or `from` + `strength` (+ `up`) |
| `shake` | personal | preset | juiceKit preset (`shakeLight`, `shakeHeavy`, `shakeRumble`, `shakeKick`, ...), `intensity` |
| `nudge` | personal | from | a small kick of the view away from a point |
| `look` | personal | at | eases the view toward a point, holds, hands it back: `turn`, `hold`, `release`, `strength` |
| `flash` | personal | color | `white / red / black / {r,g,b}`, `alpha`, `attack`, `hold`, `fade` |
| `fade` | personal | color | `duration`, `hold`, `back` (seconds, or `false` to stay dark) |
| `message` | personal | text | `style = subtitle / whisper / title / objective`, `speaker`, `duration` |
| `cutscene` | personal | def | an engine `cutscene.play` definition |
| `flag` | host | name, value | sets a world flag |
| `fire` | host | cue | fires another cue (its rules apply unless `force`), `delay` |
| `reset` | host | cue | forget that a cue fired |
| `enable` | time | cue | `on = false` turns it off |
| `call` | world | name | runs `Cues.register(name, fn)` on every peer: `fn(ctx, beat)`. The function's name is the beat's `name` field (where its main value lands), so a beat field called `name` REPLACES the function name: `{ "call", "spawnCorpse", name = "Ada" }` calls a function named `Ada`. Name it with `fn` instead to keep `name` for your data: `{ "call", fn = "spawnCorpse", name = "Ada" }` (`fn` wins when both are given) |
Every beat takes `chance = 0..1` and `only = "host"`. `Cues.registerBeat(kind, fn, { scope, main, second })` adds a beat; `fn(beat, ctx)` may return its length in seconds.
Scopes: **world** beats run on every peer and each entity is written by the one peer allowed to (its owner, or each peer for its own unshared copy), so every player sees the same door; **personal** beats run only for the cue's targeted players; **host** beats only on the host; **time** beats on everyone.
## Rules and conditions
| field | meaning |
|---|---|
| `once = true` | default: fires once per session (and per save with a state store) |
| `times = n` | fires at most n times |
| `["repeat"] = true`, `cooldown = s` | fires again after a cooldown |
| `when = { flags, notFlags, after, notAfter, item, test }` | needs flags set / unset, other cues fired / not fired, the triggering player holding an item (interactKit or inventoryKit), or your test |
| `players = "trigger" / "all" / "near"`, `near = 12` | who gets personal beats |
| `gate = fn(cue, ctx)` / `Cues.setGate(fn)` | a director may veto any fire |
| `enabled`, `label`, `data`, `save = false` | |
## API
| call | what it does |
|---|---|
| `Cues.define(id, spec)` / `undefine(id)` / `get(id)` / `list()` | author cues |
| `Cues.fire(id, { force, by, at })` | ask the host to fire it (manual trigger) |
| `Cues.fired(id)` / `hasFired(id)` / `isRunning(id)` / `whyNot(id)` | the ledger |
| `Cues.reset(id)` / `resetAll()` / `stop(id)` / `setEnabled(id, on)` | testing and control |
| `Cues.setFlag(name, v)` / `flag(name)` / `flags()` | world flags |
| `Cues.on(event, fn)` | events, returns a disconnect |
| `Cues.notify(name, data)` | feed `event` / `pickup` / `door` triggers from your code |
| `Cues.registerBeat` / `registerTrigger` / `register` / `registerSound` / `registerMaterial` | extend |
| `Cues.playBeats(list, opts)` | play a beat list on this peer only (directors, previews) |
| `Cues.setStateStore({get,set})` / `useSaveKit()` | keep the ledger between sessions |
| `Cues.setGate(fn)` / `setDebug(on)` | director veto; draw trigger volumes in play |
| `Cues.beatKinds()` / `triggerKinds()` | what is registered |
## Events
| event | data |
|---|---|
| `cueFired` | `{ id, by, count, origin }` (every peer) |
| `beat` | `{ id, index, kind, ran }` (every peer; `ran` false where a personal beat was not for this player) |
| `cueDone` | `{ id, by }` |
| `denied` | `{ id, by, reason }` (on the deciding peer) |
| `flag` | `{ name, value }` |
| `reset` | `{ id }` |
## Multiplayer
- The host decides every fire against one ledger (fired counts, last fire times, flags) that every peer mirrors; a cue fires once for the world even when two players walk in on the same frame.
- The host broadcasts `cue:run` with a start time on the session clock; every peer plays the beats from it, so doors, lights, props and positional sounds line up on every screen.
- Personal beats (flash, fade, shake, look, message, 2D sound) reach only the players the cue targets.
- A player who dies, respawns or rejoins keeps the world's ledger: a late joiner asks the host for a snapshot; a new host already has the mirror.
- With `Cues.setStateStore` (or `useSaveKit()`) the host writes the ledger so fired-once cues stay fired between sessions.
## Components
- **Cue**: a cue as fields (quick trigger + beats list, or a full `spec`); draws its area in the editor.
- **CueRunner**: spawned by the kit, one per peer in play; never added by hand.
## Known limits
- A cue defined with `Cues.define` lives in the kit's module state: it stays defined across play sessions in the same engine and fires again in the next session. Define cues where play starts (entrypoint `onLoad`, a component's `start`), not from a one-off script, or `undefine` them.
- The forced `look` is a glance: the builtin first-person controller keeps its own yaw and pitch, so the view eases toward the point and back rather than staying turned.
- Entities are addressed by name, glob or parent (the engine has no tag API); a light group is a parent entity or a name pattern.
- Beat sound and material names must be registered refs (`Cues.registerSound`); a world cannot resolve asset names computed at runtime and still publish.
- A cue's own beats are not replayed for a player who joins after it ran; state that must persist (an opened door, a spawned prop) should live on synced entities or flags.
## 1.0.4
The `call` beat also takes its function name from `fn`, so a beat can carry a data field called `name` (before, `name` is where the beat's main value lands, so a `name` field silently replaced the function name). README documents the clash. The package test reads the package.yaml and README beside the install, so it passes under deps/ and showcase/ too. New test.
## 1.0.3
The tests wait for the preview pictures a fresh install is still drawing before each test, so their first run no longer logs "camera texture not found" errors. No changes outside the tests.
## 1.0.2
README only: the install brings the packages `package.yaml` declares (it said it needed none); the first example's `sk_sting` sound is a name scaresKit registers; a cue defined from code stays defined in that engine across play sessions, so define it once (an entrypoint or a component's `start`).
## 1.0.2 (links)
Depends on nothing: tensionKit, interactKit, inventoryKit and saveKit are no longer declared, and no optional kit (pickupsKit, soundstage, juiceKit included) is required by name any more. They are linked by the game through `scriptedEventsKit.links`; `require("~horrorKit.api")` links them.
## 1.0.1
Renamed from cueKit. Declares its dependencies with versions. Test suite renamed scriptedEventsKitTests.
# eerieLightsKit 1.0.1, flickering, dying and swinging lights for horror levels
Named **eerieLightsKit** since 1.0.1 (it was published as flickerKit in 1.0.0). Search for either name.
Placed-light behaviours. Put **LightBehavior** on any entity carrying a point `Light`, a spot `Light` or a `SpotLight` and it drives that light: a dying fluorescent tube that buzzes and stutters, a bulb that really swings on its cord so the shadows sweep the room, a red emergency light, a rotating alarm beacon, lightning through a window with thunder behind it, a sparking broken fixture, and more. Every light carries a synced **state** (`on`, `off`, `flicker`, `short`, `restore`) that triggers and scripted scares set, by name, by tag, or by power circuit. Two shadow-reveal helpers come with it: a **Silhouette** that is only ever seen as a shadow on the wall, and an **Apparition** that stands in a doorway only while a light flickers.
## Install
Search ZeroMind for **eerieLightsKit** and install it, or copy `eerieLightsKit.package` into your world. No dependencies.
## First example
```lua
local lamp = entity.spawn("Hall_Light_01")
lamp.position = vector.create(0, 2.9, 0)
lamp.component.add("Light", { kind = "point", intensity = 8, radius = 9, castsShadows = true })
-- a glowing tube that lights up with the light and goes dark with it
local tube = entity.spawn("tube", { parent = lamp })
tube.localScale = vector.create(0.12, 0.05, 1.3)
tube.component.add("Model", { model = "@builtin::meshes.cube", material = "eerieLightsKit.fixtureGlow", castsShadows = false })
lamp.component.add(asset.resolve("eerieLightsKit.LightBehavior", "component"), { style = "dyingFluorescent", group = "hall", circuit = "wingB" })
```
```lua
local Lights = require("eerieLightsKit.api")
Lights.setState("Hall_Light_01", "short") -- spark, pop, dark
Lights.setGroup("hall", "flicker") -- every light tagged hall
Lights.circuit("wingB", false) -- the power dies
Lights.circuit("wingB", true, { stagger = 0.8 }) -- comes back one light at a time
Lights.on("stateChanged", function(e) print(e.entity, e.state) end)
```
## Styles
| style | what it does | colour | sound |
|---|---|---|---|
| `dyingFluorescent` | hums at 90 %, then bursts of rapid on/off with a ballast ping | cool white | tube hum loop, ping |
| `fluorescent` | strikes on with a stutter, then steady with a faint shimmer | cool white | hum loop |
| `candle` | gutters, dips, the flame position flutters | orange |, |
| `fireplace` | slow roll plus crackle flicker, moving light | deep orange | fire loop |
| `swingingBulb` | the light and its bulb swing on a cord (`hang` m) so shadows sweep the room | warm | chain creak loop |
| `emergencyRed` | dim, steady, slow breathe | red |, |
| `alarmBeacon` | rotates about its up axis (use a spot) | red-orange | klaxon loop |
| `strobe` | hard 7 Hz strobe | white | strobe ticks |
| `lightning` | dark, then rare double flashes through a window; thunder arrives 1–4 s later | blue-white | thunder |
| `sparking` | sputtering low light with bursts, sparks fly and bounce | white | crackle + sparks |
| `breathing` | slow pulse 12–100 % | (light's own) |, |
| `brownout` | sags with the power, occasional dips | dim amber |, |
| `sodiumWarmup` | from a pink glow to full orange over ~12 s after it comes on | sodium orange | ballast buzz |
| `tvGlow` | jumpy cuts between brightness levels | blue | static hiss |
| `neonStutter` | steady, then word-by-word stutters | magenta | neon buzz |
| `steady` | just obeys the state | (light's own) |, |
`styleColor = false` keeps the light's own colour. `require("eerieLightsKit.styles").define(id, { label, level = function(t, seed, since) ... end, color?, loop?, swing?, spin?, jitter?, sparks?, thunder? })` adds your own.
## States
| state | meaning |
|---|---|
| `on` | the style runs |
| `off` | dark (hum stops) |
| `flicker` | violent flicker over the style until changed |
| `short` | surge, spark shower, pop, then dark |
| `restore` | stutters back on over 1.8 s, then behaves as `on` |
A state carries `stateAt`, a session time: a change can be scheduled (`Lights.setState(t, "off", 2)` goes dark on every screen 2 s from now) and a circuit's lights come back staggered.
## API (`require("eerieLightsKit.api")`)
Targets are an entity, an id, a name, a glob (`"Hall_*"`) or a tag (a word in the light's `group` field or the entity's `tags` attribute).
| call | does |
|---|---|
| `Lights.setState(target, state, delay?)` | returns how many lights it reached |
| `Lights.setGroup(tagOrName, state, delay?)` | the same, for groups |
| `Lights.setStyle(target, style)` | switch behaviour |
| `Lights.circuit(name, on, { stagger, delay, short, from })` | power circuits: die together, come back one by one (nearest-first from `from`: a `{ x, y, z }` point, a vector, an entity or its name) |
| `Lights.point(p)` | the world point any of those forms names (nil when it names nothing) |
| `Lights.state(target)`, `Lights.levelOf(target)`, `Lights.list()`, `Lights.styles()` | reading |
| `Lights.silhouette(target, "play" \| "stop", delay?)` | start a Silhouette walking on every screen at once |
| `Lights.setQuality("high" \| "medium" \| "low")` | shadow budget 6 / 3 / 1 lights, update range 60 / 45 / 30 m |
| `Lights.on("stateChanged", fn) -> disconnect` | `{ entity, state, previous, style }` on every peer |
Entity-level contract (no require needed): set the `LightBehavior` fields `state` / `style` on the owning peer.
## Shadow reveals
- **Silhouette**, on an empty entity between a light and a wall. Its figure (`figure`, `tall`, `crawler`, `hand`) goes on the `fk_shadowOnly` render layer, which every player's camera skips while the shadow maps still draw it: you see a shadow slide across the wall and nothing that casts it. `path = "4,0,0; 4,0,-3"` (local offsets), `speed`, `loop`, `playing` (synced, started on every peer at the same session time). `shadowOnly = false` makes it a visible black figure.
- **Apparition**, a dark figure linked to a light (`light` = name or tag). While `armed`, when that light flickers, shorts or restores it shows in the lit frames (a black shape against the light, or in the dark frames with `showIn = "dark"`) for `window` seconds, then it is gone; `once` disarms it.
## Fixtures
Meshes on the light's entity and under it get the light's colour × level written to shader-data lane 2 every time it changes. Wear `eerieLightsKit.fixtureGlow` (unlit, emissive from that lane) or any instance-colour material on the tube / bulb / sign / screen and it glows when lit and goes dark when off, per lamp.
## Multiplayer
Placed lights are world state. The entity's owner writes `state`, `stateAt`, `style`; a change asked on any other peer is sent to the owner. Every peer computes the same flicker from the light's `seed` and `multiplayer.sessionTime()`, so all players see the same stutter, short and lightning flash with nothing sent per frame. Sounds and sparks are local to each peer, played from the same moments.
## Performance
About 0.07 ms of script per near light per frame (measured), less when nothing changes (the light is written only when its level moves). Lights farther than the quality's update range from the camera update twice a second. Only the nearest N shadow-casting lights (N = 6 / 3 / 1 by quality) keep `castsShadows`, re-picked twice a second. Sounds only play for near lights: a hum / fire / alarm loop exists only while the main camera (where the player hears from) is within its 18 m earshot (removed again past ~24 m), and a one-shot (ping, pop, spark, relay) is not started at all out of its earshot and is removed the moment its clip ends. Every live spatial source costs the engine a position sync each frame, so a level full of lights keeps only the handful you can hear (Brinefall Station: 21-34 live sources down to 13-19).
## Known limits
- The shadow-only trick edits each peer's main camera `renderLayers` (adds `!fk_shadowOnly`); a camera you create yourself needs the same token.
- Swinging, spinning and flame jitter move the light's own entity in play (the authored pose is the swing anchor); don't also animate that entity.
- `fk_relay` (restore click for non-fluorescent lamps) reuses the tube ping: the generated relay click was refused by the audio service.
## 1.0.1
Renamed from flickerKit. Fixture glow follows its light (a lamp whose Light is disabled counts as off). Lights update only as often as they need to (every frame within 20 m, 20 Hz beyond, 2 Hz past the cull distance, 4 Hz once settled) with no per-frame allocations. Quality is picked from the device; high is 4 shadow-casting lamps. Fixed a crash when entity positions came back as a proxy.
## 1.0.2
A registered light whose id is no entity (the test suite's stand-ins, or a light despawned while registered) no longer writes an engine error on every lookup; it is skipped quietly.
## 1.0.3
Leaving play is quiet: a light's cleanup removes its sound loop and sparks by id, only when they still exist, instead of reaching for entities the scene teardown already removed (that logged an error on every stop).
## 1.0.4
A light plays without errors before anyone listens: its sounds only look up where the listener stands when the listener names an entity that exists, so a scene with no player or camera yet (the first README example on its own) no longer logs "no entity with an empty id" every few seconds. Leaving play stays quiet.
## 1.0.5
A light plays and buzzes with no errors when nobody is listening yet. Its sounds now judge earshot from the main camera and never ask the audio system for its listener: that report snapshots the whole mix, and while no listener exists it names an empty one the engine logs about ("no entity with an empty id" every 2 to 4 s; 1.0.4 guarded the wrong step). With no camera at all a sound simply plays unculled. Leaving play stays quiet.
## 1.0.6
`Lights.circuit(name, true, { from = ... })` no longer crashes on a starting point given as `{ x, y, z }` (it read `from.x` only, so a list of three numbers, an entity name or an id stopped the restore, and a power-restored cue that called it never finished). `from` now takes a `{ x, y, z }` list, `{ x =, y =, z = }`, a vector, an entity, or an entity's name or id; a name that names nothing falls back to name order. New `Lights.point(p)` answers the world point any of those forms names. Contributed in pull request #2; the entity case and the test for every form were added on review.