r/Bitburner • • Sep 24 '24

Why won’t my script run?

Thumbnail
gallery
0 Upvotes

I’m gonna preface this by saying I’m completely new to coding as a whole, so I actually just have no clue wtf I’m doing. Why won’t my script run? It’s completely just not working at all and I’m just confused, I’ve tried everything I could think of to get it to work (not much) and nada. I always get the same we’re message too, even when I did the men command.


r/Bitburner • • Mar 07 '26

chatgpt help me to play

0 Upvotes

still updating


r/Bitburner • • Apr 23 '26

Question/Troubleshooting - Open My work PC has games webpages blocked, including BitBurner. Is there a way to make this game portable?

0 Upvotes

I really want to play this game offline. I have no access to steam or the online version of this game in my workplace PC. Is there a way to get bitburner running on a portable usb or storing it in an android phone and then copying all necessary files to the work PC?


r/Bitburner • • Feb 05 '22

Does this scrip work?

Post image
0 Upvotes

r/Bitburner • • Mar 22 '22

I hate this game

0 Upvotes

i spend time and effort making a script to hack stuff and when I say for example I called my script leg. script so I say run leg.script and the game says 'script doesn't exist' like bruh I JUST MADE THAT SCRIPT HOW CAN IT NOT EXIST


r/Bitburner • • Jan 07 '24

I just messed up so bad

Post image
8 Upvotes

I just brought some augmentations and when I did, it messed up my game…. I HAD LIKE 20 BILLION


r/Bitburner • • 27d ago

NetscriptJS Script First post (script share)

0 Upvotes

This is my home:/callback.js script. I have just maxed out sourcefile 1 and am working on BN4.2 so am finally getting a chance to go crazy with the ns.singularity API!

/**  {NS} ns */
export async function main(ns) {
ns.exec("abyssal_scan.js", "home");

/* returns master_hosts.txt, a list of all vanilla servers as: 
[hostname, maxRAM, requiredPorts, requiredHackingLevel, \n] 
and launches abyssal_sort.js, which iterates through master_hosts.txt, 
divvys up the entries by whether or not they have maxRAM > 0, 
sorts each list by requiredHackingLevel, and outputs each list respectively as
nonzeroRAM_hosts.txt and zeroRAM_hosts.txt. */

await ns.sleep(10000);

ns.exec("purchasePortbreakers.js", "home");

/* If not already present, purchases a TOR router. 
iterates through 
["bruteSSH.exe", "FTPCrack.exe", "RelaySMTP.exe", "HTTPWorm.exe", "SQLInject.exe"],
checks if they need to be purchased and whether I can afford them, and purchases them if
necessary/possible. Exits once SQLInject.exe is purchased. */

await ns.sleep(10000);

ns.exec("RAMShare_launcher.js", "home");

/* calculates half of my available RAM and dedicates it to ns.exec("RAMShare.js", "home",
n_threads). Every 10min, it checks to see if I have more/less RAM available than before,
assigns the new n_threads value in the event of a change, kills the currently running
process, and starts a fresh instance with the newly adjusted thread count. */

await ns.sleep(10000);

ns.exec("backdoor_targets.js", "home");

/* iterates through the list of servers I know of to be backdoored: 
["CSEC", "avmnite02h", "I.I.I.I", "run4theh111z", "fulcrumassets"], 
checks if they currently have a "pathFile" (`${target}_connect.txt`) and if not, 
runs a script called path.js which traces the physical path from /home to target,
outputting the path to `${target}_connect.txt`. exits when pathfiles for all listed
entries have been generated successfully. */

await ns.sleep(10000);

ns.exec("install_backdoors.js", "home");

/* iterates through the list of servers I know of to be backdoored: 
["CSEC", "avmnite-02h", "I.I.I.I", "run4theh111z", "fulcrumassets"], 
checks if they currently have a backdoor and if not, whether I can successfully pull off
installing one. uses the pathfiles generated earlier to traverse the network path, verify
connection to target host, install backdoors on the eligible entries that need it, 
return /home, sleep for 5min, and repeat until exit condition of: "fulcrumassets" has
been successfully backdoored. */

await ns.sleep(10000);

ns.exec("breakdown.js", "home");

/* iterates through "master_hosts.txt", checks for closed ports, runs the necessary
portbreakers if present, checks if openPorts >= requiredPorts, runs nuke.exe if so, and
++'s a var called nukedHosts. exits when nukedHosts === 69, since I haven't figured out a
way to arrive at the target figure programmatically. */

await ns.sleep(10000);

ns.exec("swarm.js", "home");

/* iterates through "nonzeroRAM_hosts.txt", checks for getserver().hasAdminAccess and
sufficient hacking skill, then checks to see if "local_attack.js" (my w/g/h script) is
present and/or running. If yes to both, ++'s a var called hackedHosts and moves on. If
not present, scp's it from home and executes it with the maximum number of threads
available on the target host. If present and not running, deletes the existing copy,
scp's the current copy from /home, and executes it with max threads available on target
host. exits when hackedHosts === 43,  since I haven't figured out a way to arrive at the
target figure programmatically. */
}

Currently in the works:

prestige_hacks.js <- to automate hacking the high value targets in "zeroRAM_hosts.txt" from /home,

life_of_crime.js <- to automate criminal activity,

symbol_nerd.js <- to automate stock trading,

auto_augment.js <- to automate faction work/augmentations,

working_stiff.js <- to automate vanilla job activity


r/Bitburner • • Mar 11 '23

whats the best js script to hack all servers at once?

0 Upvotes

im lazy


r/Bitburner • • Mar 03 '26

Suggestion - TODO Translate game documentation in (Russia Language)

1 Upvotes

Hey, guys! I'm from Russia and I know a lot about the game myself, because I understand what's written and used to do real programming. But in any case, would you like to additionally translate the documentation language into Russian?
I understand that this may be quite difficult, but it will lead to an influx of new people who would like to try their hand at your game, but cannot do so due to their lack of English proficiency.


r/Bitburner • • May 04 '26

I built an Ollama (or Claude Code)-powered AI player that actually plays the game — open source, runs on local LLMs

6 Upvotes

I got tired of writing scripts for every edge case, so I built an AI agent that reads the full game state every 60 seconds and decides what to do next — buy programs, deploy hacks, commit crimes, manage sleeves, join factions. It runs on a local Ollama instance (Llama 3.1 8B on a Jetson in my case, but any Ollama host works).

What it actually does:

The AI receives your complete game state as structured JSON — hack level, money, server fleet, gang info, bladeburner status, augmentations, faction rep, running scripts — and returns 1-5 action commands per cycle. Each action maps to a real NS Singularity call. It doesn't just suggest — it executes.

The safety rails are the interesting part.

Every action the AI proposes passes through a validator before execution. It can't install augmentations with fewer than 5 pending (wasteful reset). It can't spend more than 90% of your cash in one cycle. It can't soft reset without a confirmation file. It can't kill scripts or delete files. Blocked actions are logged with the reason. The AI also gets its previous action results fed back each cycle, so it learns from failures — if the safety rail blocks an upgrade_server three times in a row because of cash reserve, it eventually pivots to something else.

You can see it working in the screenshots — the AI kept trying to upgrade a server to 8 TB but the cash reserve safety rail blocked it every time (SKIP: upgrade_server would violate cash reserve). That's the system working as intended.

The stack:

scb.js is the master orchestrator — one script to run everything. It handles scanning, rooting, parallel backdooring, TOR/program auto-purchasing, incremental server upgrades, and companion script launching. The Ollama player is a spawned child process that handles strategy while scb.js handles infrastructure.

There's also a watchdog (scb-watchdog.js) that monitors the Ollama connection, auto-reconnects when it drops, and can hot-reload scb.js when you save changes through bitburner-filesync.

Flip any flag to disable a feature. The Ollama player has its own config for backend (ollama or claude), host, model, poll interval, and safety limits.

What I'm not claiming:

This won't optimally speedrun a BitNode. A well-tuned autopilot.js with hardcoded heuristics will outperform it on pure efficiency. What this does is make the game playable while you're AFK without writing a specific script for every situation. The AI adapts to whatever state it finds — early game, mid game, post-aug, new BitNode.

Repo: github.com/Subzero121800/BitBurner-AI

MIT licensed. PRs welcome. If you have a local Ollama instance running, you can be up in under 5 minutes.


r/Bitburner • • Sep 27 '25

Just copy and paste the code into a script thats in the HOME server, It will automatically open every port it can find

0 Upvotes

export async function main(ns) {

ns.disableLog("sleep");

ns.disableLog("scan");

ns.disableLog("getServerNumPortsRequired");

const start = "home";

// discover all servers (BFS)

function getAllServers() {

const seen = new Set([start]);

const queue = [start];

while (queue.length > 0) {

const cur = queue.shift();

const neighbors = ns.scan(cur);

for (const n of neighbors) {

if (!seen.has(n)) {

seen.add(n);

queue.push(n);

}

}

}

return Array.from(seen);

}

const servers = getAllServers();

// detect which port openers are available on this machine

const openers = [

{ file: "brutessh.exe", fn: (target) => ns.brutessh(target) },

{ file: "ftpcrack.exe", fn: (target) => ns.ftpcrack(target) },

{ file: "relaysmtp.exe", fn: (target) => ns.relaysmtp(target) },

{ file: "httpworm.exe", fn: (target) => ns.httpworm(target) },

{ file: "sqlinject.exe", fn: (target) => ns.sqlinject(target) },

].filter(o => ns.fileExists(o.file, start));

ns.tprint(`Found ${servers.length} servers. Available port openers on '${start}': ${openers.map(o=>o.file).join(", ") || "none"}`);

for (const s of servers) {

// skip home itself

if (s === start) continue;

try {

const reqPorts = ns.getServerNumPortsRequired(s);

// If we already have root, just report and continue

if (ns.hasRootAccess(s)) {

ns.print(`${s}: already has root access`);

continue;

}

// If we don't have enough port openers to satisfy required ports, we still try whatever we have,

// because some servers may have lower requirements than returned (or you may be running from a different machine later).

if (openers.length === 0) {

ns.print(`${s}: no port opener programs available on ${start}; skipping open attempts.`);

} else {

// run each opener in order (only as many as needed makes sense)

ns.print(`${s}: requires ${reqPorts} ports. Attempting openers (${openers.length})...`);

for (const opener of openers) {

try {

opener.fn(s);

await ns.sleep(30); // tiny pause between openers

ns.print(` -> ran ${opener.file} on ${s}`);

} catch (e) {

ns.print(` -> failed ${opener.file} on ${s}: ${e}`);

}

}

}

// Attempt to nuke (will fail if insufficient ports are open)

if (!ns.hasRootAccess(s)) {

try {

ns.nuke(s);

ns.tprint(`NUKED ${s}`);

} catch (e) {

ns.print(`${s}: nuke failed (likely insufficient open ports).`);

}

}

// final status

if (ns.hasRootAccess(s)) {

ns.print(`${s}: Root access obtained.`);

} else {

ns.print(`${s}: still no root access. Required ports: ${reqPorts}. Available openers: ${openers.length}`);

}

} catch (err) {

ns.print(`Error while processing ${s}: ${err}`);

}

// small delay so the script doesn't spam too rapidly

await ns.sleep(200);

}

ns.tprint("open-ports-all.js finished.");

}


r/Bitburner • • Jun 25 '26

I'm finally almost done with 10! ...right?

0 Upvotes

(Spoilers about ~early-mid game)

***

***

***

***

I'm hoping my folly is almost concluded and I can go get gangs and corps now. I was really greedy for sleeves and grafting, because I hate the augmentation reset, so I jumped right into Bitnode 10 after my first BN1 victory. It has taken a looooong time...but I have purchased every augmentation, I have 3000 hacking, 4 sleeves that will come to every Bitnode with me, hurray...

I read that we could buy up to 8-10 sleeves, but by the explanation in the Covenant window it looks like I have only one more to purchase. For 10 freaking quadrillion!

It took me a whole day to hack the quadrillion I just spent. Just curious, are there known caps on how fast money generation is with different hacking approaches?

My approach is very simplistic, I haven't done batching yet and I just employ a mix of the early combo-hack scripts (fine tuned to be less finicky) and balancing my own blend of constant hack, grow and weaken threads designed to keep the richest servers at 60-100% of max capacity.

I haven't even begun to max out the RAM I have access to, though. I kind of just assumed that because I haven't figured out a way to keep (grow) and (weaken) scripts from "clumping", that if I keep adding hack threads I will inevitably overhack the servers when there is an overly long interval between different (grow)s, and that will reduce my income.

Maybe it doesn't matter. With the amount of RAM I can wield, I could empty ecorp's 1.4 trillion and when the next 5000 threads of grow hits it, it'll go right back up to max.


r/Bitburner • • Dec 18 '21

Hey creator of bitburner, I’m new at this and trying to get my A+ then security + thus… you need to have much more of a learning tutorial or like a Hint button or something to help new people grow there knowledge on this thanks!

0 Upvotes

r/Bitburner • • Nov 25 '24

should be fixed

0 Upvotes
// Function for attacking a target
async function attackTarget(ns, target) {
    ns.brutessh(target);
    ns.nuke(target);
    await ns.weaken(target);
    ns.tprint(`Weaken attempt on ${target} complete`);
    await ns.grow(target);
    ns.tprint(`Grow attempt on ${target} complete`);
    await ns.hack(target);
    ns.tprint(`Hack attempt on ${target} complete`);

    // Add some random fun messages
    const funMessages = [
        `Hacking ${target} like a pro!`,
        `Another one bites the dust!`,
        `You're unstoppable!`,
        `Keep it up, hacker extraordinaire!`,
        `Boom! ${target} didn't see that coming!`
    ];
    const randomMessage = funMessages[Math.floor(Math.random() * funMessages.length)];
    ns.tprint(randomMessage);

    // Cool ASCII art saying "RAWR"
    const asciiArt = `
      ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡤⣖⣤⣶⣿⣿⣿⣿⣿⣭⡶⠶⠒⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠈⠉⠁⠒⠤⠀⡔⠄⠀⠂
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡴⢋⣥⣾⣿⣿⣿⣿⣿⣿⡿⠛⠁⢀⣠⠔⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠛⠓⢤⡀⠀⠀⢀⣀⠈⠂⠉⠀
⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠘⣿⣀⢻⡟⠉⣷⠀⠀⠀⠀⠀⠀⢀⡤⠎⠁⣀⣿⣿⣿⣿⣿⣿⣿⠟⢉⣠⣶⡾⠋⠀⠀⠀⠀⣀⣠⡤⢶⡾⠶⠀⠀⠀⠀⠀⠉⠶⣽⣾⣿⣷⣄⡀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣶⣬⣺⡟⠀⠀⠀⠀⢀⡴⠋⢀⣤⣾⣿⣿⣿⣿⣿⣿⡿⣣⣴⡿⠟⠁⠀⠀⣠⣤⣶⡿⠟⢉⣴⠋⠁⠀⠀⢀⡞⠀⠀⣦⠀⠙⢿⣿⣿⣿⣿⣦
⠀⠀⠀⠀⠀⠰⡄⠀⠀⠀⠀⠀⠀⠀⠈⠁⠀⠀⠀⢀⣴⣯⣶⣿⣿⣿⡿⣽⣿⣿⣿⣿⣿⣿⢿⠋⡀⣀⣤⣾⠿⣿⡿⢋⣴⣾⠟⠀⠀⠀⠀⣴⠋⠀⠀⠀⢹⣦⠠⢪⣻⣿⣿⣿⣿
⠀⠀⠀⠀⠀⠀⠻⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣾⣿⣿⣿⣿⣻⢋⡞⣿⣿⣿⣿⣿⣿⣿⣷⣾⡿⠟⠉⣱⡾⣯⡶⣿⡿⠃⠀⠀⠀⢀⡼⠃⢠⣆⠀⠀⣇⣿⡆⡜⡏⢿⣿⣿⣿
⠀⠀⠀⠀⠀⠀⠀⢷⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣿⣿⣿⣿⡟⠁⠀⠁⣰⣿⣿⣿⣿⣿⣿⡿⠛⠁⠀⢠⣾⣿⠟⢡⣾⣿⠅⠀⠀⠀⣠⡿⠁⣰⣿⢸⢸⡆⣿⣿⣿⣼⣼⡈⣿⣿⣿
⠀⠀⠀⠀⠀⠀⠀⠈⡇⠀⠀⠀⠀⠀⠀⠀⣴⣿⠟⣹⣿⡏⠀⠀⠀⢰⣿⣿⣿⣿⡿⠟⠉⠀⠀⠀⣰⣿⡿⠃⢠⣾⣿⠞⠀⠀⡴⣷⣿⠅⠀⣿⣿⢸⣾⡇⢻⣿⣿⣿⣿⣇⠸⣿⣿
⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀⠀⠀⢰⡿⠁⣸⣿⡟⢠⢀⢠⢀⣿⣿⣿⡿⠋⠀⠀⠀⠀⠀⢰⣿⠟⠀⢠⣿⣿⡟⠀⢀⣼⣿⣿⡿⠀⢰⣿⣿⡟⣿⣇⢸⣿⣿⣿⣿⣿⠀⣿⣿
⠀⠀⠀⠀⢰⡾⢶⣀⣥⣤⡀⠀⠀⠀⢰⡟⠁⣴⣿⣿⣧⡟⣾⢋⣼⣿⡿⠋⠀⠀⠀⠀⠀⠀⢠⣿⠏⠀⠀⣼⣿⣿⠀⢀⣾⣿⣳⡿⠁⠀⡇⣿⣿⣿⣿⣿⡸⣿⣿⣿⣿⣿⡀⢻⡏
⠀⠀⠀⠀⢸⣇⠀⠻⣇⣸⡇⠀⠀⢀⡞⠀⣼⢿⣿⣿⣿⣹⡟⣾⡿⠋⠑⠦⠤⠤⣀⣀⣀⠤⣾⡿⠂⠀⢸⣿⣿⡇⢀⣾⡿⢱⡿⠁⠀⠐⠁⣿⣿⣿⣿⣿⣇⣿⣿⣿⣿⣿⡇⢸⡇
⠀⠀⠀⠀⠀⠙⢷⣴⠟⠋⠀⠀⠀⡾⠀⢰⠃⢈⣿⣿⣿⣿⣿⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⣄⡏⠀⠀⠀⢸⣿⡿⢀⣾⡿⣇⡾⠁⠀⠀⠀⠀⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⡇
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠃⢰⠇⠀⠸⢸⣿⣿⣿⢋⡀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠸⠃⠀⠀⠀⢸⣿⡇⣾⡿⠁⡸⢣⡀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⡇
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢺⣠⠏⢀⡀⠀⣸⣿⣿⡏⢀⣹⣶⣶⣶⣿⣯⡒⢆⡀⠀⠀⠀⠀⠀⠀⢸⣿⢳⡿⠀⢰⠇⠀⠙⢦⡀⢀⠀⠀⠸⣿⣿⣿⡿⣿⣿⣿⣿⣿⡃⣼⠁
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡴⠋⣠⠞⠀⣼⢿⣿⣿⣱⡿⠋⠁⢠⣴⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠸⣿⣿⠃⠀⠀⠀⠀⠀⠀⠙⢮⡄⠀⠀⢻⣿⣿⣿⢿⣿⣿⣿⣿⠀⣿⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡾⣁⠞⠁⢀⣾⣿⢸⣿⡿⡿⠀⠀⣰⣿⣿⣿⣿⡟⢻⡇⠀⠀⠀⠀⠀⠀⠀⢻⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠲⣀⠈⢿⣿⣿⠈⣿⣿⣿⣿⢠⣿⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⠟⠁⢀⣴⣿⣿⣿⣾⣿⣿⠃⠀⢠⡟⠉⠙⠛⢻⣷⣿⡇⠀⠀⠀⠀⠀⠀⠀⠸⠃⠀⠀⠀⠀⢠⣤⣀⠀⡀⠀⠀⠀⠙⠚⢿⣿⣧⠸⣿⣿⣿⣾⣷⢰
⠀⠀⠀⠀⠀⠀⢀⣴⡿⢛⡥⢀⣴⣿⣿⣿⠟⠀⢹⣿⣧⠀⠀⠘⢇⠀⣀⡀⣸⣿⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡠⣿⣿⣷⣿⣤⡀⠀⠀⠀⠈⢿⣿⣆⠸⣿⣿⣿⣿⣾
⠀⠀⠀⢀⣠⠾⠋⢉⣴⣫⣶⣿⣿⡿⠋⠁⠀⠀⠀⣿⣿⡄⠀⠈⢿⡀⠈⠉⢁⡼⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣷⣧⡀⠀⠈⢻⣿⣆⠹⣿⣿⣿⣿
⠀⠀⠀⠈⢱⣄⣾⣯⣿⣿⠟⠋⠀⠀⠀⠀⠀⣠⣼⠃⠙⢷⠀⠐⠚⠿⠖⠚⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⠛⠿⢿⣿⡏⢙⡏⠻⣿⣆⠀⠀⠻⣿⣷⣿⣿⣿⣿
⡀⠀⠀⣠⣿⣿⣿⠟⣹⣵⣤⣤⣤⣤⣤⣤⡼⢿⡏⠀⠀⠀⠙⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⡃⠀⠀⠀⠀⢘⣿⣿⠇⠀⠹⣿⡆⠀⠀⢸⣏⣿⣿⣿⣿
⣡⣴⣾⣻⣿⠟⣩⣾⣿⣿⣿⣿⣿⣿⣿⡏⠀⣸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢉⣳⠀⢤⣀⣠⠞⢉⡿⠀⠀⠀⢹⣷⠀⢀⣾⣾⣿⣿⣿⣿
⣿⣿⢣⣿⣗⣼⣿⣿⡿⠿⢿⡟⠛⠛⠛⣷⠞⠋⠛⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣧⠀⠀⠀⠀⣠⠟⠀⠀⠀⠀⣸⠇⢀⣾⣾⣿⢿⣿⣿⣿
⣿⣿⠠⣿⠿⣿⡁⠈⠀⠀⠀⠑⣄⣠⠞⠁⠀⠀⠀⣀⡹⠶⠤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣒⠖⠋⠁⠀⠀⠀⠀⠞⠁⣰⣿⣿⠟⢡⣿⡿⠋⠀
⡋⠙⣸⠃⠀⠈⠻⣦⠀⢀⡴⣶⠟⠁⠀⠀⣀⡴⠚⠁⠀⠀⠀⠙⣆⠀⠀⠀⢦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣾⡿⢟⡥⣺⣿⠟⠀⠊⠀
⠀⠀⠃⠀⠀⠀⠀⢈⡿⠋⣰⠇⠀⠀⠐⠚⠁⠀⠀⠀⠀⣠⠴⠛⠋⠓⣆⠀⠈⢇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣴⣛⣻⠵⠚⢁⡴⠟⠁⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣰⠏⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⣠⠖⠋⠀⠀⠀⠀⠀⢸⣦⠀⠈⠳⠤⠴⠖⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠊⠉⠉⠀⢀⣤⠶⠭⠄⠀⠀⠀⠀⠀⢀
⠀⠀⠀⠀⠀⡼⠁⠀⠀⠀⠘⢦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⠞⠉⠈⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣶⠋⠁⠀⠀⠀⠀⢀⣀⣀⠐⠃
⠀⠀⠀⠀⡼⠁⠀⠀⠀⠀⠀⡎⠳⣄⠀⠀⠀⠀⠀⠀⠀⠀⠖⠋⠀⢀⠀⠀⢸⠀⠀⠀⡤⠤⠤⣤⡴⠒⠒⠒⢦⡖⠒⠲⠤⣄⣀⡀⠀⣀⣤⣾⡋⠉⠓⠶⠖⠚⠛⠉⠁⠀⠀⠀⢀
⠀⠀⠀⡸⠁⠀⠀⠀⠀⠀⠀⡇⠀⠈⢣⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠿⣦⡞⠀⢠⡞⠀⠀⠀⠈⡇⠀⠀⠀⢸⠇⠀⠀⠀⡇⠈⠉⠙⢿⣿⣿⣿⣆⠀⠀⠀⠀⢠⠀⠀⣠⣀⣠⣿
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡇⠀⡇⠀⢸⡓⢤⡀⠀⠀⠀⠀⠀⠀⢀⡴⢻⠉⢹⣿⠇⠀⠀⠀⠀⡇⠀⠀⠀⡸⠀⠀⠀⢰⡇⠀⠀⠀⢸⣿⣿⡿⠟⠳⠤⠖⠶⠤⣤⣴⣿⣌⢿⣿
⠀⠀⠀⠀⠀⠀⢀⠴⠋⠉⠁⡇⠀⠀⠀⠀⠇⠀⠉⠑⠶⢤⡤⠴⠞⠉⠄⣼⣠⠾⠿⠀⠀⠀⠀⠀⠃⠀⠀⠀⠃⠀⠀⠀⠸⠁⠀⠀⢰⠟⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠦⡹
⠠⠂⠀⠀⠀⠀⢸⠀⠀⠀⠀⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣲⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡏⠘⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠃⠀⠈⠳⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠁⠀⠀⠀⠀⠀⠙⠓⠤⢤⣤⣀⣀⣀⣀⣀⣠⡤⢖⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠀⠀⠀⠀⠀⠀⠀⠀⣀⠀⠀⠀⠀⢀⠀⠀⢀⡔⠉⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
    `;
    ns.tprint(asciiArt);
}

// Main execution function
/** @param {NS} ns **/
export async function main(ns) {
    const targets = ["n00dles", "foodnstuff", "sigma-cosmetics", "joesguns", "hong-fang-tea", "harakiri-sushi"];
    while (true) {
        for (let i = 0; i < 500; i++) {
            for (const target of targets) {
                await attackTarget(ns, target);
            }
            ns.tprint(`Iteration ${i + 1}/500 complete`);
        }
        ns.tprint(`Completed a set of 500 iterations. Starting again...`);
    }
}

r/Bitburner • • Jan 20 '22

Other languages

0 Upvotes

I know bitburner is javascript based but is there a way to use other coding languages with the game?

Or, are there other games similar to bitburner? (any coding language is fine)


r/Bitburner • • Feb 17 '22

Immortal n00dles?!? Semi or Full AUTO Upgrades on Purchased Servers!! !!NEW!! N00dles Death Counter!! n00b friendly NS2 script weighing in at 2.6GB! A Guided "Click-Through" -for the n00b, by the n00b.

0 Upvotes

On my quest to build an acceptable (to me) starting script that includes an auto-upgrading purchased server aspect, I have inadvertently created an immortal n00dles script. i mean.... it gets killed, but has a continuous resurrection. It only hacks n00dles.

It's no 4 billion/second script...yet, but it's a fun start, and wow!! n00dles sure can take a beat-down.

https://github.com/xhowlinx/xHx---bb/blob/main/rammin-n00dles.js

So, i created a timer to display the amount n00dles spends deceased.

Best installed as a fresh game. To run over your existing game, delete your purchased servers before running.

edit: file 'pushhome.js' has to be updated with this line:

var threads = (Math.floor((ns.getServerMaxRam('home')-16)/2.4)-1);

in order to function extremely better. the github file is updated now to reflect this.


r/Bitburner • • Nov 06 '25

cherche aide et/ou script

0 Upvotes

bonjour,

je joue depuis plusieurs année de maniere sporadique a bitburner.

depuis la MAJ la majorité de mes script de fonctionne plus.

je ne suis vraiment pas doué en écriture de script.

je recherche des personnes qui y joue et qui parle Français pour s'entraider.

j'ai fini le bitnote 1 a fond le 2 a 2/3 et je suis sur le 4 déjà fini une fois.

au dela de mes difficulté a faire un script pour manager mon gang je ne trouve aucune info correcte pour l'option singularity qui permet d'acheter les programe sur le darkweb et aussi de ce deplacer dans la ville via un script.

merci pour le temps et l'aide apporté :)


r/Bitburner • • Nov 10 '22

NetscriptJS Script Taking the blue pill

2 Upvotes

What is possible with the self-contained algorithm?

Jan 3, 2023 Update: A bug fix and convert to NS2.

sc4-deploy.js:

/** buildServerInfo()
 * @param {NS} ns NS2 namespace
 * @param {string} scriptName name of script to run on hosts
 * @returns {Array[]} []["scriptName", "serverName", numThreads]
 */
async function buildServerInfo(ns, scriptName) {
  var servers = [];
  var numThreads = 0;
  var scriptRam = ns.getScriptRam(scriptName);
  // Hackable servers
  var servers2Port = ["there-is", "no-shame"];
  var servers3Port = ["in-opting", "for-the"];
  
  // Purchased servers
  var serversPurch = ns.getPurchasedServers();
  for (var i = 0; i < serversPurch.length; i++) {
    var serverName = serversPurch[i];
    var ram = ns.getServerMaxRam(serverName);
    numThreads = Math.floor(ram/scriptRam);
    await ns.scp(scriptName, serverName);
    servers[servers.length] = [scriptName, serverName, numThreads];
  }
  
  // Home
  var homeRam = 256;
  numThreads = Math.floor(homeRam/scriptRam);
  servers[servers.length] = [scriptName, ns.getHostname(), numThreads];
  
  // Servers needing 2 open ports
  if (!ns.fileExists("BruteSSH.exe", "home") || 
    !ns.fileExists("FTPCrack.exe", "home")) { 
    return servers;
  }
  /*for (var i = 0; i < servers2Port.length; i++) {
    var serverName = servers2Port[i];
    var ram = ns.getServerMaxRam(serverName);
    if (ns.getHackingLevel() < ns.getServerRequiredHackingLevel(serverName)) {
      ns.tprint(serverName + " required hacking level too high.");
    } else {
      numThreads = Math.floor(ram/scriptRam);
      await ns.scp(scriptName, serverName);
      ns.brutessh(serverName);
      ns.ftpcrack(serverName);
      ns.nuke(serverName);
      servers[servers.length] = [scriptName, serverName, numThreads];
    }
  }*/
  
  // Servers needing 3 open ports
  if (!ns.fileExists("relaySMTP.exe", "home")) {
    return servers;
  }
  for (var i = 0; i < servers3Port.length; i++) {
    var serverName = servers3Port[i];
    var ram = ns.getServerMaxRam(serverName);
    if (ns.getHackingLevel() < ns.getServerRequiredHackingLevel(serverName)) {
      ns.tprint(serverName + " required hacking level too high.");
    } else {
      numThreads = Math.floor(ram/scriptRam);
      await ns.scp(scriptName, serverName);
      ns.brutessh(serverName);
      ns.ftpcrack(serverName);
      ns.relaysmtp(serverName);
      ns.nuke(serverName);
      servers[servers.length] = [scriptName, serverName, numThreads];
    }
  }
  return servers;
}

/** hostDeploy()
 * @param {NS} ns NS2 namespace
 * @param {Array[]} servers []["scriptName", "serverName", numThreads]
 * @param {string} target server to pull money from
 * @returns {Array[]} []["scriptName", "serverName", moneyAvail, secLevel,
 *       threshMoney, threshSec, chanceHack, multWeaken, multGrow,
 *       timeHack, numThreads, servers.length, "target", startTime]
 */
async function hostDeploy(ns, servers, target) {
  var retServers = [];
    // chance to call hack() (0, 1]. Adjust this by small amounts 
    // (ex. +-0.025) so that a target with money available above the 
    // threshold has money drawn down 40% on average.
  var chanceHack = ns.getServerRequiredHackingLevel(target)/
            ns.getHackingLevel()-0.125;
  var moneyAvail = ns.getServerMoneyAvailable(target);
  var secLevel = ns.getServerSecurityLevel(target);
  var timeHack = ns.getHackTime(target);
  var multWeaken = ns.getWeakenTime(target)/timeHack;
  var multGrow = ns.getGrowTime(target)/timeHack;
    // money threshold
  var threshMoney = ns.getServerMaxMoney(target)*0.75;
    // security threshold
  var threshSec = ns.getServerMinSecurityLevel(target)+3;

  // Deploy on the hosts
  for (var i = 0; i < servers.length; i++) {
    var scriptName = servers[i][0];
    var serverName = servers[i][1];
    var numThreads = servers[i][2];
    ns.exec(scriptName, serverName, numThreads, moneyAvail, secLevel,
        threshMoney, threshSec, chanceHack, multWeaken, multGrow,
        timeHack, numThreads, servers.length, target);
    retServers[retServers.length] = [scriptName, serverName,
        moneyAvail, secLevel, threshMoney, threshSec, chanceHack,
        multWeaken, multGrow, timeHack, numThreads, servers.length,
        target, Date.now()];
    await ns.sleep(250);
  }
  return retServers;
}

/** getTotalIncome()
 * @param {NS} ns NS2 namespace
 * @param {Array[]} servers []["scriptName", "serverName", moneyAvail, 
 *      secLevel, threshMoney, threshSec, chanceHack, multWeaken, 
 *      multGrow, timeHack, numThreads, servers.length, "target", 
 *      startTime]
 * @returns {number} total income ($) for given servers
 */
function getTotalIncome(ns, servers) {
  var totalIncome = 0;
  for (var i = 0; i < servers.length; i++) {
    var income = ns.getScriptIncome(servers[i][0], servers[i][1],
          servers[i][2], servers[i][3], servers[i][4], servers[i][5],
          servers[i][6], servers[i][7], servers[i][8], servers[i][9],
          servers[i][10], servers[i][11], servers[i][12]);
    var startTime = servers[i][13];
    totalIncome = totalIncome+income*(Date.now()-startTime)/1000;
  }
  return totalIncome;
}

/** @param {NS} ns NS2 namespace */
export async function main(ns) {
  var target = "blue-pill";   // server to pull money from
  var scriptName = "sc4-host.js"; // name of script to run on hosts

  if (ns.scriptRunning(scriptName, ns.getHostname())) {
    ns.tprint("Host script already running. Exiting.");
    ns.exit();
  }
  // Get root access on the target
  if (ns.fileExists("BruteSSH.exe", "home")) { ns.brutessh(target); }
  if (ns.fileExists("FTPCrack.exe", "home")) { ns.ftpcrack(target); }
  if (ns.fileExists("relaySMTP.exe", "home")) { ns.relaysmtp(target); }
  ns.nuke(target);
  // Build array of server information
  var servers = await buildServerInfo(ns, scriptName);
  ns.tprint("Deploying on " + servers.length + " servers.");
  // Deploy on servers
  servers = await hostDeploy(ns, servers, target);
  // Sleep for 30 minutes, then print total $ produced
  await ns.sleep(30*60*1000);
  ns.tprint("Total produced on all servers: " +
      ns.nFormat(getTotalIncome(ns, servers), "$0.000a"));
}

sc4-host.js:

/** @param {NS} ns NS2 namespace */
export async function main(ns) {
  // Takes 11 arguments:
  //  - money available
  //  - security level
  //  - money threshold
  //  - security threshold
  //  - chance to call hack() (0, 1]
  //  - weaken multiplier
  //  - grow multiplier
  //  - hack time
  //  - number of threads
  //  - number of hosts
  //  - the target server
  if (ns.args.length < 11) { ns.exit(); }
  var moneyAvail = ns.args[0];
  var secLevel = ns.args[1];
  var threshMoney = ns.args[2];
  var threshSec = ns.args[3];
  var chanceHack = ns.args[4];
  var multWeaken = ns.args[5];
  var multGrow = ns.args[6];
  var timeHack = ns.args[7];
  var numThreads = ns.args[8];
  var numHosts = ns.args[9];
  var target = ns.args[10];
  var timeWeaken = timeHack*multWeaken;
  var timeGrow = timeHack*multGrow;
  // The hack time and security level are linear, so we need two 
  // points on the line. We already have the first point.
  var prevTimeHack = timeHack;
  var prevSecLevel = secLevel;
  var slope = 0, yIntercept;
  // Is the money available below the threshold?
  var cntGrow = 0;
  if (moneyAvail < threshMoney) {
    if (moneyAvail < threshMoney*0.4) {   // very low
      cntGrow = 2;
    } else {   // low
      cntGrow = 1;
    }
  }
  
  // Is the target prepped?
  if ((secLevel <= threshSec) && (moneyAvail >= threshMoney)) {
    // Start approximately 2 of 3 threads with short scatter. 
    // Start the rest after the first complete their hack() calls.
    var scatter = Math.random()*numHosts*250;
    if (Math.random() < 0.67) {
      await ns.sleep(Math.ceil(scatter));
    } else {
      await ns.sleep(Math.ceil(timeHack+numHosts*250+scatter));
      moneyAvail = ns.getServerMoneyAvailable(target);
      secLevel = ns.getServerSecurityLevel(target);
    }
  } else {
    // Start threads with longer scatter.
    var scatter = Math.random()*numHosts*750;
    await ns.sleep(Math.ceil(scatter));
  }
  
  while (true) {
    var bSecHigh = secLevel > threshSec;
    var bMoneyLow = moneyAvail < threshMoney;
    if (cntGrow == 0 && (moneyAvail < threshMoney*0.4)) {
      cntGrow = 2;
    }
  
    // Assign three jobs. Jobs are 0:weaken, 1:grow, 2:hack.
    var jobs = null;
    if (secLevel > (threshSec+5)) {
      // Security level is very high, weaken twice.
      if (bMoneyLow) {
        jobs = [0, 0, 1];
      } else {
        jobs = [0, 0, 2];
      }
    } else if (cntGrow > 0) {
      // Use more grow() calls.
      if (bSecHigh && bMoneyLow) {
        jobs = [0, 1, 1];
      } else if (!bSecHigh && bMoneyLow) {
        if (moneyAvail < threshMoney*0.4) {
          jobs = [1, 1, 0];
        } else {
          jobs = [1, 1, 2];
        }
      } else if (bSecHigh && !bMoneyLow) {
        jobs = [0, 2, 1];
      } else {
        jobs = [2, 1, 0];
      }
      cntGrow--;
    } else {
      // Use more hack() calls.
      if (bSecHigh && bMoneyLow) {
        jobs = [0, 1, 2];
      } else if (!bSecHigh && bMoneyLow) {
        jobs = [1, 2, 1];
      } else if (bSecHigh && !bMoneyLow) {
        jobs = [0, 2, 1];
      } else {
        jobs = [2, 1, 0];
      }
    }
  
    // Perform the jobs, sometimes skipping them. Jobs after 
    // the first job have decreasing chance to run. 
    for (var i = 0; i < jobs.length; i++) {
      var rand = Math.random();
      if (jobs[i] == 0) {
        if (rand < 0.93*(1-i*0.02)) {
          await ns.weaken(target);
        }
        await ns.sleep(Math.ceil(numThreads*timeWeaken/10000));
      } else if (jobs[i] == 1) {
        if (rand < 0.93*(1-i*0.02)) {
          await ns.grow(target);
        }
        await ns.sleep(Math.ceil(numThreads*timeGrow/10000));
      } else {
        if (rand < chanceHack*(1-i*0.02)) {  // hack
          await ns.hack(target);
          await ns.sleep(Math.ceil(numThreads*timeHack/10000));
        } else {  // sleep for a while plus short scatter
          await ns.sleep(Math.ceil(
              timeHack/5+Math.random()*numThreads*15));
        }
      }
    }
  
    // Get target values.
    moneyAvail = ns.getServerMoneyAvailable(target);
    if (slope == 0) {
      timeHack = ns.getHackTime(target);
      secLevel = ns.getServerSecurityLevel(target);
      if (prevSecLevel != secLevel) {
        // This is the second point on the line.
        slope = (timeHack-prevTimeHack)/(secLevel-prevSecLevel);
        yIntercept = prevTimeHack-slope*prevSecLevel;
      }
    } else {
      secLevel = ns.getServerSecurityLevel(target);
      timeHack = slope*secLevel+yIntercept;
    }
    timeWeaken = timeHack*multWeaken;
    timeGrow = timeHack*multGrow;
  }
}

r/Bitburner • • Jun 04 '22

[rant] BN8: just. f*cking. sucks.

6 Upvotes

Normally I'm not the guy to flip out, but BN8 is just ridiculous!

I've opened a thread to gather input and tried all the advice (aside from that really funny jerk who said "buy all, sell at profit"... f*ck you!). I've thought about things hard. I've written lots and lots of different scripts to output logs, gathered hours of stats (which was completely worthless btw), even graphed that sh*t. Read that (interesting but useless) thread from some guy who threw a whole bunch of machine learning at the stock market - even that was no good!

I normally refuse to cheat (and copy+pasting other people's scripts, using save/load or abusing the casino is nothing else IMHO) but I'm pretty much out of ideas.

I wouldn't be so p*ssed if there was any other way to at least get some progress: like in all other BNs - clear corporations without corps? sure, takes some time, but works. clear gangs without gangs? easy. Sleeves? Nice bonus. Hacknet? Just ignore... You get my point. But since there's no way to get any money in BN8 I guess I'll just quit.

P.S.: I managed to double my starting money. By manually buying stuff, sitting there, watching losses go worse and worse, and after an hour or two getting +2...4%. This is not the way a coding game should work.

edit Thanks to all who endured my grumpiness and still gave me advice - I've found my (biggest) error: Do not trade more than 10k shares of one single company at once to reduce (eliminate?) the effect your long/short have on stock trends! I'm slowly making some progress at last!


r/Bitburner • • Sep 08 '26

Darknet automation

0 Upvotes

Hi everyone, can anyone share a fully automated script for darknet? I love the game, but dont honestly want to learn JS or any other programming language.

Thanks in advance!


r/Bitburner • • Jul 11 '26

NetscriptJS Script Steal $$ with the help of Loop algorithm

0 Upvotes

It's easy, just set homeRam to the amount of RAM to use on the host.

lo-deploy.js:

/** buildServerInfo()
 * @ param {NS} ns NS2 namespace
 * @ param {string[]} callScript ["weakenScript", "growScript", "hackScript"]
 * @ param {string} target server to pull money from
 * @ returns {Array[]} []["serverName", numWeaken, numGrow, numHack]
 */
function buildServerInfo(ns, callScript, target) {
  let servers = [];
  let callRam = [ns.getScriptRam(callScript[0]), ns.getScriptRam(callScript[1]), ns.getScriptRam(callScript[2])];
    // Purchased servers
  let serversPurch = ns.cloud.getServerNames();
  for (let i = 0; i < serversPurch.length; i++) {
    let serverName = serversPurch[i];
    let ram = ns.getServerMaxRam(serverName);
    if (ram < 64) {
      ns.tprint(serverName + " RAM too low, need 64 GB minimum.");
    } else {
      servers[servers.length] = [serverName, ram];
    }
  }
  
    // Home
  let homeRam = 2048;
  servers[servers.length] = [ns.getHostname(), homeRam];
  
  // Reserve callRam[0] from the last server
  servers[servers.length - 1][1] -= callRam[0];
  // Calculate ratio of weaken, grow, and hack threads
  let ratio = getRatio(ns, callRam, target);
  // Calculate total RAM on all servers
  let totalRam = 0;
  for (let i = 0; i < servers.length; i++) { totalRam += servers[i][1]; }
  // Convert ratio to (part of RAM) instead of (amount of RAM)
  if (ratio[3] >= totalRam) { ratio[3] = 1; }
  else { ratio[3] /= totalRam; }
  // Build a new list of servers []["serverName", numWeaken, numGrow, numHack]
  let retServers = [];
  let numHack = 0;  // total of hack threads
  for (let i = 0; i < servers.length; i++) {
    let assign = assignThreads(servers[i][1], callRam, ratio, servers.length);
    ns.scp(callScript[0], servers[i][0]);
    ns.scp(callScript[1], servers[i][0]);
    ns.scp(callScript[2], servers[i][0]);
    retServers[retServers.length] = [servers[i][0], assign[0], assign[1], assign[2]];
    numHack += assign[2];
  }
  // If we assigned no hack threads, add one to the last server
  if (numHack == 0) { retServers[retServers.length - 1][3]++; }
  else { retServers[retServers.length - 1][2]++; }
  return retServers;
}

/** loopDeploy()
 * @ param {NS} ns NS2 namespace
 * @ param {number} delay delay before start threads (ms)
 * @ param {number} duration time needed to start threads (ms)
 * @ param {number} interval time between start of threads (ms)
 * @ param {string[]} callScript ["weakenScript", "growScript", "hackScript"]
 * @ param {number} mode modes are 0:weaken, 1:grow, 2:hack
 * @ param {Array[]} servers []["serverName", numWeaken, numGrow, numHack]
 * @ param {string} target server to pull money from
 * @ returns {Array[]} []["hackScript", "serverName", delay, duration, interval, numHack, "target", startTime]
 *        or empty array if mode is weaken or grow
 */
function loopDeploy(ns, delay, duration, interval, callScript, mode, servers, target) {
  let retServers = [];
  for (let i = 0; i < servers.length; i++) {
    // Deploy the weaken, grow, or hack loop
    if (servers[i][mode + 1] > 0) {
      ns.exec(callScript[mode], servers[i][0], servers[i][mode + 1], delay, duration, interval, servers[i][mode + 1], target);
      if (mode == 2) {
        retServers[retServers.length] = [callScript[mode], servers[i][0], delay, duration, interval, servers[i][mode + 1], target, Date.now()];
      }
    }
  }
  return retServers;
}

/** assignThreads()
 * @ param {number} ram amount of RAM on host (GB)
 * @ param {number[]} callRam [weakenRam, growRam, hackRam]
 * @ param {number[]} ratio [partWeaken, partGrow, partHack, partRam]
 *    where partWeaken + partGrow + partHack = 1 and partRam is the part of RAM to use
 * @ param {number} numHosts number of hosts
 * @ returns {number[]} [numWeaken, numGrow, numHack]
 */
function assignThreads(ram, callRam, ratio, numHosts) {
  let partRam = /* 1.4 * */ ram * ratio[3];
  // First pass of assigning threads
  let numWeaken = Math.floor(ratio[0] * partRam / callRam[0]);
  let numGrow = Math.floor(ratio[1] * partRam / callRam[1]);
  let numHack = Math.floor(ratio[2] * partRam / callRam[2]);
  let remainder = partRam - numWeaken * callRam[0] - numGrow * callRam[1] - numHack * callRam[2];
  if (remainder >= callRam[2] * numHosts) {
    // Second pass of assigning threads
    numWeaken += Math.floor(ratio[0] * remainder / callRam[0]);
    numGrow += Math.floor(ratio[1] * remainder / callRam[1]);
    numHack += Math.floor(ratio[2] * remainder / callRam[2]);
    remainder = partRam - numWeaken * callRam[0] - numGrow * callRam[1] - numHack * callRam[2];
    if (remainder >= callRam[1]) {  // anything left put to grow
      numGrow += Math.floor(remainder / callRam[1]);
    }
  }
  return [numWeaken, numGrow, numHack];
}

/** getRatio()
 * @ param {NS} ns NS2 namespace
 * @ param {number[]} callRam [weakenRam, growRam, hackRam]
 * @ param {string} target server to get values from
 * @ returns {number[]} [partWeaken, partGrow, partHack, amountRam]
 *    where partWeaken + partGrow + partHack = 1 and amountRam is the amount of RAM to use (GB)
 */
function getRatio(ns, callRam, target) {
  let partPerHack, mockTarget, bDefault = false, partWeaken, partGrow, partHack, ppgNorm = 1, amountRam;
  let moneyAvail = ns.getServerMoneyAvailable(target);
  let moneyMax = ns.getServerMaxMoney(target);
  let secLevelMin = ns.getServerMinSecurityLevel(target);
  let secLevel = ns.getServerSecurityLevel(target);
  let secIncrease = secLevel - secLevelMin;
  let bFormulas = ns.fileExists("Formulas.exe", "home");
  if (bFormulas) { ns.tprint("Using Formulas.exe."); }
  // get part per hack
  if (bFormulas) {
    mockTarget = ns.getServer(target);
    mockTarget.hackDifficulty = mockTarget.minDifficulty + 0.5;
    partPerHack = ns.formulas.hacking.hackPercent(mockTarget, ns.getPlayer());
  } else {
    let norm = 1;
    partPerHack = ns.hackAnalyze(target);
    // normalize part per hack
    if (secIncrease > 4.75) { ns.tprint("Security level is too high. Returning default ratio."); bDefault = true; }
    else if (secIncrease > 3.75 && secIncrease <= 4.75) { norm += 0.0545; }
    else if (secIncrease > 2.75 && secIncrease <= 3.75) { norm += 0.0394; }
    else if (secIncrease > 1.75 && secIncrease <= 2.75) { norm += 0.0247; }
    else if (secIncrease > 0.75 && secIncrease <= 1.75) { norm += 0.0105; }
    else if (secIncrease >= 0 && secIncrease <= 0.25) { norm -= 0.0068; }
    partPerHack *= norm;
  }

  if (!bFormulas && !bDefault) {
    if (moneyAvail < 0.7 * moneyMax) {
      ns.tprint("Money available is too low. Returning default ratio."); bDefault = true;
    } else {
      let bSecHigh = secLevel > secLevelMin + 3;
      let bMoneyLow = moneyAvail < 0.85 * moneyMax;
      // get multiplier to normalize part per grow
      if (bSecHigh && !bMoneyLow) {
        if (moneyAvail > 0.95 * moneyMax) { ppgNorm += 0.154; }
        else if (moneyAvail > 0.9 * moneyMax && moneyAvail <= 0.95 * moneyMax) { ppgNorm += 0.1; }
        else { ppgNorm += 0.118; }
      } else if (!bSecHigh && bMoneyLow) {
        if (moneyAvail >= 0.8 * moneyMax) { ppgNorm += 0.037; }
        else if (moneyAvail >= 0.75 * moneyMax && moneyAvail < 0.8 * moneyMax) { ppgNorm += 0.07; }
        else { ppgNorm += 0.104; }
      } else if (bSecHigh && bMoneyLow) {
        if (moneyAvail >= 0.8 * moneyMax) { ppgNorm += 0.153; }
        else if (moneyAvail >= 0.75 * moneyMax && moneyAvail < 0.8 * moneyMax) { ppgNorm += 0.185; }
        else { ppgNorm += 0.226; }
      }
    }
  }

  if (!bDefault) {
    let partToHack = 0.2, numGrow;
    if (!bFormulas) {
        // hacking skill multiplier
      let skillM = (ns.getServerRequiredHackingLevel(target) / ns.getHackingLevel() - 1 / 3) * 0.67;
      partToHack *= (skillM + 1);
    }
    // calculate number of hack calls
    let numHack = Math.round(partToHack / (partPerHack + Number.EPSILON));
    if (numHack == 0) { numHack = 1; }
    partToHack = numHack * partPerHack;
    // get amount of RAM to use for hack
    let amtHack = numHack * callRam[2];
    // calculate number of grow calls
    if (bFormulas) {
      mockTarget.moneyAvailable = (1 - partToHack) * moneyMax;
      numGrow = 3.2 * ns.formulas.hacking.growThreads(mockTarget, ns.getPlayer(), moneyMax);
    } else {
      numGrow = 3.2 * ns.growthAnalyze(target, 1 / ppgNorm / (1 - partToHack));
    }
    // get amount of RAM to use for grow
    let amtGrow = numGrow * callRam[1];
    // calculate number of weaken calls
    let numWeaken = 4 * (numGrow / 10 + numHack / 6.25);
    // get amount of RAM to use for weaken
    let amtWeaken = numWeaken * callRam[0];
    // get amount of RAM to use
    amountRam = amtWeaken + amtGrow + amtHack;
    // get parts of RAM to use
    partHack = amtHack / amountRam;
    partGrow = amtGrow / amountRam;
  } else {  // default ratio
    amountRam = 736; partHack = 0.0185; partGrow = 0.692;
  }
  partWeaken = 1 - partGrow - partHack;
  ns.tprint("Ratio  w=" + ns.format.percent(partWeaken) + "  g=" + ns.format.percent(partGrow) +
        "  h=" + ns.format.percent(partHack) + "  amt=" + ns.format.ram(amountRam));

  return [partWeaken, partGrow, partHack, amountRam];
}

/** getTotalIncome()
 * @ param {NS} ns NS2 namespace
 * @ param {Array[]} servers []["hackScript", "serverName", delay, duration, interval, numHack, "target", startTime]
 * @ returns {number[]} [total income ($), total income ($/sec)] for given servers
 */
function getTotalIncome(ns, servers) {
  let totalIncome = 0, totalPerSecond = 0;
  for (let i = 0; i < servers.length; i++) {
    let income = ns.getScriptIncome(servers[i][0], servers[i][1], servers[i][2], servers[i][3], servers[i][4], servers[i][5], servers[i][6]);
    totalPerSecond += income;
    totalIncome += income * (Date.now() - servers[i][7]) / 1000;
  }
  return [totalIncome, totalPerSecond];
}

/**
 * @ param {NS} ns NS2 namespace
 * @ version 1.0
 */
export async function main(ns) {
  if (ns.args.length < 1) {
    ns.tprint("Usage: " + ns.getScriptName() + " <target>");
    ns.exit();
  }
  let target = ns.args[0];  // server to pull money from
  let callScript = ["lo-weaken.js", "lo-grow.js", "lo-hack.js"];
  // Check for running script
  if (ns.scriptRunning(callScript[0], ns.getHostname())) {
    ns.tprint("Host script already running. Exiting.");
    ns.exit();
  }
  // Get root access on the target
  if (ns.fileExists("BruteSSH.exe", "home")) { ns.brutessh(target); }
  if (ns.fileExists("FTPCrack.exe", "home")) { ns.ftpcrack(target); }
  if (ns.fileExists("relaySMTP.exe", "home")) { ns.relaysmtp(target); }
  if (ns.fileExists("HTTPWorm.exe", "home")) { ns.httpworm(target); }
  if (ns.fileExists("SQLInject.exe", "home")) { ns.sqlinject(target); }
  ns.nuke(target);
  
  let threshMoney = ns.getServerMaxMoney(target) * 0.9;  // money threshold
  let threshSec = ns.getServerMinSecurityLevel(target) + 1.5;  // security threshold
  let secLevel = ns.getServerSecurityLevel(target);
  let moneyAvail = ns.getServerMoneyAvailable(target);
  let bSecHigh = secLevel > threshSec;
  let bMoneyLow = moneyAvail < threshMoney;
  // Build array of server information
  let servers = buildServerInfo(ns, callScript, target);
  ns.tprint("Deploying on " + servers.length + " servers.");
  
  let timeHack = ns.getHackTime(target);
    // Deploy weaken loops
  loopDeploy(ns, 200, timeHack * 4, timeHack / 5, callScript, 0, servers, target);
  if (!bSecHigh && !bMoneyLow) {  // fastest deployment
    // Deploy grow loops
    loopDeploy(ns, 100, timeHack * 3.2, timeHack / 5, callScript, 1, servers, target);
    // Deploy hack loops
    servers = loopDeploy(ns, timeHack * 2.2, timeHack, timeHack / 5, callScript, 2, servers, target);
  } else if (!bSecHigh && bMoneyLow) {  // moneyAvail is low, hack later
    // Deploy grow loops
    loopDeploy(ns, 100, timeHack * 3.2, timeHack / 5, callScript, 1, servers, target);
    // Deploy hack loops
    servers = loopDeploy(ns, timeHack * 3.2, timeHack, timeHack / 5, callScript, 2, servers, target);
  } else if (bSecHigh && !bMoneyLow) {  // secLevel is high, grow later
    // Deploy grow loops
    loopDeploy(ns, 100 + timeHack * 1.8, timeHack * 3.2, timeHack / 5, callScript, 1, servers, target);
    // Deploy hack loops
    servers = loopDeploy(ns, timeHack * 5, timeHack, timeHack / 5, callScript, 2, servers, target);
  } else {  // grow and hack later
    // Deploy grow loops
    loopDeploy(ns, 100 + timeHack * 1.8, timeHack * 3.2, timeHack / 5, callScript, 1, servers, target);
    // Deploy hack loops
    servers = loopDeploy(ns, timeHack * 6, timeHack, timeHack / 5, callScript, 2, servers, target);
  }
  
  // Display income every 5 minutes
  while (true) {
    await ns.sleep(5 * 60 * 1000);
    let income = getTotalIncome(ns, servers);
    ns.tprint("Total: $" + ns.format.number(income[0], 3, 1000, true) +
                "  Per second: $" + ns.format.number(income[1], 3, 1000, true));
  }
}

lo-weaken.js (or lo-grow.js, or lo-hack.js):

/**
 * @ param {NS} ns NS2 namespace
 * @ version 1.0
 */
export async function main(ns) {
  // Takes 5 arguments:
  //  - delay (ms)
  //  - duration (ms)
  //  - interval (ms)
  //  - number of threads
  //  - the target server
  if (ns.args.length < 5) { ns.exit(); }
  let delay = ns.args[0];
  let duration = ns.args[1];
  let interval = ns.args[2];
  let numThreads = ns.args[3];
  let target = ns.args[4];
  // start threads between intervals
  let offsets = Math.round(duration / interval);
  let offset = Math.floor(Math.random() * offsets);
  let odelay = offset * interval;
  await ns.sleep(delay + odelay + Math.random() * numThreads / offsets);
  while(true) {
    await ns.weaken(target);  // or grow, or hack
    await ns.sleep(numThreads / offsets);
  }
}

r/Bitburner • • Jun 12 '25

Question/Troubleshooting - Open Barely make money from scripts

Thumbnail
gallery
7 Upvotes

Let me preface this with the fact that I am very new to this game but I have been trying to make a system that automatically chooses the best targets and adds smaller multithreaded worker scripts onto every server I have access to but the big problem is I make next to no money doing hacking scripts and any money I do make is blown out of the water by just buying a load of hacknet nodes and letting them do their thing, I would just like to know if this is intentional and that hacking picks up later on or if it is always more worthwhile to do something instead of hacking pictures of my Launcher and Worker Scripts below 👇


r/Bitburner • • May 03 '23

Help with tutorial

Post image
4 Upvotes

r/Bitburner • • Feb 20 '24

Help, scripts not copying to server

Thumbnail
gallery
3 Upvotes

So, im basically just following a tutorial on YouTube, I don't know anything about coding whatsoever. I'm pretty sure everything else is working properly (I think). The highlighted bit of code is SUPPOSED to be copying my hack, grow, weaken scripts over to the server, however when I type ls on foodnstuff they are not there. Does anyone know what I am doing wrong?