Bitburner
45 valoraciones
basic hacknet manager
Por tokumeiko y 1 colaboradores
a basic code to manage your hacknets for you, while trying not to spend too much money
5
   
Premiar
Favoritos
Favorito
Quitar
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 comentarios
whattodo795 1 ENE a las 11:46 
Thanks!
Kermit 3 JUN 2024 a las 8:53 
nice
22#MANGO#22 26 JUL 2022 a las 13:11 
nice
Yelk 26 ENE 2022 a las 12:28 
H A C K E R M A N
tokumeiko  [autor] 18 ENE 2022 a las 20:54 
@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 ENE 2022 a las 18:46 
Wow, what an elegant approach. Probably not quite optimal, but I can actually understand what's going on!
tokumeiko  [autor] 27 DIC 2021 a las 5:38 
@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 DIC 2021 a las 1:54 
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 DIC 2021 a las 18:21 
nice
Yardstiick 24 DIC 2021 a las 19:45 
nice