Bitburner
45 人が評価
basic hacknet manager
作者: tokumeiko と 1 のコラボレーション
a basic code to manage your hacknets for you, while trying not to spend too much money
5
   
アワード
お気に入り
お気に入り
お気に入りから削除
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 件のコメント
whattodo795 1月1日 11時46分 
Thanks!
Kermit 2024年6月3日 8時53分 
nice
22#MANGO#22 2022年7月26日 13時11分 
nice
Yelk 2022年1月26日 12時28分 
H A C K E R M A N
tokumeiko  [作成者] 2022年1月18日 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 2022年1月18日 18時46分 
Wow, what an elegant approach. Probably not quite optimal, but I can actually understand what's going on!
tokumeiko  [作成者] 2021年12月27日 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 2021年12月27日 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 2021年12月25日 18時21分 
nice
Yardstiick 2021年12月24日 19時45分 
nice