Add watcher and kill all scripts
This commit is contained in:
parent
f34a37a3fb
commit
000e69a418
@ -9,6 +9,7 @@ export async function main(ns: NS) {
|
|||||||
let moneyThresh = ns.getServerMaxMoney(server) * 0.75;
|
let moneyThresh = ns.getServerMaxMoney(server) * 0.75;
|
||||||
let securityThresh = ns.getServerMinSecurityLevel(server) + 5;
|
let securityThresh = ns.getServerMinSecurityLevel(server) + 5;
|
||||||
let numThreads = ns.getServerMaxRam(server) / ns.getScriptRam("hack.js")
|
let numThreads = ns.getServerMaxRam(server) / ns.getScriptRam("hack.js")
|
||||||
|
numThreads = Math.floor(numThreads);
|
||||||
executeScriptOnServerFromAnother(ns, server, "hack.js", numThreads, [server, moneyThresh, securityThresh])
|
executeScriptOnServerFromAnother(ns, server, "hack.js", numThreads, [server, moneyThresh, securityThresh])
|
||||||
}
|
}
|
||||||
}
|
}
|
9
servers/home/killall.ts
Normal file
9
servers/home/killall.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import {NS} from "NetscriptDefinitions";
|
||||||
|
import {recursiveScan} from "./utils";
|
||||||
|
|
||||||
|
export async function main(ns: NS) {
|
||||||
|
let servers: string[] = recursiveScan(ns)
|
||||||
|
for (const server of servers) {
|
||||||
|
ns.killall(server)
|
||||||
|
}
|
||||||
|
}
|
18
servers/home/watcher.ts
Normal file
18
servers/home/watcher.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import {NS} from "NetscriptDefinitions";
|
||||||
|
export async function main(ns: NS) {
|
||||||
|
let hackingLevel = ns.getHackingLevel();
|
||||||
|
while (hackingLevel < 9999) {
|
||||||
|
ns.run("hackallservers.js");
|
||||||
|
let seconds = 60 * 1000; // 1 minute
|
||||||
|
await ns.sleep(seconds)
|
||||||
|
|
||||||
|
let oldHackingLevel = hackingLevel;
|
||||||
|
hackingLevel = ns.getHackingLevel();
|
||||||
|
if(oldHackingLevel !== hackingLevel) {
|
||||||
|
ns.tprint(`Hacking level increased from ${oldHackingLevel} to ${hackingLevel}`);
|
||||||
|
ns.run("killall.js");
|
||||||
|
await ns.sleep(1000) // 1 second
|
||||||
|
ns.run("hackallservers.js");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user