-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicHack.js
More file actions
29 lines (26 loc) · 996 Bytes
/
basicHack.js
File metadata and controls
29 lines (26 loc) · 996 Bytes
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
/**
* @param {NS} ns
**/
export async function main(ns) {
const args = ns.flags([['help', false]]);
const targetServerToHack = args._[0];
const moneyThreshold = ns.getServerMaxMoney(targetServerToHack) * 0.75;
const securityThreshold = ns.getServerMinSecurityLevel(targetServerToHack) + 5;
// If missing argument or help
if (args.help || false) {
ns.tprint("This script will generate money by hacking a target server.");
ns.tprint(`USAGE: run ${ns.getScriptName()} SERVER_NAME`);
ns.tprint("Example:");
ns.tprint(`> run ${ns.getScriptName} n00dles`);
return;
}
while (true) {
if (ns.getServerSecurityLevel(targetServerToHack) > securityThreshold) {
await ns.weaken(targetServerToHack);
} else if (ns.getServerMoneyAvailable(targetServerToHack) < moneyThreshold) {
await ns.grow(targetServerToHack);
} else {
await ns.hack(targetServerToHack);
}
}
}