Advertisement
Guest User

Bitburner hacknet node script

a guest
Sep 28th, 2022
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. //Don't spend more than this proportion of our total money on any single purchase
  2. var cashMultiplier = 1 / 20
  3.  
  4. //Should we subtract the cost of whatever we purchase from our available cash?
  5. //not updating cash after purchase can sometimes keep your home cash pretty low as it can make a lot of purchases each loop
  6. //upating after purchase can make it take a while to build up a strong hacknet
  7. var updateAvailableCashAfterPurchase = true
  8.  
  9. //How long to wait between each purchase loop
  10. var timerMS = 30000
  11.  
  12. /** @param {NS} ns */
  13. export async function main(ns) {
  14. ns.disableLog("getServerMoneyAvailable");
  15. ns.disableLog("sleep");
  16.  
  17. while (true) {
  18. //var madePurchase = false;
  19. var availableCash = ns.getServerMoneyAvailable("home") * cashMultiplier;
  20. if (ns.hacknet.getPurchaseNodeCost() < availableCash) {
  21. if (updateAvailableCashAfterPurchase) {
  22. availableCash -= ns.hacknet.getPurchaseNodeCost()
  23. }
  24. ns.hacknet.purchaseNode();
  25. ns.print("purchased hacknet node");
  26. }
  27. for (var i = 0; i < ns.hacknet.numNodes(); i++) {
  28. availableCash = ns.getServerMoneyAvailable("home") * cashMultiplier;
  29. while (ns.hacknet.getLevelUpgradeCost(i) < availableCash) {
  30. if (updateAvailableCashAfterPurchase) {
  31. availableCash -= ns.hacknet.getLevelUpgradeCost(i)
  32. }
  33. ns.hacknet.upgradeLevel(i, 1);
  34. }
  35. while (ns.hacknet.getRamUpgradeCost(i) < availableCash) {
  36. if (updateAvailableCashAfterPurchase) {
  37. availableCash -= ns.hacknet.getRamUpgradeCost(i)
  38. }
  39. ns.hacknet.upgradeRam(i, 1);
  40. }
  41. while (ns.hacknet.getCoreUpgradeCost(i) < availableCash) {
  42. if (updateAvailableCashAfterPurchase) {
  43. availableCash -= ns.hacknet.getCoreUpgradeCost(i)
  44. }
  45. ns.hacknet.upgradeCore(i, 1);
  46. }
  47. }
  48.  
  49. await ns.sleep(timerMS);
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement