Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** @param {NS} ns */
- export async function main(ns) {
- let validNums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512,
- 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576];
- const args = ns.flags([["help", false]]);
- let mem = args._[0];
- if (!mem || args.help) {
- ns.tprint("This script buys a server at the specified RAM.");
- ns.tprint("If the second argument is optional and if left empty, the server will be named:");
- ns.tprint(" MyServer-MEMSIZE");
- ns.tprint("%m in the server name argument will be replaced with the memory size.");
- ns.tprint(`Usage: run ${ns.getScriptName()} MEMSIZE [SERVERNAME]`);
- ns.tprint("Examples:");
- ns.tprint(`> run ${ns.getScriptName()} 32`);
- ns.tprint(`> run ${ns.getScriptName()} 1024 MyAwesomeServer`);
- ns.tprint(`> run ${ns.getScriptName()} 1048576 Server-%m`);
- return;
- }
- if (ns.args[0]){
- let cost = ns.getPurchasedServerCost(ns.args[0]);
- if (cost < ns.getServerMoneyAvailable("home")){
- if (validNums.includes(ns.args[0] )){
- let name = "MyServer-" + ns.args[0];
- if (ns.args[1]) {
- name = ns.args[1];
- name = name.replace(/%m/g, ns.args[0]);
- }
- //ns.tprint(name);
- let hostname = ns.purchaseServer(name, ns.args[0]);
- if (hostname != "") ns.tprint(hostname, " purchased for ", cost);
- else ns.tprint("Something went wrong when purchasing the server.");
- } else ns.tprint(ns.args[0], " is an invalid size. Valid sizes are - ", validNums);
- } else ns.tprint("You do not have enough money! Cost: ", cost);
- } else ns.tprint("You need to include the size of the server. Valid sizes are - ", validNums);
- }
- export function autocomplete(data, args) {
- return ["1", "2", "4", "8", "16", "32", "64", "128", "256", "512",
- "1024", "2048", "4096", "8192", "16384", "32768", "65536", "131072", "262144", "524288", "1048576"];
- }
Advertisement
Add Comment
Please, Sign In to add comment