-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaveloadout.js
More file actions
38 lines (34 loc) · 1.22 KB
/
saveloadout.js
File metadata and controls
38 lines (34 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import fsp from "node:fs/promises";
import { join } from "path";
// If you use a loadout bind, (aka a resup bind or b4nny bind), you'll know that it won't save your active loadouts between restarts
// This script lets you save the changes by echoing "tfview.saveloadout(class, loadout)" in the console
// assuming you have a file "tf/cfg/initloadouts.cfg" with the following structure:
// alias scoutRespawn "loadout1"
// alias soldierRespawn "loadout1"
// ...etc...
const classes = [
"scout",
"soldier",
"pyro",
"demo",
"heavy",
"engineer",
"medic",
"sniper",
"spy",
]
export async function run(context, className, loadout) {
const index = classes.indexOf(className);
if(index === -1) {
context.log.error(`${className} is not a valid class`);
return;
}
// Read the existing config
const path = join(context.tfPath, "cfg", "initloadouts.cfg");
const content = await fsp.readFile(path, "utf-8");
const lines = content.split("\n");
// Update and write the content
lines[index] = `alias ${className}Respawn "loadout${loadout}"`;
await fsp.writeFile(path, lines.join("\n"), "utf-8");
context.log.info(`Saved loadout ${loadout} for class ${className}`);
}