Skip to content

Instantly share code, notes, and snippets.

@benzittlau
Created December 30, 2021 21:34
Show Gist options
  • Save benzittlau/8c3c1a857514a4e872c5d67143e4b363 to your computer and use it in GitHub Desktop.
Save benzittlau/8c3c1a857514a4e872c5d67143e4b363 to your computer and use it in GitHub Desktop.
/**
* @param {NS} ns
*/
export async function main(ns) {
ns.print("Running hacking script...");
var target; securityTreshold; moneyTreshold
// Identify the server to attempt to hack
var target = ns.args[0];
// Set the thresholds based on the server configuration
var securityTreshold = ns.args[1] || ns.getServerMinSecurityLevel(target) + 5;
var moneyTreshold = ns.args[2] || ns.getServerMaxMoney(target) * 0.75;
ns.print('Hacking "' + target + '" with thresholds: security:' + securityTreshold + ', money:' + moneyTreshold + '.');
while (true) {
if (securityTreshold < ns.getServerSecurityLevel(target)) {
await ns.weaken(target);
}
else if (moneyTreshold > ns.getServerMoneyAvailable(target)) {
await ns.grow(target);
}
else {
await ns.hack(target);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment