-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstage1.js
More file actions
43 lines (38 loc) · 1.48 KB
/
Copy pathstage1.js
File metadata and controls
43 lines (38 loc) · 1.48 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
39
40
41
42
43
/** @param {NS} ns */
export async function main(ns) {
const serversToHack = ['sigma-cosmetics'];
const serverToHack = 'n00dles';
const unlockScriptName = 'unlock.js';
const scriptToExecute = 'autohack.js';
const free = ['n00dles', 'foodnstuff'];
const autohackMemCost = ns.getScriptRam(scriptToExecute);
function unlockAndExecute(hostname) {
ns.tprintf("Unlocking hostanme: %s", hostname);
ns.exec(unlockScriptName, 'home', 1, hostname);
while (!ns.hasRootAccess(hostname)) {
await ns.sleep(1000);
}
var freeRam = ns.getServerMaxRam(hostname) - ns.getServerUsedRam(hostname);
var threadCount = Math.floor(freeRam / autohackMemCost);
ns.tprintf("%s thread count: %d", scriptToExecute, threadCount);
if (threadCount > 0) {
ns.scp(scriptToExecute, hostname);
ns.exec(scriptToExecute, hostname, threadCount, serverToHack);
}
}
// run script on free servers
free.forEach(unlockAndExecute);
// run script on home pc (it's cheaper to use exec in this script instead of run)
ns.tprintf("Running 30 threads on 'Home' for %s hacking %s", scriptToExecute, serverToHack);
ns.exec(scriptToExecute, 'home', 30, serverToHack);
// try hack all others
for (const hostname of serversToHack) {
while (ns.getServerRequiredHackingLevel(hostname) > ns.getHackingLevel()) {
await ns.sleep(1000);
}
unlockAndExecute(hostname);
}
ns.tprintf("Time to buy VMs");
ns.exec('buy-8gb-servers.js', 'home');
}
// My initial script after prestige/reset