Proximity voice and a pirate radio station
Give factions their own voice range, silence the dead, show who is talking, and put your own station on every Pip-Boy.
You will build a resource that turns raw proximity voice into something with rules: a settlement where voice carries further, a faction that can talk across the map, dead players who cannot whisper their killer’s position, and a nametag that lights up while someone speaks. Then you will put a station on the Pip-Boy dial that plays whatever you tell it to.
What you will learn
Section titled “What you will learn”- How voice range is decided, and the three places it can be set.
- Tiers, which let one call change the range for a whole faction at once.
- Muting and deafening, both as a punishment and as a game rule.
playerVoiceStartandplayerVoiceStop, the reserved events behindVoice.isPlayerTalking.- Creating a radio station, putting a track on air, and taking the game’s own stations off.
vault-radio/ package.json tsconfig.json tsconfig.client.json src/server/ index.ts wires the pieces together voice.ts the default range and the tiers rules.ts who may talk, and who may hear nametags.ts light up a speaker for the room radio.ts the station and its playlist src/client/ index.ts transmit mode, hearing range, a talk indicator1. The manifest
Section titled “1. The manifest”{ "name": "vault-radio", "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"] }}2. How far voice carries
Section titled “2. How far voice carries”Three settings decide whether one player hears another, and they are checked in that order:
| Setting | Call | Applies to |
|---|---|---|
| Per player | Voice.setPlayerRange(player, range) |
That one player’s transmissions |
| Per tier | Voice.setTierRange(tier, range) |
Everyone in the tier, unless they have their own range |
| Server default | Voice.setRange(range) |
Everyone with neither of the above |
Connected clients are told the result, so their playback fades out at the same distance the server uses. Set the default once, at startup:
/** Game units. The Commonwealth is large: a settlement is a few thousand across. */const DEFAULT_RANGE = 1500;
Voice.setRange(DEFAULT_RANGE);The next step grows this into the file you will keep.
3. Tiers, for factions and radios
Section titled “3. Tiers, for factions and radios”A tier is just a number you assign. Give each faction one, set the tier’s range once, and every member picks it up:
const DEFAULT_RANGE = 1500;
export const Tier = { /** Everyone, out of the box. */ Survivor: 0, /** Carrying a working radio: heard across a settlement. */ Scout: 1, /** Faction command: heard anywhere, for a team channel. */ Command: 2,} as const;
Voice.setRange(DEFAULT_RANGE);Voice.setTierRange(Tier.Scout, 6000);Voice.setTierRange(Tier.Command, 1000000);
export function setTier(player: Player, tier: number): void { Voice.setPlayerTier(player, tier); player.state.set("voiceTier", tier, { scope: "owner" });}Writing the tier into the player’s state bag as well is not redundant: scope: "owner" sends it to
that player’s own game, where the client half can show which channel they are on without asking the
server.
4. Rules, not just punishment
Section titled “4. Rules, not just punishment”setPlayerMuted stops a player transmitting. setPlayerDeaf stops them hearing. Both are server
decisions, so neither can be turned off from the client:
import { Tier } from "./voice.js";
Events.on("playerDeath", (player: Player) => { // The dead do not give away their killer's position. Voice.setPlayerMuted(player, true);});
Events.on("playerReady", (player: Player) => { Voice.setPlayerMuted(player, false); Voice.setPlayerTier(player, Tier.Survivor);});setLocalMute(listener, target, muted) is different in kind: it is one player’s personal block
list, kept on the server so it survives a reconnect.
import { Tier } from "./voice.js";
Events.on("playerDeath", (player: Player) => { // The dead do not give away their killer's position. Voice.setPlayerMuted(player, true);});
Events.on("playerReady", (player: Player) => { Voice.setPlayerMuted(player, false); Voice.setPlayerTier(player, Tier.Survivor);});
export function block(listener: Player, target: Player): void { Voice.setLocalMute(listener, target, true); Chat.sendToPlayer(listener, `You will not hear ${target.nickname}.`, { author: "Voice" });}5. Show who is talking
Section titled “5. Show who is talking”The server raises two reserved events whenever a player starts or stops speaking. They track actual
speech, not the push-to-talk key, because silence is dropped before it reaches the server. They are
not in the typed EventMap, so narrow the argument yourself:
Events.on("playerVoiceStart", (...args: unknown[]) => { const player = args[0]; if (!(player instanceof Player)) return; player.setNametagColor(0xffb627ff);});
Events.on("playerVoiceStop", (...args: unknown[]) => { const player = args[0]; if (!(player instanceof Player)) return; player.setNametagColor(0xffffffff);});Nametag colour is a packed 0xRRGGBBAA integer. Because the nametag is server state, every player
who can see them sees the change, which is what you want: a speaker lights up for the room.
Voice.isPlayerTalking(player) answers the same question on demand, for code that runs on a timer
rather than on an event.
6. A station on the dial
Section titled “6. A station on the dial”A station is a replicated entity, like a player or a mine. Create it once and every connected Pip-Boy lists it; a player who joins later gets it too.
/** BGSSoundDescriptorForm form IDs from the game's own data. */const PLAYLIST = [ { sound: 0x0010cf1d, durationMs: 171000 }, { sound: 0x0010cf1e, durationMs: 142000 },];
let station: RadioStation | null = null;let track = 0;
function playNext(): void { if (!station) return; const entry = PLAYLIST[track % PLAYLIST.length]; if (!entry) return; track += 1; station.play(entry.sound, entry.durationMs); // No event marks the end of a track: the schedule is yours to keep. setTimeout(playNext, entry.durationMs);}
/** Takes the game's own stations off the dial, leaving yours alone on it. */export function exclusive(): void { RadioStation.setVanillaStationsEnabled(false);}
export function startStation(): void { // 80 to 110, the Pip-Boy's dial. No two stations may hold the same frequency. station = RadioStation.create("Vault 111 Relay", 98); if (!station) { console.error("Radio: the name or frequency was refused"); return; } playNext();}Only a player’s own data files can say whether a form ID really is a sound descriptor, so a wrong one is silent rather than an error. Test with a form you know plays.
Taking the game’s own stations off leaves your station alone on the dial:
// Diamond City Radio, Classical Radio, quest signals and distress beacons.// Each player's game runs those alone, so no two players ever hear the same thing on them.RadioStation.setVanillaStationsEnabled(false);That is the real argument for turning them off on a roleplay server: a shared station is shared, and the game’s own are not.
7. Wire it up
Section titled “7. Wire it up”import "./voice.js";import "./rules.js";import "./nametags.js";import { startStation, exclusive } from "./radio.js";
exclusive();startStation();
Events.on("playerCommand", (player: Player, command: string, args: string[]) => { if (command !== "channel") return; const name = args[0] ?? ""; const tier = name === "command" ? 2 : name === "scout" ? 1 : 0; Voice.setPlayerTier(player, tier); Chat.sendToPlayer(player, `Channel: ${name || "survivor"}.`, { author: "Voice" });});8. The client half
Section titled “8. The client half”The client owns the microphone. Everything here is that player’s own preference, which is why none of it belongs on the server:
Voice.setTransmitMode("pushToTalk");Voice.setPushToTalkKey("v");// A short tail stops the last syllable being clipped.Voice.setPushToTalkReleaseDelay(250);Voice.setNoiseSuppression(true);
if (!Voice.hasMicrophone()) { Hud.notify("No microphone found. Voice is receive only.");}Hearing range is the listener’s side of the same number the server sets for talkers. Lowering it is a comfort setting; it cannot be used to hear further than the server allows:
Key.bind("f9", "down", () => { const quiet = Voice.getHearingRange() < 1000; Voice.setHearingRange(quiet ? Voice.getRange() : 500); Hud.notify(quiet ? "Hearing: normal" : "Hearing: close only");});A talk indicator, polled rather than evented, because the client knows its own microphone level every frame:
setInterval(() => { if (!Voice.isTalking()) return; const level = Math.round(Voice.getInputLevel() * 100); Hud.showSubtitle(`Transmitting ${level}%`, 1);}, 500);Try it
Section titled “Try it”-
Build and load:
Server console refreshensure vault-radio -
Connect two clients. Walk apart until you stop hearing each other: that is
DEFAULT_RANGE. -
Type
/channel commandon one of them and walk to the other side of Sanctuary. You are still audible. -
Open the Pip-Boy, go to the radio, and tune to Vault 111 Relay.
-
Die, and try to talk. Nothing goes out until you respawn.
What to change next
Section titled “What to change next”- Give the tier a cost. Require an item in the inventory for
Tier.Scout, checked withplayer.getItemCount, and drop the player back toSurvivorwhen they lose it. - One station per faction.
RadioStation.createper team on different frequencies, andsetVisibleToso only that team’s Pip-Boy lists it. - Take requests. A
/requestcommand that jumps the playlist, which is just a different implementation ofplayNext.