Bitburner – Simple Hacknet Manager Guide

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

Guide to Simple Hacknet Manager

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.

Recommended for You

Be the first to comment

Leave a Reply

Your email address will not be published.


*