Skip to content
FMFallout Multiplayer Scripting APIScripting guides and API
GuideMaintainer authored

Build a settlement terminal in HTML

Ship an HTML panel inside your resource, open it with Web.createView, and run a full page to server round trip without ever letting the page talk to the server directly.

You will build a terminal the player opens with a key: an HTML panel listing everyone on the server, their condition, and a locate action that paints a label over that survivor’s head for ten seconds. The page never speaks to the server. Every message goes page to client script to server and back, which is the only arrangement where the server can check anything.

  • Shipping page files with a resource and serving them from the internal fw:// origin.
  • Web.createView and the focus gate, which decides whether the game or the page owns the keyboard.
  • The two halves of the page bridge: callEvent going up, Web.emit coming down.
  • Keeping the server authoritative when the request came from a page.
  • Nametags.setLabel, a client-only way to mark somebody in the world.
vault-terminal/
package.json
tsconfig.json
tsconfig.client.json
web/
terminal.html the page
terminal.css its styling
terminal.js its script
src/server/
index.ts the roster
locate.ts the locate request, and what it refuses
live.ts push updates while somebody is watching
src/client/
index.ts imports the rest
view.ts creates the view
panel.ts opens and closes it
bridge.ts page to server
roster.ts server to page

Page files are not scripts, so they go in files. Only what you list there is sent to players and mounted for the view to read; anything else in the folder stays on the server.

package.json
{
"name": "vault-terminal",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "tsc -p tsconfig.json && tsc -p tsconfig.client.json"
},
"devDependencies": {
"@falloutmp/types": "0.1.0",
"typescript": "^5.9.2"
},
"mafiahub": {
"serverScripts": ["dist/server/index.js"],
"clientScripts": ["dist/client/index.js"],
"files": ["web/terminal.html", "web/terminal.css", "web/terminal.js"]
}
}

Once the resource is running, the client mounts those files read only and serves them from an internal origin:

fw://resources/vault-terminal/web/terminal.html

A view is origin locked to the URL it was created with, so the page cannot navigate itself somewhere else, and a callEvent from any other origin is dropped.

Keep it ordinary. The body is a heading and an empty list the script fills in:

web/terminal.html (body)
<div class="terminal">
<h1>Settlement roster</h1>
<ul id="roster"></ul>
<div class="hint">ESC closes</div>
</div>

The page gets one global from the client, callEvent(name, payloadJson), and receives messages as a CustomEvent on window whose detail is the payload. That is the whole bridge:

// web/terminal.js, running in the page, not in the client isolate.
const roster = document.getElementById("roster");
function render(survivors) {
roster.replaceChildren();
for (const survivor of survivors) {
const row = document.createElement("li");
row.textContent = `${survivor.nickname} ${Math.round(survivor.health)} HP`;
row.className = "row";
row.addEventListener("click", () => {
callEvent("terminal:locate", JSON.stringify({ id: survivor.id }));
});
roster.append(row);
}
}
window.addEventListener("terminal:roster", (event) => {
render(event.detail);
});
window.addEventListener("keydown", (event) => {
if (event.key === "Escape") callEvent("terminal:close", null);
});
// Ask for the first roster as soon as the page is up.
callEvent("terminal:ready", null);

The client creates the view hidden, so the page is loaded and ready before the player ever asks for it. Opening is then instant:

src/client/view.ts
const PAGE = "fw://resources/vault-terminal/web/terminal.html";
const screen = Web.getScreenSize();
const width = Math.min(760, Math.round(screen.width * 0.6));
const height = Math.min(520, Math.round(screen.height * 0.7));
export const view = Web.createView(PAGE, {
width,
height,
x: Math.round((screen.width - width) / 2),
y: Math.round((screen.height - height) / 2),
zIndex: 10,
visible: false,
focus: false,
});

This is the one concept that catches everyone. A focused view owns the mouse and keyboard, and the game stops receiving input. An unfocused but visible view is a passive overlay that draws live data while the player keeps playing.

State Player can play Page receives clicks Key binds fire
Hidden Yes No Yes
Visible, not focused Yes No Yes
Visible and focused No Yes No
src/client/panel.ts
import { view } from "./view.js";
let open = false;
export function setOpen(next: boolean): void {
open = next;
if (open) {
Web.showView(view);
Web.focusView(view, true);
Events.emitServer("terminal:open");
} else {
Web.focusView(view, false);
Web.hideView(view);
}
}
Key.bind("f3", "down", () => setOpen(!open));

Web.on receives what the page raised. A JSON payload arrives parsed; anything else arrives as the raw string, and an empty payload as undefined.

src/client/bridge.ts
import { view } from "./view.js";
import { setOpen } from "./panel.js";
Web.on(view, "terminal:ready", () => {
Events.emitServer("terminal:open");
});
Web.on(view, "terminal:close", () => {
setOpen(false);
});
Web.on(view, "terminal:locate", (payload?: unknown) => {
// Relayed as it arrived. The server does not trust it, and neither should this.
Events.emitServer("terminal:locate", payload);
});

Coming the other way, the server answers the one player who asked, and the client forwards it into the page. The server sends JSON text, but the client parses it before any handler runs, so what arrives here is already the array or object, never the string:

src/client/roster.ts
import { view } from "./view.js";
Events.on("terminal:roster", (...args: unknown[]) => {
const roster = args[0];
if (!Array.isArray(roster)) return;
// Web.emit serializes it again; the page reads it back as event.detail.
Web.emit(view, "terminal:roster", roster);
});
Events.on("terminal:located", (...args: unknown[]) => {
const target = args[0] as { id?: unknown; nickname?: unknown } | undefined;
if (typeof target?.id !== "number" || typeof target.nickname !== "string") return;
// Client-only: a label above that entity, for this player alone.
Nametags.setLabel(target.id, `>> ${target.nickname} <<`, 10000, 0xffb627ff);
});

Finally, an entry point that is only imports:

src/client/index.ts
import "./panel.js";
import "./bridge.js";
import "./roster.js";

The page asked for a roster, so the page gets exactly the fields the roster needs, and nothing else. A survivor’s position is deliberately absent: handing out coordinates would make the terminal a wallhack.

src/server/index.ts
interface RosterEntry {
id: number;
nickname: string;
health: number;
}
export function roster(): RosterEntry[] {
return Player.all().map((player) => ({
id: player.id,
nickname: player.nickname,
health: player.health,
}));
}
Events.onClient("terminal:open", (...args: unknown[]) => {
const player = args[0];
if (!(player instanceof Player)) return;
player.emit("terminal:roster", JSON.stringify(roster()));
});

The locate request is where the trust boundary earns its keep. The payload names an entity ID, and a page can name any number it likes:

src/server/locate.ts
const RANGE = 20000;
Events.onClient("terminal:locate", (...args: unknown[]) => {
const player = args[0];
const payload = args[1];
if (!(player instanceof Player) || typeof payload !== "object" || payload === null) return;
const id = (payload as { id?: unknown }).id;
if (typeof id !== "number") return;
// Resolve the ID yourself. Never act on a handle the client built.
const target = Player.getById(id);
if (!target || target.id === player.id) return;
const away = target.position.distance(player.position);
if (away > RANGE) {
Chat.sendToPlayer(player, `${target.nickname} is out of range.`, { author: "Terminal" });
return;
}
player.emit("terminal:located", JSON.stringify({ id: target.id, nickname: target.nickname }));
Chat.sendToPlayer(player, `${target.nickname} is ${Math.round(away / 100)} m away.`, { author: "Terminal" });
});

Four checks in nine lines, and each one answers a way the page could lie: a missing payload, a non-numeric ID, an ID that is not a player, and a player too far away to be findable.

A roster that is a snapshot goes stale while the panel is open. Push a new one on a timer, but only while somebody is looking:

src/server/live.ts
import { roster } from "./index.js";
const watching = new Set<number>();
Events.onClient("terminal:open", (...args: unknown[]) => {
const player = args[0];
if (player instanceof Player) watching.add(player.id);
});
Events.on("playerDisconnect", (player: Player) => {
watching.delete(player.id);
});
setInterval(() => {
if (watching.size === 0) return;
const json = JSON.stringify(roster());
for (const id of watching) Player.getById(id)?.emit("terminal:roster", json);
}, 2000);

Serialise once, send many: JSON.stringify on every player is the easiest way to make a two second timer cost real money on a full server.

  1. Build and load:

    Server console
    refresh
    ensure vault-terminal
  2. Press F3. The roster lists everyone connected.

  3. Click a name. A label appears over them for ten seconds, and chat tells you the distance.

  4. Press Escape. Control returns to the game.

  5. Open the client log and look for browserConsoleMessage entries: the page’s own console.log lands there, which is how you debug the half that has no scripting API.

  • A passive overlay. Create a second view with focus: false that never takes input, and use it for a permanent HUD. The same bridge works, and key binds keep firing.
  • Let the page act. Add a terminal:summon request that teleports a player, gated on the caller holding an item. Everything you need is in step 6.
  • Close on disconnect. Views are resource owned and destroyed when the resource stops, but a view left focused while the player is kicked is worth handling yourself.