Bitburner – Code for Basic Hacknet Manager

Bitburner – Code for Basic Hacknet Manager 1 - steamlists.com
Bitburner – Code for Basic Hacknet Manager 1 - steamlists.com

a basic code to manage your hacknets for you, while trying not to apend too much money
 
 

How to use

make a .js file, or a .ns file,
 
either of those will work, .script uses a different standard so those wont work
 
then paste the code into it.
 
the new file starts with some stuff all ready in it, so make sure you paste over it
 
 
 

The code

/** @param {NS} ns **/export async function main(ns) {
 function myMoney() {
 return ns.getServerMoneyAvailable("home");
 }
 //this script is designed to manage the hacknet nodes
 //to prevent excess spending i've limited it from spending
 //more than half the players money
 var nodes = 0;
 var ref = 0;
 ns.disableLog("ALL");
 while (true) {
 //sleep for second to prevent the loop from crashing the game
 await ns.sleep(1000);
 //buy a node if we have more than twice the money needed
 if (ns.hacknet.getPurchaseNodeCost() < myMoney() / 2) {
 ref = ns.hacknet.purchaseNode();
 ns.print("bought node hn-" + ref);
 }
 nodes = ns.hacknet.numNodes()
 for (var i = 0; i < nodes; i++) {
 //check if nodes level is a multiple of 10
 var mod = ns.hacknet.getNodeStats(i).level % 10;
 //buy level node to the nearest multiple of 10 if we have double the money needed
 if (ns.hacknet.getLevelUpgradeCost(i, 10 - mod) < myMoney() / 2) {
 ns.hacknet.upgradeLevel(i, 10 - mod);
 ns.print("node hn-" + i + " leveled up");
 }
 //same for ram
 if (ns.hacknet.getRamUpgradeCost(i) < myMoney() / 2) {
 ns.hacknet.upgradeRam(i);
 ns.print("node hn-" + i + " ram upgraded");
 }
 //and cores
 if (ns.hacknet.getCoreUpgradeCost(i) < myMoney() / 2) {
 ns.hacknet.upgradeCore(i);
 ns.print("node hn-" + i + " core upgraded");
 }
 }
 }
}

 
 

Written by tokumeiko, PG SDVX

 
 
I hope you enjoy the Guide we share about Bitburner – Code for Basic Hacknet Manager; if you think we forget to add or we should add more information, please let us know via commenting below! See you soon!
 
 


Be the first to comment

Leave a Reply

Your email address will not be published.


*