Bitburner

Bitburner

45 ratings
basic hacknet manager
By tokumeiko and 1 collaborators
a basic code to manage your hacknets for you, while trying not to spend too much money
5
   
Award
Favorite
Favorited
Unfavorite
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"); } } } }
11 Comments
whattodo795 1 Jan @ 11:46am 
Thanks!
Kermit 3 Jun, 2024 @ 8:53am 
nice
22#MANGO#22 26 Jul, 2022 @ 1:11pm 
nice
Yelk 26 Jan, 2022 @ 12:28pm 
H A C K E R M A N
tokumeiko  [author] 18 Jan, 2022 @ 8:54pm 
@RedPine it's literally looping through all possible upgrades every second, and checking if the cost of each one is less than half of your money, it's not the best approach, but it runs fast.
a better method would be it also calculated how long it would take for the upgrades to pay for themselves, more expensive hacknets can take a few days to earn enough money if you buy too many, but this a decent way to handle it as a beginner.
RedPine 18 Jan, 2022 @ 6:46pm 
Wow, what an elegant approach. Probably not quite optimal, but I can actually understand what's going on!
tokumeiko  [author] 27 Dec, 2021 @ 5:38am 
@Slyve you create files ingame by using "nano {filename}" this also open the file editor.
to run a script you use "run {filename}"
more information can be found in the games tutorial section, which includes links to the games documentation where you can learn almost everything you need to know about the game.
Corvus 27 Dec, 2021 @ 1:54am 
Where to put or how to load the js file in the game?

BTW where are all the scripts saved? Any local folder?

Hope you can help me, to make your script run :)
Red 25 Dec, 2021 @ 6:21pm 
nice
Yardstiick 24 Dec, 2021 @ 7:45pm 
nice