A simple hacknet manager to purchase all the hacknet upgrades for you in an efficient way.
Contents
Guide to Simple Hacknet Manager
Setup
Simply create a .js file and paste the code below.
nano nameOfYourFile.jsNote: 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.jsHowever, you can also pass it two arguments (buy time delay and money threshold multiplier).
run nameOfYourScript.js 5000 2The 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.
More Guides:
- Bitburner – Autocomplete Your Scripts in VS Code!
- Bitburner – How to Make Cat Viewer Program
- Bitburner – Basic Auto Hack Script for Beginners
- Bitburner – Making the Most of Augmentations
- Bitburner – Unachievable Achievement Guide (How to Get Any Achievement)
Written by Kirtle