-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhack-self.js
More file actions
27 lines (24 loc) · 896 Bytes
/
Copy pathhack-self.js
File metadata and controls
27 lines (24 loc) · 896 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
/** @param {NS} ns **/
export async function main(ns) {
const args = ns.flags([['help', false]]);
if (args.help) {
ns.tprint('This script will generate money by hacking a target server.');
ns.tprint(`USAGE: run ${ns.getScriptName()}`);
ns.tprint('Example:');
ns.tprint(`> run ${ns.getScriptName()}`);
return;
}
let hostname = ns.getHostname();
// TODO: Are these sensible values???
let thresholdMoney = ns.getServerMaxMoney(hostname) * 0.75;
let thresholdSecurity = ns.getServerMinSecurityLevel(hostname) + 5;
while (true) {
if (ns.getServerSecurityLevel(hostname) > thresholdSecurity) {
await ns.weaken(hostname);
} else if (ns.getServerMoneyAvailable(hostname) < thresholdMoney) {
await ns.grow(hostname);
} else {
await ns.hack(hostname);
}
}
}