Bitburner

Bitburner

View Stats:
THE best hack script
I haven't seen this program here on steam discussions so I want to share it. It is awesome from start to finish from what I'm seeing. I'm only early/mid game but it's been useful from lvl 1 hacking to lvl 500+ hacking. pastebin = SQgAKMX8

EDIT: since steam scrubs the links I'll paste the entire page here.
------------------------------------------------------------------------------------------------

Here we go again, V2 has arrived!
Hello once more, today I bring you a better chunk of code! But it’s slightly less easy to understand

100% plug and play, but put it in a .ns file instead of .script, create in and run from home

NOTICE: It will automatically create/overwrite 3 files in the home directory called “weak.script”, “grow.script” and “hack.script”

This guide has a little less documentation, but much higher gains than the last

Let me know if there is any issue you can see, or any way to improve it further 🙂


Please note that it takes a while to warm up the wallets before the farming can start




Code
/** @param {NS} ns**/
export async function main(ns) {
ns.disableLog("ALL"); //Visual clarity

//Welcome to the Auto Farm part 2: Electric Boogaloo
//This script is a little more complicated to explain easily, it dedicates high RAM servers to attack high profit servers
//This is also set and forget, your EXEs and hacking level are reacquired each second, so new servers are added without needing to reboot it
//Well I hope this brings you ideas, knowledge and or profits :D

var files = ["weak.script", "grow.script", "hack.script"];//No touching, unless you understand everything here
await ns.write(files[0], "weaken(args)", "w"); await ns.write(files[1], "grow(args)", "w"); await ns.write(files[2], "hack(args)", "w");

var serverList; var targetList; var hostList; var exes; var temp; var manager = false;
var cycle = [0, "─", "\\", "|", "/"]; var latest = [["-", "-"], ["-", "-"], ["-", "-"]];
if (false) { brutessh(); ftpcrack(); relaysmtp(); httpworm(); sqlinject() } //Avoid RAM cost bypass error

var pServers = await ns.prompt("Use player servers as hosts?");

async function scanExes() {
exes = ["BruteSSH", "FTPCrack", "relaySMTP", "SQLInject", "HTTPWorm"];
for (let i = 0; i <= exes.length - 1; i++) { if (!ns.fileExists(exes + ".exe")) { exes.splice(i, 1); i-- } }//Removes EXEs you don't have
}

function arraySort(array) { return array.sort(function (a, b) { return b[0] - a[0] }) }//Sorts nested arrays
function logBalance(server) {//For balance in display
return [ns.nFormat(ns.getServerMoneyAvailable(server), '0a')] + " / " + [ns.nFormat(ns.getServerMaxMoney(server), '0a')]
+ " : " + ns.nFormat(ns.getServerMoneyAvailable(server) / ns.getServerMaxMoney(server), '0%')
}

async function log() {//The display
if (cycle[0] >= 4) { cycle[0] = 0 }; cycle[0]++;//Speen
ns.clearLog();
ns.print("╔═══╦═╣ HOST ╠════════════════╣ TARGET ╠═╗");
ns.print("║ G ║ " + latest[0][0] + latest[0][1].padStart(34 - latest[0][0].length) + " ║")
ns.print("║ W ║ " + latest[1][0] + latest[1][1].padStart(34 - latest[1][0].length) + " ║")
ns.print("║ H ║ " + latest[2][0] + latest[2][1].padStart(34 - latest[2][0].length) + " ║")
ns.print("║ " + cycle[cycle[0]] + " ╠════════════════════════════════════╣")
if (targetList.length < 6) { ns.print("╚═══╝ ║") } else {
ns.print("╠═══╝ Priority Servers Balance ║")
for (let i = 0; i < 6; i++) {
temp = targetList[1];
ns.print("║ > " + temp + logBalance(temp).padStart(36 - temp.length) + " ║")
}
ns.print("╠════════════════════════════════════════╝")
ns.print("║ EXE " + exes.length + "/5 ║ HOSTS " + hostList.length + " ║ TARGETS " + targetList.length)
ns.print("╠════════════════════════════════════════╗")
if (manager) {
ns.print("╠══════╣ Managing " + ns.hacknet.numNodes() + " HNet Nodes ╠".padEnd(21, "═") + "╣")
}
}
}

async function scanServers() {//Finds all servers
serverList = ns.scan("home"); let serverCount = [serverList.length, 0]; let depth = 0; let checked = 0; let scanIndex = 0;
while (scanIndex <= serverCount[depth] - 1) {
let results = ns.scan(serverList[checked]); checked++;
for (let i = 0; i <= results.length - 1; i++) {
if (results != "home" && !serverList.includes(results)) {
serverList.push(results); serverCount[depth + 1]++
}
}
if (scanIndex == serverCount[depth] - 1) { scanIndex = 0; depth++; serverCount.push(0) } else { scanIndex++ };
}
}

async function checkServers() {//Sorts servers into lists based on RAM and money/hack time ratio: hostList and targetList
targetList = []; hostList = [[ns.getServerMaxRam("home"), "home"]];
if (pServers) {//Adds in player servers
temp = ns.getPurchasedServers();
for (let i = 0; i < temp.length; i++) {
hostList.push([ns.getServerMaxRam(temp[i]), temp])
await ns.scp(files, "home", temp);
}
}
for (let i = 0; i <= serverList.length - 1; i++) {
let cTarget = serverList;
if (ns.getServerMoneyAvailable(cTarget) > 0 || ns.getServerMaxRam(cTarget) > 2) {//Filters out servers like darkweb
if (ns.getServerNumPortsRequired(cTarget) <= exes.length) {
for (let i = 0; i <= exes.length - 1; i++) { ns[exes[i].toLowerCase()](cTarget) }//Runs all EXEs you have
ns.nuke(cTarget);//Ghandi.jpeg
temp = [Math.floor(ns.getServerMaxMoney(cTarget) / ns.getServerMinSecurityLevel(cTarget)), cTarget];
if (ns.getServerMoneyAvailable(cTarget) != 0 && !targetList.includes(temp) && ns.getServerRequiredHackingLevel(cTarget) <= ns.getHackingLevel()) {
targetList.push(temp); targetList = arraySort(targetList);
}
temp = [ns.getServerMaxRam(cTarget), cTarget];
if (ns.getServerMaxRam(cTarget) > 2 && !hostList.includes(cTarget)) {
hostList.push(temp); hostList = arraySort(hostList)
}
await ns.scp(files, "home", cTarget);
}
}
}
}


async function hackAll() {//Dedicates high RAM servers to attack high profit per second servers
let tarIndex = 0; let loop = false;
for (let i = 0; i <= hostList.length - 1; i++) {
if (tarIndex > targetList.length - 1) { tarIndex = 0; loop = true };
let hHost = hostList[1]; let hTarget = targetList[tarIndex][1]; let freeRam;
if (hHost == "home") { freeRam = Math.max(ns.getServerMaxRam(hHost) - ns.getServerUsedRam(hHost) - 50, 0) } else {
freeRam = ns.getServerMaxRam(hHost) - ns.getServerUsedRam(hHost)
}
if (freeRam >= 4) {
let threads = Math.floor(freeRam / 1.75); let bThreads = 0;
if (ns.getServerMoneyAvailable(hTarget) < ns.getServerMaxMoney(hTarget) * .70 || loop) {//Server money target here
latest[0][0] = hHost; latest[0][1] = hTarget;
if (threads > 2) {
ns.exec("weak.script", hHost, Math.ceil(0.08 * threads), hTarget);
ns.exec("grow.script", hHost, Math.floor(0.92 * threads), hTarget);
} else { ns.exec("grow.script", hHost, threads, hTarget) }
} else if (ns.getServerSecurityLevel(hTarget) > ns.getServerMinSecurityLevel(hTarget) + 5) {//Security target here
latest[1][0] = hHost; latest[1][1] = hTarget;
ns.exec("weak.script", hHost, threads, hTarget);
} else {
while (parseFloat(ns.hackAnalyze(hTarget)) * threads > .4) { threads--; bThreads++ }//Hack limit here
latest[2][0] = hHost; latest[2][1] = hTarget;
ns.exec("hack.script", hHost, threads, hTarget);
if (bThreads > 0) { ns.exec("weak.script", hHost, bThreads, hTarget) }
}
}
tarIndex++
}
}
//Put modules below here
manager = await ns.prompt("Activate Hacknet Manager?");
async function hnManager() {
let mode = ["Level", "Ram", "Core"]
function check(q) { return eval(q < ns.getPlayer().money / 5) }
if (check(ns.hacknet.getPurchaseNodeCost())) {
ns.hacknet.purchaseNode();
}
for (let i = 0; i < ns.hacknet.numNodes(); i++) {
for (let n = 0; n < 3; n++) {
if (check(ns.hacknet["get" + mode[n] + "UpgradeCost"](i))) {
ns.hacknet["upgrade" + mode[n]](i);
}
}
}
}
//But above here
ns.tail()
while (true) {//Keeps everything running once per second
await scanExes()
await scanServers()
await checkServers()
await hackAll()
if (manager) { await hnManager() }
await log()
await ns.asleep(1000)
}}



Written by PG SDVX
Last edited by ejizme; Jan 11, 2022 @ 10:00am
< >
Showing 1-15 of 21 comments
Dolly ✨🌈🔧 Jan 11, 2022 @ 7:51am 
Links get scrubbed by Steam. Use a [ code ] tag or try another site to host it?
Shogal Jan 11, 2022 @ 9:37am 
Upload it to pastebin or github gist and give a link, so we can read the script easy with syntax highlighting rather than wall of text.
tclord Jan 11, 2022 @ 11:56am 
This script is already in the community hub, isn't it?
sNapz Jan 11, 2022 @ 12:34pm 
or search on github and there so many much more complex scripts.
Broso Jan 11, 2022 @ 12:57pm 
Or just try to come up with something on your own because that is the actual fun that's to be had in this game.

It IS interesting to see other people's approaches though.
tclord Jan 11, 2022 @ 2:03pm 
Originally posted by Broso:
Or just try to come up with something on your own because that is the actual fun that's to be had in this game.

Agreed. You actually learn and improve at coding as well. There is no skill involved with copy and paste.
76561198031356890 Jan 13, 2022 @ 9:47pm 
Originally posted by wickered:
Originally posted by Broso:
Or just try to come up with something on your own because that is the actual fun that's to be had in this game.

It IS interesting to see other people's approaches though.
...I mean, it looks like all the script does is hacking and hacknet. Those are two core mechanics but far from everything. There's still all the singularity stuff, corporations and gangs, etc.
I like going through scripts like this and figuring out the purpose of all the things (and documenting them). You can then work out how to hack the script apart and reapply it based on different needs.
So yeah, I appreciate the post.

Definently not everything. RIght now it's almost everything I need though. I havent even hit the first bitnode. I'm not a programmer but maybe I can peice together enough scripts to helhp me further, after I progress. This is the base though.
Snicker Jan 15, 2022 @ 7:09pm 
Well, not exactly plug and play. Note the first: Needs 12.60 GB of RAM, so that first upgrade is mandatory.

Second, ran it after upgrades and got this:

RUNTIME ERROR
auto-farm.js@home

scan: Invalid hostname or IP: home,zer0

Stack:
auto-farm.js:L56@scanServers
auto-farm.js:L145@Module.main

Man this is educational, though.
duregard Jan 16, 2022 @ 2:11am 
This is far from "THE best" hackscript though. It coud be a good starter hackscript with a few fixes though (like using hackAnalyze without a loop).
76561199233805760 Jan 17, 2022 @ 7:47am 
Nice
TheDude1972 Jan 17, 2022 @ 9:20pm 
Copied from the number one available steam guide by of course someone else (PG SDVX)...

If you want to see the latest update which THE ORIGINAL creator PG SDVX still does. just go to the ORIGINAL guide and not this sad thief's copy and paste attempt.
Last edited by TheDude1972; Jan 17, 2022 @ 9:22pm
ille216 Jan 22, 2022 @ 3:08am 
that is one of the worst hack scripts... that is so litte gain / time
tclord Jan 22, 2022 @ 9:08pm 
I tried to figure out the logic of how it works. I failed. The logic doesn't make sense. It does make money, though, but any kind of hack program is going to make you money.
SporeSorcerer Jun 11, 2022 @ 6:44am 
I don't know how this can work at all.
The author forgot a lot of references to Array positions.

such as :

if (results != "home" [...])

He is comparing a arrray of strings with a string...

await ns.scp(files, "home", temp)

Trying to copy a file to an array of strings, again...

I've been debugging this mess for an hour and half. It has more holes than swiss cheese... :steamfacepalm:
aquern Jun 12, 2022 @ 6:30am 
I would put code inside CODE /CODE tags for legibility on this forum. Example:
//This is in a coding format
In general, this looks a lot like my second group of scripts. I ended up re-writing the non-hacknet material before finishing my third bitnode, and got a roughly 10x improvement in efficiency (far more than I expected). Note that I am not claiming that my attack scripts cannot be further improved - they can. The hacknet material lasted longer, but has also been re-written, for a more modest improvement. The main issue is that various purchases have different benefits. This is obtainable through Formulas.exe, or something like:

// The value of the hacknet node, relative to 1 for level 1, 1 RAM, and 1 core. // warning: This function changes for Hacknet servers. export function valueHackNetNode(ns, level, ram, cores) { return level * Math.pow(1.035, Math.log2(ram)-1) * (1 + (cores +5) / 6); }

Source: https://github.com/danielyxie/bitburner/blob/46b0b399e9dbdbbea170257bf5cb49aa8b037782/src/Hacknet/formulas/HacknetNodes.ts

I /think/ your hackall() function can be improved significantly without major changes to your scripts. I think you're ignoring how long some of those attack scripts take, as those durations can vary. You can get this information dynamically with the material unlocked through Formulas.exe, or read about it in the wiki or the source code.

You are missing a major feature that I consider roughly as important as a decent set of attack scripts, and is accessible at the beginning of the game. It does consume RAM, though, so it /might/ not be worthwhile yet.
ns.share()
Last edited by aquern; Jun 12, 2022 @ 7:43am
< >
Showing 1-15 of 21 comments
Per page: 1530 50