Downed and revived
Replace instant death with the game's own bleedout: a player who would die goes down where they fell, is marked on every map, and gets back up when someone revives them or they give up.
On most roleplay and co-op servers a fatal hit does not end a life at once. The player goes down,
their friends can see where, and someone has a chance to get them back on their feet. Fallout 4
already has this state, the bleedout a companion falls into, and you will build the rule out of
pieces the API already has: playerDeath, respawn, a blip, playerActivatePlayer, and the
client’s LocalPlayer.setBleedingOut.
This is the downed rule of the default gamemode (/downed toggles it there), rebuilt step by step.
What you will learn
Section titled “What you will learn”- What “dead” means to the server, and why
respawnis the way back into a downed state. - Splitting one rule between the server, which decides, and the client, which shows it.
- Timers that act on a player later, and the checks they need when they fire.
- Reviving with the Activate button through
playerActivatePlayer.
downed/ package.json tsconfig.json src/server/ index.ts the rule: down, revive, give up src/client/ index.ts in and out of the bleedout1. Why not just stop the death?
Section titled “1. Why not just stop the death?”There is no “almost dead” on the server. Each player’s game is the authority for their own body, and
when it reports the death, playerDeath fires and the player stays dead until something calls
player.respawn(). You cannot refuse it.
So the rule works the other way around: let the death happen, bring the player straight back where they fell, and put them into bleedout once they are standing. To everyone else it looks like a player who dropped and stayed down.
| Step | Who | What |
|---|---|---|
| 1 | Server | playerDeath: note them as downed, respawn on the spot |
| 2 | Server | A moment later: lower their health, add a blip, tell their game |
| 3 | Client | LocalPlayer.setBleedingOut(true): on the ground, controls held |
| 4 | Server | playerActivatePlayer or /revive: clear it, full health, tell their game |
| 5 | Client | LocalPlayer.setBleedingOut(false): back on their feet |
2. The client half
Section titled “2. The client half”The bleedout can only be entered from the player’s own game, so the client’s job is one line:
// clientEvents.on("downed:set", (payload: unknown) => { LocalPlayer.setBleedingOut(payload === true);});While bleeding out, nothing kills the player, the same way nothing kills a downed companion. They stay there until a script gets them up, and every other player sees them on the ground.
3. Going down
Section titled “3. Going down”const kDownedHealth = 0.25; // of the maximum, once they are downconst kDownedAfterMs = 2500; // let the respawn's get-up play out firstconst kRespawnDelayMs = 5000; // an ordinary death, when they cannot go down
/** IDs of players who are down, or about to be. */const downed = new Set<number>();const blips = new Map<number, Blip>();
function setDowned(player: Player, on: boolean): void { if (on) { downed.add(player.id); const blip = Blip.create({ entity: player, label: `Downed: ${player.nickname}` }); if (blip !== null) blips.set(player.id, blip); } else { downed.delete(player.id); blips.get(player.id)?.destroy(); blips.delete(player.id); } player.emit("downed:set", JSON.stringify(on));}
Events.on("playerDeath", (player: Player) => { if (downed.has(player.id)) { // Killed again in the moment before they went down: this one is a real death. downed.delete(player.id); blips.get(player.id)?.destroy(); blips.delete(player.id); setTimeout(() => player.respawn(), kRespawnDelayMs); return; }
downed.add(player.id); player.respawn(player.position, player.heading);
const id = player.id; setTimeout(() => { // Anything can have happened in 2.5 seconds. Look the player up again. const again = Player.getById(id); if (again === null || !downed.has(id) || again.isDead) return; again.health = again.maxHealth * kDownedHealth; setDowned(again, true); Chat.sendToPlayer(again, "You are down. Wait for a revive, or /giveup.", { author: "Server" }); }, kDownedAfterMs);});
Events.on("playerDisconnect", (player: Player) => { downed.delete(player.id); blips.get(player.id)?.destroy(); blips.delete(player.id);});Three decisions in there are worth spelling out:
downed.addhappens before the timer, not inside it. The set doubles as “this player already used their second chance”. A player shot again during the 2.5 seconds dies for real instead of going down twice.- The timer looks the player up by ID. A handle captured in a closure can outlive the player it
pointed at.
Player.getByIdreturnsnullfor someone who left, which is the check you want. - The blip is on the player, not on a point.
entitymakes it follow their body, so a downed player who is dragged or ragdolled is still where their marker says.
4. Getting someone up
Section titled “4. Getting someone up”The Activate button on another player’s body raises playerActivatePlayer, which is exactly the
gesture a revive wants. Offer a chat command as well, for players who cannot reach the body:
const kReviveRange = 300;
export function tryRevive( rescuer: Player, target: Player, downed: Set<number>, getUp: (player: Player) => void,): string | null { if (!downed.has(target.id) || target.isDead || target.id === rescuer.id) return `${target.nickname} is not down.`; if (rescuer.isDead || downed.has(rescuer.id)) return "You are down yourself."; if (rescuer.position.distance(target.position) > kReviveRange) return `${target.nickname} is too far away.`;
getUp(target); target.health = target.maxHealth; return null;}It answers null for success and a reason otherwise, so both entry points can share it and only
differ in how they report:
import { tryRevive } from "./revive.js";
const kDownedHealth = 0.25;const kDownedAfterMs = 2500;const kRespawnDelayMs = 5000;const kSpawn = new Vector3(-80768, 88174, 8199); // Sanctuary
const downed = new Set<number>();const blips = new Map<number, Blip>();
const reply = (player: Player, text: string): void => Chat.sendToPlayer(player, text, { author: "Server" });
function clear(player: Player): void { downed.delete(player.id); blips.get(player.id)?.destroy(); blips.delete(player.id);}
function setDowned(player: Player, on: boolean): void { if (on) { downed.add(player.id); const blip = Blip.create({ entity: player, label: `Downed: ${player.nickname}` }); if (blip !== null) blips.set(player.id, blip); } else { clear(player); } player.emit("downed:set", JSON.stringify(on));}
const getUp = (player: Player): void => setDowned(player, false);
Events.on("playerDeath", (player: Player) => { if (downed.has(player.id)) { clear(player); setTimeout(() => player.respawn(), kRespawnDelayMs); return; } downed.add(player.id); player.respawn(player.position, player.heading); const id = player.id; setTimeout(() => { const again = Player.getById(id); if (again === null || !downed.has(id) || again.isDead) return; again.health = again.maxHealth * kDownedHealth; setDowned(again, true); reply(again, "You are down. Wait for a revive, or /giveup."); }, kDownedAfterMs);});
Events.on("playerDisconnect", (player: Player) => clear(player));
// Activate on a downed body.Events.on("playerActivatePlayer", (player: Player, target: Player) => { if (!downed.has(target.id)) return; const refused = tryRevive(player, target, downed, getUp); if (refused !== null) reply(player, refused);});
Events.on("playerCommand", (player: Player, command: string, args: string[]) => { if (command === "revive") { const target = Player.all().find((p) => p.nickname === args[0] || String(p.id) === args[0]); if (target === undefined) return reply(player, "/revive <player>"); const refused = tryRevive(player, target, downed, getUp); if (refused !== null) reply(player, refused); return; }
if (command === "giveup") { if (downed.has(player.id) && !player.isDead) { // Down and waiting: get up, but somewhere safe. setDowned(player, false); player.health = player.maxHealth; player.teleport(kSpawn, 0, { worldSpace: 0x3c }); } else if (player.isDead) { clear(player); player.respawn(); } }});/giveup covers both ways a player can be stuck: lying in bleedout waiting for help that is not
coming, or dead after a second hit with the respawn timer still running.
Try it
Section titled “Try it”-
Build and load:
Server console refreshensure downed -
Have your friend kill you, or run
/killfrom the default gamemode. You drop, get up, and go down into bleedout. A “Downed” marker appears on their compass. -
They walk up and press Activate on you. You stand at full health and the marker disappears.
-
Go down again and type
/giveup. You get up in Sanctuary. -
Go down, and have them shoot you while you are getting up. That one is a normal death.
What to change next
Section titled “What to change next”- A bleedout timer. Store when each player went down, and call
player.kill()on whoever has been down longer than two minutes. - Medics only. Require a stimpak: check
rescuer.getItemCount(0x23736)intryReviveandremoveItemone on success. - Tell everyone nearby. On going down, send a line to
Player.getInRange(player, 3000), as Roleplay chat does for speech.