Inspired by this basic auto farm, automate all servers with improved performances.
알아채다
메모: Require at least 8.1G on your ‘home’ server.
Create a ‘runner.js’ file on your home server, paste the content below on it then run it.
nano runner.js
기본적으로, this script will not kill all other services running on each server. You can enforce it by running
run runner.js --kill
This script will use all your personally owned servers. The more you have, the more it’ll be efficient.
스크립트
/** @param {NS} ns **/ 비동기 함수 메인 내보내기(ns) { ns.disableLog('모두'); ns.enableLog('print'); var options = ns.flags([ ['kill', 거짓], ['hack', 거짓], ['grow', 거짓], ['weaken', 거짓], ['waitTime', 10], ['help', 거짓] ]); 만약에 (옵션['help']) { ns.tail(); ns.print(`Auto-script, 옵션: * --죽이다: Force kill every other process on every servers * --hack some-script.js: Replace hack script with some-script.js one * --grow some-script.js: Replace grow script with some-script.js one * --weaken some-script.js: Replace weaken script with some-script.js one * --waitTime 10: Wait time between two servers in ms, must be higher than 1 * --돕다: show this message `); 반품; } // Creating scripts var hack = options['hack'] || '/temp/hack.js', grow = options['grow'] || '/temp/grow.js', weaken = options['weaken'] || '/temp/weaken.js'; 만약에 (!옵션['hack']) { await ns.write(hack, ` /** @param {NS} ns **/ 비동기 함수 메인 내보내기(ns) { await ns.hack(ns.args[0]); } `, 'w'); } 만약에 (!옵션['grow']) { await ns.write(grow, ` /** @param {NS} ns **/ 비동기 함수 메인 내보내기(ns) { await ns.grow(ns.args[0]); } `, 'w'); } 만약에 (!옵션['weaken']) { await ns.write(weaken, ` /** @param {NS} ns **/ 비동기 함수 메인 내보내기(ns) { await ns.weaken(ns.args[0]); } `, 'w'); } // Divs variables declarations var serverList = ns.scan('home'), serverCount = [serverList.length, 0], softwares = [0, 0, 0, 0, 0, 0], softwaresCount = 0, scanLevel = 2, index = 0, notProxyList = [], proxyList = ['home'], hackables = [], growables = [], weakenables = [], linked, 목표, proxyTarget, depth = 0, checked = 0, hackType; // Checking softwares if (ns.FileExists('brutessh.exe')) { softwares[0] = 1; softwaresCount++; }; 만약에 (ns.FileExists('ftpcrack.exe')) { softwares[1] = 1; softwaresCount++; }; 만약에 (ns.FileExists('Relaysmtp.exe')) { softwares[2] = 1; softwaresCount++; }; 만약에 (ns.FileExists('httpworm.exe')) { softwares[3] = 1; softwaresCount++; }; 만약에 (ns.FileExists('sqlinject.exe')) { softwares[4] = 1; softwaresCount++; }; 만약에 (ns.FileExists('DeepscanV1.exe')) { scanLevel += 2; }; 만약에 (ns.FileExists('DeepscanV2.exe')) { scanLevel += 5; }; ns.print('/---/ SEARCHING \\---\\\n-- Default --\n > ' + serverList.join('\n > ') + '\n>- Scan Limit: L' + [scanLevel + 1] + ' -<'); ~하는 동안 (index <= serverCount[깊이] - 1 && 깊이 < scanLevel) { linked = ns.scan(serverList[확인됨]); checked++; ~을 위한 (let index = 0; index <= linked.length - 1; index++) { target = linked[index]; 만약에 (목표 != 'home' && !ServerList.includes(목표)) { serverList.push(목표); ns.print('L' + [깊이 + 2] + ' > ' + 목표); serverCount[깊이 + 1]++; } } 만약에 (index == serverCount[깊이] - 1) { index = 0; depth++; serverCount.push(0); } 또 다른 { index++; }; } ns.print('/-------/ CHECKING \\-------\\'); ~을 위한 (let index = 0; index <= serverList.length - 1; index++) { target = serverList[index]; 만약에 (ns.getPurchasedServers().includes(목표)) { await ns.scp([hack, grow, weaken], 'home', 목표); 만약에 (옵션['kill']) { ns.killall(목표); } proxyList.push(목표); ns.print(' >>> PROXY ' + 목표); } else if (ns.getServernumportsRequired(목표) > softwaresCount) { ns.print(' >엑스< SOFTWARE ' + 목표); } else if (ns.getServerMaxRam(목표) < 2) { ns.print(' >엑스< NO RAM ' + 목표); } else if (ns.gethackinglevel() < ns.getServerRequiredHackinglevel(목표)) { ns.print(' >엑스< SKILL ' + 목표); } 또 다른 { 만약에 (softwares[0]) { Ns.Brutessh(목표); }; 만약에 (softwares[1]) { ns.ftpcrack(목표); }; 만약에 (softwares[2]) { ns.relaysmtp(목표); }; 만약에 (softwares[3]) { ns.httpworm(목표); }; 만약에 (softwares[4]) { ns.sqlinject(목표); }; ns.wull(목표); await ns.scp([hack, grow, weaken], 'home', 목표); 만약에 (옵션['kill']) { ns.killall(목표); } 만약에 (ns.getServerMoneyAvailable(목표) == 0) { ns.print(' >엑스< NO MONEY ' + 목표); proxyList.push(목표); ns.print(' >>> PROXY ' + 목표); } 또 다른 { notProxyList.push(목표); ns.print(' >>> VALID ' + 목표); } } } 만약에 (notProxyList.length > 0) { ns.print('/------------/ HACKING \\------------\\'); ~하는 동안 (진실) { hackables = []; growables = []; weakenables = []; ~을 위한 (target of notProxyList) { // Priority for targets: weaken, then grow, then hack if (ns.getServerSecurityLevel(목표) > ns.getServerMinSecurityLevel(목표) + 5) { hackType = weaken; weakenables.push(목표); } else if (ns.getServerMoneyAvailable(목표) < ns.getServerMaxMoney(목표) * 0.80) { hackType = grow; growables.push(목표); } 또 다른 { hackType = hack; hackables.push(목표); } 만약에 ((ns.getServerMaxRam(목표) - ns.getServerUsedRam(목표)) > ns.getScriptRam(hackType)) { ns.exec(hackType, 목표, Math.floor((ns.getServerMaxRam(목표) - ns.getServerUsedRam(목표)) / ns.getScriptRam(hackType)), 목표); ns.print('|||||||||| ' + hackType + ' --> ' + 목표 + ' ||||||||||'); } } ~을 위한 (target of proxyList) { // Priority for proxies: hack, then grow, then weaken if (hackables.length > 0) { proxyTarget = hackables[Math.floor(Math.random() * hackables.length)]; hackType = hack; } else if (growables.length > 0) { proxyTarget = growables[Math.floor(Math.random() * growables.length)]; hackType = grow; } else if (weakenables.length > 0) { proxyTarget = weakenables[Math.floor(Math.random() * weakenables.length)]; hackType = weaken; } 만약에 ((ns.getServerMaxRam(목표) - ns.getServerUsedRam(목표)) > ns.getScriptRam(hackType)) { ns.exec(hackType, 목표, Math.floor((ns.getServerMaxRam(목표) - ns.getServerUsedRam(목표)) / ns.getScriptRam(hackType)), proxyTarget); ns.print('|||||||||| proxy --> ' + 목표 + ' --> ' + hackType + ' --> ' + proxyTarget + ' ||||||||||'); } } // Await n ms between each servers to avoid issue with the infinite loop await ns.sleep(옵션['waitTime']); } } 또 다른 { ns.print('Error, no server available.'); } }
Advanced Usage
You can see all options in-game with
run runner.js --help
You are allowed to use your own hack, grow, weaken script. You can also customize the waiting time between each server. 경고. Always use more that 1ms or you’ll freeze your game.
As of release 2.0.1, the last two arguments of the scp function need to be flipped. It won’t throw errors, but you’ll find that it will only be using the home computer to run the grow/weaken/hack cycle.