GithubHelp home page GithubHelp logo

bitburner-scripts's Introduction

Bitburner-Scripts

A collection of scripts written for the game Bitburner.
Listed below is the name of each available script and a short description of what it does.
Note that all of the scripts listed require that you are using ns2 instead of ns1

hacknet-upgrades.js

Credit to u/boz987 on Reddit for return on investment math
Purchases the number of requested hacknet nodes and upgrades based on a percentage of your current money.
The script will calculate whether or not buying a server or purchasing an upgrade has a better return on investment.
If purchasing an upgrade is better, it will then determine which type of upgrade is best for each server and purchase upgrades accordingly.
Takes two arguments:

  • pct: The percentage of your money you want to use as a threshold for buying nodes and upgrades. The percentage is converted to a decimal for the calculations. There are currently no checks in place to see if you are outside the bounds of what is feasible so passing in zero, a negative number, or a number greater than 100, will result in the script not working as intended.
  • maxNodes: The maximum number of nodes you want to purchase and upgrade.

buy-servers.js

Purchases the number of servers passed in.
The RAM purchased for each server is calculated based on the number of servers requested and will be the highest amount you can currently afford. Therefore requesting a lower amount of servers will yield more RAM per server, whereas requesting a higher amount of servers will yield less RAM per server. If the number of servers you request is more than the number of server slots available, it will ask to delete old servers with the smallest RAM until enough slots are open to create the requested number of servers. Clicking No on this prompt will kill the script. If the existing servers are already at the maximum RAM capacity or have more RAM than what will be created, it will not delete them. Any number of servers requested after the maximum number of servers has been reached with the maximum RAM, will not be created or deleted.
All purchased servers follow the same naming format of pserv + index so servers will be labeled starting with pserv-0 through pserv-24
Takes one argument:

  • numServers: The number of servers you would like to purchase.

hack-manager.js

Requires targeted-hack.js, targeted-grow.js, targeted-weaken.js, and utils.js to run
Targets server with the most money that is possible for the player to hack and then continually executes targeted-hack.js, targeted-grow.js, and targeted-weaken.js scripts on that target.
It is timed so that the hack, grow, and weaken for each cycle finish in order, so as to maintain optimal security level and money amount on the server. Part of maintaining this synchrony is only executing this targeted script cycle for the duration of how long the time to hack is. Any longer and hacks will initiate after the first hack finishes but before the weaken, increasing the hack time to take longer than accounted for in the initial delay.

targeted-hack.js

Targets a specific server to hack after an initial delay decided by hack-manager.js.
Takes three arguments:

  • threads: number of threads to use on hack, calculated to take half of a servers money
  • hack_delay: time to sleep before initiating hack
  • target: the server to target for the hack

targeted-grow.js

Targets a specific server to grow after an initial delay decided by hack-manager.js.
Takes three arguments:

  • threads: number of threads to use on grow, calculated to double the servers money
  • grow_delay: time to sleep before initiating grow
  • target: the server to target for the grow

targeted-weaken.js

Targets a specific server to weaken decided by hack-manager.js.
Takes two arguments:

  • threads: number of threads to use on weaken, calculated to decrease security by the amount of increase from targeted-hack.js, and targeted-grow.js
  • target: the server to target for the weaken

utils.js

Contains various utility functions used throughout the other scripts.

multiscan

A recursive function which finds all available servers starting from the server passed in.
Takes two arguments:

  • ns: The Netscript package.
  • server: Name of the server you want to start from when scanning.

If home is passed as the value for server, then it will return all available servers in the current bitnode.

gainRootAccess

Attempts to gain root access of the server passed in.
Takes two arguments:

  • ns: The Netscript package.
  • server: Name of the server you want to attempt to gain root access to.

It will attempt to open as many ports as possible on the server before nuking.
If the player does not have enough files to open the required number of ports by the end of the function, it does not attempt to nuke.

bitburner-scripts's People

Contributors

jrpl avatar riley-h-99 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bitburner-scripts's Issues

1 ms sleep loop

when I start the hack-manager.js it just sleeps for 1 ms in an endless loop. Tried to kill and reset everything but still.

hack-manager.js Syntax Error

SYNTAX ERROR
hack-manager.js@home (PID - 4)

Expecting Unicode escape sequence \uXXXX (10:4) (sorry we can't be more helpful)

hack-manager.js sleep loop?

When I use hack-manager.js it fills up the queues in the Active Scripts tab. But then, after a while, it seems to "finish" and only the original hack-manager.js is running with no child scripts on other servers. If I kill hack-manager.js and run it again, it fills up the queues and makes a bunch of money, then lulls to zero again.

Would appreciate if someone could at least explain what might be going on here. Is this likely because of low server money? High security? What gives.

TIA

buy-servers.js output just showing me how much money I have

The script used to work, but it seems to have broken for some time now. I don't remember when exactly it started, but it's followed me to BN2 and back to BN1 again. It also does the same thing each time I install augmentations. Doesn't seem to be based on any sort of stats since it happens early in the BN all the way through to the end.

When the script is run, it immediately terminates. The log output just repeats how much money I have. Here's the output of the one I just ran:

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

getServerMoneyAvailable: returned player's money: $12.628m

Script finished running

hack-manager.js - scp parameter order (Bitburner v2.2.2)

scp is defined as scp(files: string | string[], destination: string, source?: string): boolean in Bitburner v2.2.2 (Steam). This results in the script trying to copy files from target server to home.

if (ns.hasRootAccess(server)) {
await ns.scp('targeted-grow.js', 'home', server);
await ns.scp('targeted-weaken.js', 'home', server);
host_servers.push(server);
}

if (ns.hasRootAccess(server)) {
await ns.scp('targeted-hack.js', 'home', server);
await ns.scp('targeted-grow.js', 'home', server);
await ns.scp('targeted-weaken.js', 'home', server);
host_servers.push(server);
}

Hostname is Expected to be a String

Hi! I am trying to use these scripts, but it seems when trying to run all three targeted-hack.js, targeted-grow.js, and targeted-weaken.js, I get an error message saying that...

"TYPE ERROR
targeted-hack.js@sigma-cosmetics (PID - 13)

hack: hostname expected to be a string. Is undefined.

Stack:
targeted-hack.js:[email protected]"

This same thing happened with targeted-grow.js, and targeted-weaken.js
I'm not sure what to do with this, so I would love for someone to help me out. Thanks!

hack-manager.js Runtime Error

RUNTIME ERROR
hack-manager.js@home (PID - 6)

Failed to resolve module specifier "utils.js". Relative references must start with either "/", "./", or "../".
stack:
TypeError: Failed to resolve module specifier "utils.js". Relative references must start with either "/", "./", or "../".

1ms sleep loop after a successful cycle

So ill start this out by saying im entirely new to java and scripting in general so I could be doing something wrong. The issue im having is that i run hack-manager.js and it works as intended for the first and sometimes even the second cycle, but randomly at the beginning of another cycle it will enter a 1ms loop and then do nothing for the rest of the time it runs. Could this be caused by me not having enough ram on the home system? Im pretty stumped on how to solve it.

Bitburner 2.0 changes ns.scp function

The script does not copy the hack, weak, and grow files to run. They should be changed from
"await ns.scp('targeted-weaken.js', 'home' , server)"
to
"await ns.scp('targeted-weaken.js', server , 'home')"

threads should be a positive integer

TYPE ERROR
hack-manager.js@home (PID - 9)

exec: threads should be a positive integer, was 7320.958053450061

Stack:
hack-manager.js:[email protected]

L366:
ns.exec('targeted-grow.js', prep_server, gt, gt, 0, hack_target);

i think its the gt variable from L339:
gt = ns.growthAnalyze(hack_target, initial_growth_amount);

exec() says it round to the nearest integer but apparently its not.

I'm not sure if this is an issue for your script or bitburner

Infinite loop when when initially low money on the server

	while (ns.weakenAnalyze(weaken_threads) < sec_increase * 1.1) {
		weaken_threads += 5;
		await ns.sleep(1);
	}

Script breaks down there when sec_increase equals infinity.

 let hack_threads = ns.hackAnalyzeThreads(hack_target, ns.getServerMoneyAvailable(hack_target) / 2);

Problem is that hack threads for me equals infinity for server global-pharm.

TYPE ERROR, positive interger

TYPE ERROR
hack-manager.js@home (PID - 30)

exec: threads should be a positive integer, was 1.9255258526271177

Stack:
hack-manager.js:L216@little_hack
hack-manager.js:L330@async Module.main

what does this mean

Latest update to hack-manager.js not working

Just started in BN2 and couldn't get the hack-manager script to work due to RAM issues. Noticed the update from @Riley-H-99 today that says it should address this; but the script doesn't seem to run after initiating it.

Running the script:

Bitburner v1.4.0 (a3c599e6)
[home ~/]> run hack-manager.js 
Running script with 1 thread(s), pid 19 and args: [].
[home ~/]> ps
[home ~/]> 

For the sake of anybody looking at this in the future, this is the copy of the code that I'm running right now:

/** @param {NS} ns **/
import { multiscan, gainRootAccess } from "utils.js";

function maxElement(arr) {
	let max = 0;
	for (let i = 0; i < arr.length; i++) {
		if (arr[i] > max) {
			max = arr[i]
		}
	}

	let maxE = arr.indexOf(max);
	return maxE
}

export function best_target(ns, arr) {
	let list = [];
	let results = [];
	arr.forEach(server => {
		if (!ns.hasRootAccess(server)) {
			gainRootAccess(ns, server);
		}

		if (ns.hasRootAccess(server) && ns.getServerRequiredHackingLevel(server) <= ns.getHackingLevel() && server != 'home' && !ns.getPurchasedServers().includes(server)) {
			list.push(server);
		}
	})

	let i = 0;
	list.forEach(target => {
		results[i] = ns.getServerMaxMoney(target);
		i++;
	})

	return list[maxElement(results)];
}

export async function main(ns) {
	while (true) {
		let full_list = multiscan(ns, 'home');

		// finds most profitable server to target
		const hack_target = best_target(ns, full_list);

		// determines threads needed for grow hack and weaken to maintain optimal profit
		const grow_threads = ns.growthAnalyze(hack_target, 2);
		const hack_threads = ns.hackAnalyzeThreads(hack_target, ns.getServerMoneyAvailable(hack_target) / 2);
		const sec_increase = ns.hackAnalyzeSecurity(hack_threads) + ns.growthAnalyzeSecurity(grow_threads);
		let weaken_threads = 1;
		while (ns.weakenAnalyze(weaken_threads) < sec_increase * 1.1) {
			weaken_threads++;
		}

		// determines needed RAM for a cycle of grow weaken hack with determined threads
		const needed_ram = (grow_threads * ns.getScriptRam('targeted-grow.js', 'home') + hack_threads * ns.getScriptRam('targeted-hack.js', 'home') + weaken_threads * ns.getScriptRam('targeted-weaken.js', 'home'));

		// goes through Purchased servers and creates list of servers with enough RAM to utilize 
		// note only Purchased servers are going to reliably have enough RAM
		let purchased_servers = ns.getPurchasedServers();
		let host_servers = [];

		purchased_servers.forEach(server => {
			if (ns.getServerMaxRam(server) >= needed_ram) {
				host_servers.push(server);
			}
		})

		if (ns.getServerMaxRam('home') >= needed_ram) {
			host_servers.push('home');
		}

		if (host_servers == 0) {
			ns.print('Not enough RAM for proper hack cycle current needed is ' + needed_ram);
			return 0
		}

		// prepares target to be hacked uses home to weaken and grow server to required initial conditions
		const initial_growth_amount = .5 * ns.getServerMaxMoney(hack_target) / ns.getServerMoneyAvailable(hack_target);
		let gt = 0;
		if (initial_growth_amount > 1) {
			gt = ns.growthAnalyze(hack_target, initial_growth_amount);
		}

		let wt = 0;
		while (ns.weakenAnalyze(wt) < ns.getServerSecurityLevel(hack_target) + ns.growthAnalyzeSecurity(gt) - ns.getServerMinSecurityLevel(hack_target)) {
			wt++;
		}
		if (wt == 0) {
			wt = 1;
		}

		ns.print(wt + ' ' + gt);

		let prep = 1;
		const prep_RAM = ns.getScriptRam('targeted-grow.js', 'home') * gt + ns.getScriptRam('targeted-weaken.js', 'home') * wt;
		const prep_server = host_servers.find(server => ns.getServerMaxRam(server) - ns.getServerUsedRam(server) >= prep_RAM);
		if (prep_server == null) {
			prep = 0;
		}
		ns.print(prep_server + ' ' + prep);

		if (gt > 1 && prep) {
			ns.exec('targeted-grow.js', prep_server, gt, gt, 0, hack_target);
			ns.exec('targeted-weaken.js', prep_server, wt, wt, hack_target);
			await ns.sleep(ns.getWeakenTime(hack_target) + 1000);
		}

		else if (ns.getServerSecurityLevel(hack_target) > ns.getServerMinSecurityLevel(hack_target) * 1.5 && prep) {
			ns.exec('targeted-weaken.js', prep_server, wt, wt, hack_target);
			await ns.sleep(ns.getWeakenTime(hack_target) + 1000);
		}


		// sets a variable to keep track of time taken executing hacks in the loop
		// if a hack were initiated later than the reset time the first hack would complete changing hack times for every hack following it throwing off the sync
		// most of the time execution time doesn't take that long but this safeguards overly draining a target through desync
		let initial_time = Date.now();
		let k = 0;

		for (let i = 0; i < host_servers.length; i++) {

			let weaken_time = ns.getWeakenTime(hack_target);
			let grow_time = ns.getGrowTime(hack_target);
			let hack_time = ns.getHackTime(hack_target);
			let grow_delay = weaken_time - grow_time - 2;
			let hack_delay = weaken_time - hack_time - 1;

			// assigns a server from the host server list and determines amount of cycles possible
			let server = host_servers[i]
			let n = Math.floor((ns.getServerMaxRam(server) - ns.getServerUsedRam(server)) / needed_ram);

			// writes needed scripts to host server
			await ns.scp('targeted-grow.js', server);
			await ns.scp('targeted-hack.js', server);
			await ns.scp('targeted-weaken.js', server);

			// loops through a cycle of grow weaken and hack executions on the target
			// each script will complete in order of grow hack weaken 2 milliseconds apart
			while (n > 0) {
				if (Date.now() >= initial_time + ns.getHackTime(hack_target)) {
					while (ns.getServerMaxRam(host_servers[k]) - ns.getServerUsedRam(host_servers[k]) < ns.getScriptRam('targeted-weaken', 'home') * weaken_threads) {
						k++;
						if (k == host_servers.length) {
							k = 0;
							await ns.sleep(10000);
						}
					}
					ns.exec('targeted-weaken.js', host_servers[k], weaken_threads, weaken_threads, hack_target);
					await ns.sleep(weaken_time + 20);
					i = 0;
					initial_time = Date.now();
					break
				}

				ns.exec('targeted-weaken.js', server, weaken_threads, weaken_threads, hack_target, n);
				ns.exec('targeted-grow.js', server, grow_threads, grow_threads, grow_delay, hack_target, n);
				ns.exec('targeted-hack.js', server, hack_threads, hack_threads, hack_delay, hack_target, n);
				await ns.sleep(3);

				n--;
			}

			await ns.sleep(5);
		}

		await ns.sleep(10);
	}
}

Does hack-manager take in to account a rising hack attribute?

Does hack-manager take in to account the rising hack attribute, and choose a new optimal target after every hack sequence? If not, that would be a very good feature to add.
Also, if it does not already, it would be beneficial for it to automatically scan available connections (not just those already nuked) and nuke any that are available to be nuked.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.