Bitburner

Bitburner

65 ratings
Full Automation - Hacknet Manager for All Upgrades
By Laingsta
RAM Usage: 5.7GB

This script will fully automate the purchase of all Hacknet upgrades in the fastest method possible.

The fastest method is exponential returns awarded through selecting the cheapest upgrade at all times, therefore making your money work for you faster. Determine the cheapest upgrade, wait for funds, purchase, rinse and repeat.
4
5
   
Award
Favorite
Favorited
Unfavorite
Create ES5 Script
This script utilises ES5 JavaScript interpreter, otherwise referenced as Netscript 1.0 meaning a file extension of .script is required.

While inside the Bitburner Terminal create a new script by typing the following:

nano nameOfYourFile.script

Example: nano hacknet_infinite.script

Note: This script requires 5.7GB of memory available

Alternative - Create ES6 Script
This script utilises ES6 JavaScript interpreter, otherwise referenced as Netscript 2.0 meaning a file extension of .js is required.

This alternative script has been provided by Caladrel

While inside the Bitburner Terminal create a new script by typing the following:

nano nameOfYourFile.js

Example: nano hacknet_infinite.js

Note: This script requires 5.7GB of memory available

Script Code ES5.script
Copy the contents of the script and save into the new script file you just created.

// Create Function to Return Balance function myMoney() { return getServerMoneyAvailable("home"); } // Disable Logging for the Following Commands Below (We Dont Want To See Them While we Wait for Our Balance to Grow) disableLog("getServerMoneyAvailable"); disableLog("sleep"); // Create Function to Purchase Upgrade Based on 3 Flags for Node, Item, Qty // # Note Qty is not utilised but the Framework is in Place to Future Proof function purchase(node, item, qty){ var node = node, item = item, qty = qty; if (item == "New Node"){ hacknet.purchaseNode(); print("Purchasing New Node") } if (item == "LVL"){ hacknet.upgradeLevel(node , qty) print("Purchasing LVL Upgrade for Node: " + node) } if (item == "RAM"){ hacknet.upgradeRam(node , qty) print("Purchasing RAM Upgrade for Node: " + node) } if (item == "CPU"){ hacknet.upgradeCore(node , qty) print("Purchasing CPU Upgrade for Node: " + node) } } // Create Function to Find the Cheapest Upgrade and Set Flags to be Used by the Purchase Function // We will set the Default Flags to Purchase a New Node, Only to be Overwritten if a Cheaper Option is Available function check_cheapest() { var new_node_cost = hacknet.getPurchaseNodeCost(); var node = "Default"; var item = "New Node"; var qty = 1; var cheapest = new_node_cost; var node_qty = hacknet.numNodes(); // Iterate Through all Node Upgrade Options, Overwrite Flags if Cheaper Upgrade is Found for (var i = 0; i < node_qty; i++) { var node_lvl = hacknet.getLevelUpgradeCost(i, 1); var node_ram = hacknet.getRamUpgradeCost(i, 1); var node_cpu = hacknet.getCoreUpgradeCost(i, 1); if (node_lvl < cheapest) { cheapest = node_lvl; node = i; item = "LVL"; } if (node_ram < cheapest) { cheapest = node_ram; node = i; item = "RAM"; } if (node_cpu < cheapest) { cheapest = node_cpu; node = i; item = "CPU"; } } // I am not a JavaScript Programmer so I am not Adept at String Manipulation in this Language // Print a Summary Log of Cheapest Upgrade Found // Thanks @Dr. Red print( "\n" + "Cheapest Hacknet Upgrade Available:" + "\n" + "Node : " + node + "\n" + "Item : " + item + "\n" + "Qty : " + qty + "\n\n" + "Current Balance : $" + myMoney() + "\n" + "Upgrade Cost : $" + cheapest + "\n" ) // After Determining the Cheapest Upgrade we will wait for Balance to Increase Enough to Purchase (This is why we turned off logging) while (myMoney() < cheapest) { print("Waiting for funds to increase") sleep(3000); } // Call the Purchase Function purchase(node, item, qty); } // Run the Cheapest Upgrade Function in an Infinite Loop while(true) { check_cheapest() }
Alternative - Script Code ES6.js
Copy the contents of the script and save into the new .js file you just created.

/** @param {NS} ns **/ export async function main(ns) { while(true) { // Check optimal purchase var nodeNum = "Default"; var itemType = "New Node"; var cheapest = ns.hacknet.getPurchaseNodeCost(); var num_nodes = ns.hacknet.numNodes(); // Iterate through all nodes and select lowest purchase/upgrade available for (var i = 0; i < num_nodes; i++) { var level_cost = ns.hacknet.getLevelUpgradeCost(i, 1); var ram_cost = ns.hacknet.getRamUpgradeCost(i, 1); var cpu_cost = ns.hacknet.getCoreUpgradeCost(i, 1); if (level_cost < cheapest) { cheapest = level_cost; nodeNum = i; itemType = "Level"; } if (ram_cost < cheapest) { cheapest = ram_cost; nodeNum = i; itemType = "RAM"; } if (cpu_cost < cheapest) { cheapest = cpu_cost; nodeNum = i; itemType = "CPU"; } } // If affordable, purchase and recalculate above var purchased = false; while (!purchased) { var money = ns.getServerMoneyAvailable("home"); if (money >= cheapest) { if (itemType == "New Node"){ ns.hacknet.purchaseNode(); } if (itemType == "Level"){ ns.hacknet.upgradeLevel(nodeNum , 1); } if (itemType == "RAM"){ ns.hacknet.upgradeRam(nodeNum , 1); } if (itemType == "CPU"){ ns.hacknet.upgradeCore(nodeNum , 1); } purchased = true; } // If we didn't purchase, wait 1 second and try again if(!purchased) { await ns.sleep(1000); } } } }
Usage
After saving the script you can run it by typing:

run nameOfYourScript.script

Example: run hacknet_infinity.script

Alternatively if you went for the ES6 option run your code by typing:

run nameOfYourScript.js

Example: run hacknet_infinity.js
Under the Hood
This script iterates through all upgrade options, sets flags for the cheapest option and waits until there is enough funds to purchase.

Currently it does not utilise the quantity function, as the cheapest option is always to purchase in single units to get your money working for you faster under the passive income method. This is why the variable Qty is set to 1 and not overwritten in the loop.

If you read through the Hacknet API on the official website there is an example script which uses a value of 10 when purchasing basic levels for Nodes. IMO buying single units will net you more money in the long run due to exponential returns from the smaller purchases of single levels.

Please see below screen shots below to see how IMBA this script is to your crash flow.


15 Comments
FlynnTheFearless Mar 12 @ 1:28pm 
Check your upgraded outputs. Sometimes 100k more for another level of ram beats 10 on your level or 1-2 on your core. Cheapest isn't always best but the script is nicely done and essentially the same thing.
Bonewagon May 27, 2024 @ 7:12am 
Thank you very much!! It worked perfectly
kettcardriverprofi Jan 24, 2024 @ 10:11am 
I like this. I d call it a "go-crazy-script for Hacknet" :D
Key Oct 7, 2022 @ 10:23am 
thanks for the help king
TexMexChexMix Jul 19, 2022 @ 12:30am 
I enjoyed giving this try. Thanks for sharing
SenorPollo Mar 29, 2022 @ 3:40am 
At my current progress, maxing out 35 hacknet nodes costs me almost 3t$. You seem to be very far in terms of augmentations you own to be able to buy that many maxed out nodes for such a little amount of money. My current limitation is the cost of new nodes, I can just max upgrade on a whim once I acquire them.

My very basic hacking script (I just list all the servers in the network, push a script there and use the max amount of RAM available to grow/weaken/hack in loop) already generate trillions of $ after a few days of playing that game very passively.

Unless I missed something, hacking seems to be way more profitable than buying hacknet nodes early on and once they become profitable, you don't really need to be careful about the cost of upgrading them since you generate way more money than necessary through hacking?
RemoteObserver Feb 28, 2022 @ 1:51pm 
I simplified it a bit, for example, the upgrade function returns false when it fails, so there is no need to check available money. Here is my implementation: https://pastebin.com/wqqw1cMk
Laingsta  [author] Jan 5, 2022 @ 9:05pm 
Should'nt be too hard to write a server script up, I also am new and haven't found a need for servers yet as the passive income from this script is too strong especially if you choose to purchase all augmentations from Netburners on your vanilla run. Money builds so quickly you can augment and start fresh every day. For me Im more interested in the coding contract challenges or the stock market API to worry about scaling already written exploit functions provided by the game. IMO the create a program feature should be removed, or atleast put some type of coding challenge wall in front of these pre-built programs.
Juebar Jan 5, 2022 @ 10:13am 
I love (!) this script! I maxed out all nodes already.
My question is: Is there a comparable script for getting servers up?
I am fairly new to the game - but I am learning :)
would be glad to get a hint.
Thanks !
Laingsta  [author] Jan 4, 2022 @ 12:00am 
@Caladrel Thanks mate, I will add your code as an ES6 option to the guide with credits.