# Event director and nights

> How many random events reach the player in a day, the night director that brings crime and strange things after dark, and how your mod adds a scene to the night table.

Source: https://underlives.com/docs/gameplay/event-director

`ul_Core` paces the random events of every mod: a **daily budget** for the everyday ones, and a **night director** that rolls its own table of crimes and strange things from 20:00 to 06:00. Both are settings on the player's *Event Director* page (Mods panel), and both are open to your mod.

## The daily budget

A random scene asks the director before it plays:

```lua
if EventDirector and not EventDirector.allow(Game, "money", "flavour") then return false end
```

or, in a [declarative scene](/docs/scripting/declarative-scenes), `director = { "money", "flavour" }`.

| Argument | Values |
| --- | --- |
| category | `career`, `learning`, `hobbies`, `sport`, `family`, `social`, `money`, `travel`, `wellbeing`, `offbeat`, `life`, `daily`, `relationships`, `danger`. The player can switch each one off. An unknown category is treated as `misc`: never switched off, still counted. |
| priority | `flavour` (counted against the day's budget, 3 by default), `social` (one slot more), `story` (always passes: a quest step, a message the player waits for). |

Holiday mode lets only story events through. Quiet hours (23:00 to 07:00) are off unless the player turns them on. A test run with `-ModSetting=dev.dice=true` lets everything through.

`danger` is the night director's category. It never spends the day's budget: it has **its own budget per night**, which runs from 20:00 to 20:00 the next day, so a scene of yours that asks `allow(Game, "danger", "flavour")` at any hour counts against the night it belongs to.

## The night director

The roll after an action is not night-aware: it shuffles every scene that fits the place and the hour, and most crime scenes refuse at their own odds. The night director rolls its own table instead (owner, 2026-11-26: nights are brutal by default, with a setting to turn them down).

- **Every game hour from 20:00 to 06:00**, with the player out or awake at home, it rolls the odds of the player's *Nights* level. On a hit it draws one row of the night table and queues its scene, through a hand-over scene (`ul_core_night`) that runs when the queue is free and queues the drawn one right behind it. The clock runs only while the player does a timed action or walks, so an hour often falls in the middle of an action; the roll then waits for the action's end, since a queued scene would play over the action and the action carry on after it (only an action with an animation clip can be seen from Lua).
- **After a night's sleep at home** (two hours or more slept between midnight and five), it rolls the `asleep` rows once, and the scene is told as the player wakes: the forced door, someone in the next room. Being woken at three and living it then needs the engine to end the sleep; until then it is found on waking.
- **One pick at a time.** A scene that has not started a quarter of an hour after its hand-over declined (its own filter said no), and another row is drawn for the same slot, five draws at most. A slot whose scenes all declined stays owed: the next eligible hour is sure to draw. A pick the queue held past its hour (a long stay) is dropped at its hand-over, never played late.
- **Not** during a trip away, in a cell or a hospital bed (`NightTable.NEVER`), on holiday, with the Danger category switched off, or in quiet hours. A run with `dev.dice` leaves it off, so a test that plays scenes by name gets nothing on top; `-ModSetting=dev.night=true` turns it on and draws at every eligible hour.
- The log says what it does: `[ul_Core night] queued …`, `… played`, `… declined`, `nothing fits`.

### The Nights levels

The levels are data (`NightTable.LEVELS` in `ul_Core/Lua/ul_night_data.lua`): a mod may replace the table.

| Level | Odds an hour out | Awake at home | After a night's sleep | Most a night | Hours between two | Sure, out | Scale |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Quiet | 12 % | 4 % | 5 % | 1 | 4 | 0 | x0.25 |
| Dark | 35 % | 12 % | 15 % | 2 | 2 | 0 | x0.6 |
| **Brutal** (default) | 65 % | 25 % | 35 % | 4 | 1 | 1 | x1 |

*Sure* is how many events a night out is certain to bring once the player has been out an hour with nothing: on Brutal, every night out brings something. *Scale* is for a mod's own night rolls: a scene that starts a night story on its own dice multiplies them by `EventDirector.nightScale()` when `EventDirector.nightNow()` is true, and spends `EventDirector.allow(Game, "danger", "flavour")`, so the setting turns it down too (ul_Shadows' break-in, noise at night and hit-and-run do).

## The night table

The table is a plain global, `UL_NIGHT_EVENTS`, keyed by row id. Add, replace or take out a row from your own `Lua/*.lua`, at load: `ul_Core` only fills the ids nobody set, so the load order does not matter.

```lua
-- Lua/ynl_night.lua
UL_NIGHT_EVENTS = UL_NIGHT_EVENTS or {}

-- a scene of this mod, out on foot after 22:00 ("street" and "side_street" are ul_Street's open streets)
UL_NIGHT_EVENTS.ynl_followed_home = {
	mod = "ynl_Nightlife",
	kind = "danger",
	places = { "street", "side_street", "bus_stop", "park", "parking" },
	hours = { 22, 5 },
	weight = 4,
	fits = function(Game) return not Game:isWithCompanion() end,
}

-- the same scene twice: rows have their own ids, `scene` names what they queue
UL_NIGHT_EVENTS["ynl_door@asleep"] = { scene = "ynl_door", mod = "ynl_Nightlife", kind = "danger",
	places = { "home" }, asleep = true, weight = 3 }

-- another mod's row, taken out
UL_NIGHT_EVENTS.spiced_drink = false
```

| Field | Means |
| --- | --- |
| `scene` | The scene queued (default: the row id). |
| `mod` | The row is skipped while this mod is not loaded. |
| `kind` | `danger` or `weird`: what the row is. Both spend the same night budget. |
| `places` | Where the player must be, as a scene's `WHERE`: tags, `"all"`, `"-tag"`. `"all"` never covers a trip away. |
| `hours` | `{ from, to }`, whole hours, wrapping midnight: `{ 22, 4 }` is 22:00 to 03:59. Ignored for `asleep` rows. |
| `weight` | The row's share of the draw. 0 or `false` takes it out. |
| `tags` | The [content tags](/docs/start/content-tags) it shows. A build that denies one (the Steam build denies `sexual` and `nonconsent`) never draws it, so its nights keep the robberies, the knives and the strange, without the sexual rows. |
| `arrive` | Only for a player who has just come home: travel home crossed the hour and nothing has been done there yet (a forced door, someone waiting on the step). |
| `asleep` | Only after a night's sleep at home, told on waking, see above. A sleep is an action listed in `NightTable.SLEEP` (`sleep`, `nap`, `sleep_hotel`, `str_sleep_rough`...): add yours. |
| `fits` | `function(Game)`: true when the scene can play now. Read only, cheap: an arc's stage, a wait that is over, a companion. An error skips the row. |

The director also skips a row whose scene is on cooldown, and never draws a row tagged `sexual`, `nonconsent`, `incest` or `bestiality` for a player under 18.

## A scene the director queues

A queued scene skips its own `WHERE`, `WHEN` and cooldown: the row's places and hours stand in for them, and the director checks the cooldown. Its `filter` still runs, so the scene still says no when its story does not hold (no home, no partner, an arc at the wrong stage). Its **odds** are the director's:

- its first `UL.chanceRoll` passes (a filter rolls its gate first; a later roll in the scene, a fight or a getaway, stays its own);
- its `EventDirector.allow` passes, whatever the category, without spending the day's budget;
- `EventDirector.picked(Game, "<scene id>")` answers `"out"`, `"home"`, `"arrive"` (an `arrive` row: just home) or `"asleep"` (after a night's sleep, told on waking) for that run, `nil` otherwise.

The pass belongs to the first queued run that starts after the hand-over, within a quarter of an hour.

A filter that rolls `Game:Random` itself keeps that roll unless it asks first:

```lua
filter = function(Game, S)
	if not Game:isAtHome() then return false end
	local night = EventDirector and EventDirector.picked and EventDirector.picked(Game, "ynl_door")
	S.vars.woke = night == "asleep"
	if not night and Game:Random(1, 100) > 4 then return false end
	return true
end,
```

When `picked` answers `"asleep"`, the scene plays as the player wakes after the night: write the opening for that (`cond` on the line, see [Lines](/docs/scripting/declarative-scenes)), the break-in found in the morning, someone still in the next room at dawn. When it answers `"arrive"`, they have just walked in; otherwise (`"home"`, or your scene's own roll after an action done at home) they have been home a while.

A scene that starts a story with a long wait (a break-in a week apart) sets that wait **once the story has started**, not before its roll: set before, every draw burnt the week, and a 3 % roll came once in about 230 days.

Every sexual scene keeps its own adult checks on every party (`UL.requireAdult`). Nothing sexual ever involves a minor, whatever the level.

## The rows that ship

`ul_Core` fills the table with the night scenes the mods already have; a row whose mod is not loaded is skipped.

| Kind | Rows |
| --- | --- |
| Done to the player, out | `ul_dm_attack` (a knife on the walk home), `ul_ar_mugged`, `ul_hm_target` (someone who wants the player dead: hospital in Normal, maybe death in Hardcore), `ul_db_press_lesson` (the collectors), `ul_sh_hit` (a car that doesn't stop), `dating_robbed`, `ul_uc_taken`; full build: `vi_darkalley_rape`, `vi_darkalley_gangrape(_cms)`, `wi_darkalley_rape(_cms, _ntr)`, `vi_spiked_rape`, `vi_date_rape`, `vi_revenge_rape` |
| Seen by the player, out | `come_across_robbery`, `catches_pickpocket`, `spiced_drink`, `ul_nm_killer_followed` |
| At home, awake | `ul_sh_break_in` (coming home, or the door found forced), `ul_msh_burglary` (coming home), `ul_sh_night_noise`, `ul_hm_defend` (the controlling partner) |
| After a night's sleep at home | `ul_sh_break_in`, `ul_sh_night_noise`, `orcs_kidnap`; at weight 0 until the engine wakes the player at night, since their text is a waking in the dark: `burglar`, `vi_homeinvader_rape`, `vampire_invades`, `orcs_invade` |
| Weird | `ul_nm_legend_rumour` (the 3:33 bus), `ul_nm_house_follow`, `ul_cg_episode`, `tentacles_dark_alley`, `tentacles_disguise`, `ul_loop_dejavu` |

Scenes that still roll `Game:Random` in their filter (most of `ul_Base`'s and `ul_NonConsensual`'s, `ul_uc_taken`'s `chance`) are drawn but often decline; the director then draws another row for the slot.
