# 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.
# bulkheadKit
Build derelict sci-fi interiors in code: research stations, ships, bunkers, submarines, labs, maintenance tunnels. One call builds a room or corridor with real doorway openings, door frames, structural ribs and ceiling beams, pipe runs, cable trays and trims; another places one of 30 procedural props. Six surface themes switch the whole look with one word. Made for horror levels (it builds the demo level of the horror kit in this world, *Brinefall Station*), and works for any interior.
Version **1.0.3** (`Build.VERSION`).
## Install
Search ZeroMind for **bulkheadKit** and install `bulkheadKit.package`, or `zero zeromind installAsset <guid>` in the shell. It needs nothing else: the surfaces it builds with ship inside it.
## First example
In a scene's `build.luau`:
```lua
local B = require("bulkheadKit.build")
function content()
local root = entity.spawn("Station")
B.useTheme("derelict") -- pale green bulkheads, grating, rusty pipes
-- a 3 m wide, 20 m long corridor with a doorway at its north end
local hall = B.room("hall", { x0 = -1.5, x1 = 1.5, z0 = 0, z1 = 20, h = 3.2,
openings = { { side = "N", at = 0, w = 1.6, h = 2.3 } } }, root)
-- a lab beyond it, in another theme
B.useTheme("clinical")
local lab = B.room("lab", { x0 = -6, x1 = 6, z0 = 20.3, z1 = 32, h = 4,
skipWalls = { S = true } }, root)
B.prop("labBench", { 0, 0, 25 }, 0, lab.root)
B.prop("tank", { -4, 0, 29 }, 0, lab.root)
B.prop("fluoro", { 0, 3.95, 25 }, 90, lab.root) -- ceiling fixture; put your Light under it
end
```
Two rooms that touch share one wall: give one of them `skipWalls` on that side and cut the doorway (`openings`) on the other.
## Rooms: `B.room(name, spec, parent?) -> { root, cuts, center, y, h }`
`spec` is the inner floor rectangle and what to put round it:
| field | meaning | default |
|---|---|---|
| `x0, x1, z0, z1` | inner floor rectangle, metres (+Z = north) | required |
| `y`, `h` | floor height and room height | 0, 3.2 |
| `wall` | wall thickness | 0.3 |
| `openings` | doorways `{ side = "N"/"S"/"E"/"W", at = centre along that wall, w, h, sill }` (a sill makes a window) | none |
| `skipWalls` | `{ N = true, ... }` sides left open (corridor ends, shared walls) | none |
| `ribs` | spacing of structural frames on the long walls and beams across the ceiling (0 = none) | 2.4 |
| `pipes`, `trays` | the pipe bundle along one long wall and the cable tray down the middle | on |
| `noFloor`, `noCeiling` | leave them out (pools, shafts, ramps, open sky) | off |
| `floor`, `walls`, `lower`, `ceiling` | a material or theme role for this room only | the theme's |
Walls have a dark lower band (`wallLower`) to 1.05 m, a skirting and a dado rail, and every doorway gets jambs and a header in the theme's `trim`. Walls and floors carry box colliders; decoration does not.
## Themes: `B.useTheme(name)`
| theme | walls | floor | for |
|---|---|---|---|
| `derelict` | chipped pale-green riveted bulkhead | rusty grating | research stations, the default |
| `hull` | dark bolted pressure hull | wet tread plate | docks, engine rooms, the deep parts of a ship |
| `clinical` | cracked white tile | studded rubber | med bays, labs, showers |
| `concrete` | damp stained concrete | grating | pump rooms, service tunnels, basements |
| `quarters` | green over wood laminate | rubber | cabins, offices, a mess |
| `industrial` | dark green over hazard stripes | tread plate | plant rooms, cargo holds |
The surfaces are generated PBR sets (colour, normal, roughness/metal) wrapped with the engine's world-space **triplanar** shader, so a 20 m wall and a 0.3 m jamb both tile at real size and nothing stretches. `B.material(roleOrName)` returns any of them for your own parts.
## Props: `B.prop(kind, pos, yaw?, parent?, opts?) -> group`
Every prop is built round its own floor point, facing -Z, and placed with `pos` and `yaw` (degrees). `B.propKinds()` lists them:
| kind | what | options |
|---|---|---|
| `locker` | row of steel lockers | `count`, `openIndex` (one door hangs open) |
| `bunk` | two-tier bunk with mattresses, blankets, ladder | |
| `desk` | steel desk, drawers, papers, lamp, mug, chair | `chair = false`, `chairYaw` |
| `chair` | swivel chair | |
| `crate`, `cases` | strapped crate; a stack of three cases | `size`, `mat` |
| `shelf` | four-shelf rack with boxes | `seed` varies the contents |
| `labBench` | steel bench, microscope, jars, tray, clipboard | |
| `console` | control desk, toggles, three CRT monitors | `screens = false` for dead screens |
| `tank` | cylindrical specimen tank with murky fluid | `height`, `fluid = false` |
| `pump` | pump housing, motor, plinth, pipes, valve wheel, gauge | |
| `gurney` | med-bay gurney with instrument trolley | |
| `gasTanks` | four chained gas cylinders | |
| `vent` | wall duct mouth whose grate is its own child entity `grate` (blow it off in a scare) | `size` |
| `fluoro` | caged double fluorescent fixture (tubes `tubeA`/`tubeB`) | `off = true` for dead tubes |
| `wallLamp` | caged bulkhead lamp | `glow` = glowRed, glowAmber, glowTube, glowCold |
| `hangingBulb` | bare bulb on a cord (`bulb`) | `cord`, `glow` |
| `valveWheel`, `hatchRing` | brass valve wheel; bolted pressure-hatch ring for a doorway | `size` |
| `divingBell`, `submersible` | hero props for a dive bay and a sub dock | |
| `bodyBag`, `papers`, `cable`, `barrel`, `table`, `puddle` | dressing | |
Lower level: `B.part`, `B.box`, `B.pipe(parent, name, a, b, radius, material?)`, `B.group`, `B.quatYaw`, `B.quatAxis`, `B.quatMul`. Rooms and props call `B.part` through the table, so wrapping it reaches everything they make.
## Batching: `B.collect(fn, body)`
Every prop part is its own Model entity by default. To batch, build inside `B.collect`: each visible part goes to `fn(part)` instead, as `{ parent, name, mesh, center, size, rot?, material, shadows, tint? }` (`center`, `size`, `rot` local to `parent`, the room or prop group entity, which is still spawned and placed). Parts with a collider still spawn an entity carrying only the BoxCollider; invisible helper parts never reach `fn`.
```lua
local parts = {}
B.collect(function(p) table.insert(parts, p) end, function()
B.prop("locker", { 1.2, 0, 6 }, -90, root)
B.prop("desk", { -1, 0, 4 }, 0, root)
end)
-- merge `parts` by material into your own meshes or one quickGeometry Group
```
## Multiplayer
Everything is plain scene content built at author time and baked into the scene, so every player loads the same station. Put moving or scripted things (doors, lights that fail) on synced entities with the kits that drive them.
## Performance
A room is ~40–120 primitive entities; a 10-room level is ~1,900. Props share a handful of materials. Fixture glows are emissive and cast no light; add real Lights only where they matter and keep shadow-casting lights few.
## Known limits
- Props are built from primitives (boxes, cylinders, tori, capsules), not sculpted meshes. They read well in the dark; up close they read as stylised.
- Ramps are a rotated box (`B.box` with a `rot`), so stairs are not modelled step by step.
- Rooms are axis-aligned rectangles.
## 1.0.1
Props use lit materials instead of tints, so nothing shows in total darkness. Fixture glow follows its light.
## 1.0.2
Ships a test suite, `bulkheadKitTests`: every theme and prop builds, unknown names are refused, doorways open, the README example builds (all dry runs, nothing lands in your scene).
## 1.0.3
Surfaces no longer render black under a camera with `environment = "isolated"`: the triplanar materials shipped `metallic: 1`, so every surface took its metalness from the packed texture at full strength and reflected nothing where there is no environment. Painted bulkheads, concrete, ceiling panels, tiles, rubber, hazard paint and wood are now `metallic: 0`; the rusty grating 0.25, the painted hull 0.3, tread plate 0.45, rusted pipe 0.2, dark steel trim 0.55 (brass stays 1). New `B.collect(fn, body)` hands visible parts to the caller for batching instead of one Model entity per part (colliders still spawn), and rooms and props call `B.part` through the table so a wrapper reaches them. The version test reads the package.yaml beside the install, so it passes under deps/ and showcase/ too. Two new tests.