Bitburner: Simple Hacknet Manager

Published on: December 27, 2021 by Robins Chew

A simple hacknet manager to purchase all the hacknet upgrades for you in an efficient way.

Setup Simply create a .js file and paste the code below
nano nameOfYourFile.js
Note: This script requires 6.1GB of memory available Script code
export async function main(ns) {
 let delayTime = ns.args[0] || 1000;
 let thresholdMultiplier = ns.args[1] || 1; //Bigger threshold, the less it spends
 
 while (true) {
 let ownedNodes = ns.hacknet.numNodes();
 let minValue = ns.hacknet.getPurchaseNodeCost();
 let nodeIndex = ownedNodes;
 let upgradeType = -1; //-1 -> purchase, 0 -> level, 1 -> ram, 2 -> core
 
 for (let i = 0; i < ownedNodes; i++) {
 let upgrades = [
 ns.hacknet.getLevelUpgradeCost(i, 1), 
 ns.hacknet.getRamUpgradeCost(i, 1), 
 ns.hacknet.getCoreUpgradeCost(i, 1)
 ];
 
 let value = Math.min.apply(Math, upgrades);
 if (value < minValue) {
 minValue = value;
 nodeIndex = i;
 upgradeType = upgrades.indexOf(value);
 }
 }
 
 await waitForMoney(ns, minValue, delayTime, thresholdMultiplier);
 switch (upgradeType) {
 case -1:
 ns.hacknet.purchaseNode();
 break;
 case 0:
 ns.hacknet.upgradeLevel(nodeIndex, 1);
 break;
 case 1:
 ns.hacknet.upgradeRam(nodeIndex, 1);
 break;
 case 2:
 ns.hacknet.upgradeCore(nodeIndex, 1);
 break;
 }
 
 await ns.sleep(1);
 }
 }
 
 async function waitForMoney(ns, targetMoney, delayTime, thresholdMultiplier) {
 while (ns.getPlayer().money / thresholdMultiplier < targetMoney) {
 await ns.sleep(delayTime);
 }
 }
How it works The script finds the cheapest upgrade available in one of the hacknet nodes and buys it whenever it has enough money for it. Usage You can run this script simply by typing
run nameOfYourScript.js

However, you can also pass it two arguments (buy time delay and money threshold multiplier).

run nameOfYourScript.js 5000 2

The command above would try to purchase an upgrade every 5s (5000ms) whenever the player has at least twice the money it would cost to purchase said upgrade.

Note: Passing a money threshold multiplier below 1 will break the script

Thanks to Kirtle for his great guide, all credit to his effort. you can also read the original guide from Steam Community. enjoy the game.

Related Posts:

  • Bitburner: Post-BN9 Hacknet Script (V2.2.1)
  • Bitburner: Scan/Nuke/Money Script (Working 2022)
  • Bitburner: How to Scan Every Server
  • Bitburner: How to Autocomplete Your Scripts in VSCode
  • Bitburner: Unorthodox Automation & In-game Modding

About Robins Chew

I'm Robins, who love to play the mobile games from Google Play, I will share the gift codes in this website, if you also love mobile games, come play with me. Besides, I will also play some video games relresed from Steam.

Contact me Via X