forked from bitburner-official/bitburner-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_hack.js
More file actions
20 lines (20 loc) · 754 Bytes
/
basic_hack.js
File metadata and controls
20 lines (20 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
export async function main(ns) {
const args = ns.flags([['help', false]]);
const hostname = args._[0];
if(args.help || !hostname) {
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(hostname) > ns.getServerMinSecurityLevel(hostname)) {
await ns.weaken(hostname);
} else if (ns.getServerMoneyAvailable(hostname) < ns.getServerMaxMoney(hostname)) {
await ns.grow(hostname);
} else {
await ns.hack(hostname);
}
}
}