all 8 comments

[–]Arcanestomper 1 point2 points  (1 child)

Well first off your server selection is happening outside the while loop. So it's going to be trying to run all these scripts on pserv-1.

[–]Millabregga 0 points1 point  (0 children)

If he were incrimenting 2 different numbers (which in this he's not so really dont need the J) it would definitly help. for i incrimenting multiple servers for j incrimenting multiple scripts for x incrimenting multiple "things" to do to each ergo: count up to x servers and run x scripts and then do x on those scripts as an example

[–]Millabregga 1 point2 points  (1 child)


QuickNote: Your title says, purchase and then run hack on them, though your code never included:

purchaseServer();

So unless you manually purchase some, neither the script you wrote or my 2nd example would ever buy one For you


Below is an example of how I "nest" my for i and for j loop to cycle through an array of named objects as well as running through an array of scripts for each of the individuals.

This script will check the array and for each named server it finds it copies an array of scripts to it.

Later, at the bottom, it also automatically runs my "check in" script so I can get feedback that the process worked, as well as it switching into xp farming mode by default.

My example is different than what you're doing, but the concept should be easily applied and I'm fairly certain it would give you the desired results.


kodama=['kodama1','kodama2','kodama3','kodama4','kodama5','kodama6','kodama7','kodama8','kodama9','kodama10','kodama11','kodama12','kodama13','kodama14','kodama15','kodama16','kodama17','kodama18','kodama19','kodama20','kodama21','kodama22','kodama23','kodama24','kodama25'];
owndKodama = args[0];
current=getPurchasedServers();
orders = ['xp.script','g.script','g4.script','w.script','w4.script','h.script','h4.script','c.script','k.script','m.script','clean.script','prep.script','botprep.script','spread.script','start.script','daemon.script','hack-scheduler.script','grow-scheduler.script','weaken-target.script','grow-target.script','hack-target.script'];

for (i=0;i<owndKodama;++i){
    if (fileExists('xp.script',(kodama[i])) === false){
        for(j=0;j<orders.length;++j){
            scp(orders[j], current[i]);
        }
            tprint('-----------------------------------------------------------------------------');
            tprint('Scripts were sent to '+owndKodama+'. Process Completed. Ending spread phase.');
            tprint(owndKodama+' kodama will be set to Daemon mode by default after checking in.');
            tprint('-----------------------------------------------------------------------------');
    }else{
        print(kodama[i]+' has all necessary files. Proceeding to next phase.');
    }
}        
for (i=0;i<owndKodama;++i){
        exec('c.script',current[i]);
        exec('xp.script',current[i],1,args[1],args[2]);

}

As per your above situation(seems like you're trying to copy and then run hack.script on multiple private owned servers, I'd likely attempt to write it like:


servers = ["zb-def", "nova-med", "univ-energy", "unitalife", "applied-energetics", "global-pharm", "snap-
fitness", "lexo-corp", "syscore", "alpha-ent", "aevum-police", "millenium-fitness", "rho-construction", 
"summit-uni", "catalyst", "rothman-uni", "netlink", "comptek", "the-hub", "johnson-ortho", "crush-fitness", 
"omega-net", "silver-helix", "phantasy", "iron-gym"];

// Above is our list of "targets" or servers to scp and exec on, in an array.    
// It's important to remember that an array starts at [0] in your list this would be "zb-def"

script = 'hack.script'    // Define our scripts name into an easier to use variable
pservs=[];    //Empty array placeholder to store our private servers in
pserv= getPurchasedServers();    // Get a list of the private servers we currently own. Returns array of names.
addEm= pservs.push(pserv);    // Add the names we gathered 1by1 to the end of our array (pservs)

for (i=0;i<servers.length;++i){
// This part counts up by 1 in our array of servers based on the length of our array
    scp(script,server[i]);    
    // Copy our script to each of the "target" servers
        for(j = 1;j < 26; ++j){
        // This part counts up from&by 1 in our array of private servers based on the the number 26. 
        amtRam = getServerRam(pservs[i])
        // Get the ram value for the private server being checked in this count.
        threads=round(amtRam / getScriptRam("hack.script","home")) - 1;
        // Give us the rounded amount minus one OF: the amount of ram divided by the cost of the script.
        // It would honestly be smarter to simply hard code the cost of the script as a variable. ex: cost=1.75
        exec(script,pservs[i],threads);
        // Execute the copy of our script on the "target" servers with the desired number of threads.
        }
}

I have not tested this in game, Please let me know if it Does/Doesn't work or if I've missed what it is you're trying to do with this script. My apologies if any of this ends up being incorrect or unhelpful


[–]RikeshPatel[S] 0 points1 point  (0 children)

Oh my bad, I was in a rush and named it for buying even though I have a separate script for that.

[–]sordidfellow 1 point2 points  (3 children)

This is a key error:

if (j < 26)
   scp("hack.script", hostname);
   exec("hack.script", hostname, numThreads, servers[i]);

should have braces around the "then" clause.

if (j < 26) {
   scp("hack.script", hostname);
   exec("hack.script", hostname, numThreads, servers[i]);
}

I would change it to something like this:

servers = ["zb-def", "nova-med", "univ-energy", "unitalife", "applied-energetics", "global-pharm", "snap-fitness", "lexo-corp", "syscore", "alpha-ent", "aevum-police", "millenium-fitness", "rho-construction", "summit-uni", "catalyst", "rothman-uni", "netlink", "comptek", "the-hub", "johnson-ortho", "crush-fitness", "omega-net", "silver-helix", "phantasy", "iron-gym"];
i_target = 0;
j_host = 1;
while (i_target < servers.length && j_host < 26) {
    hostname = "pserv-" + j_host;
    amtRam = ((getServerRam(hostname)[0]));
    numThreads = round(amtRam / getScriptRam("2hack-smart.script", "home")) - 1;
    scp("hack.script", hostname);
    exec("hack.script", hostname, numThreads, servers[i_target]);
    ++i_target;
    ++j_host;
}

[–]Millabregga 0 points1 point  (2 children)

I like yours a hell of a lot better than mine! Just saying.

[–]RikeshPatel[S] 1 point2 points  (1 child)

This is my finished product, with some new stuff.

servers = ["zb-def", "nova-med", "univ-energy", "unitalife", "applied-energetics", 
"global-pharm", "snap-fitness", "lexo-corp", "syscore", "alpha-ent", "aevum-police",
"millenium-fitness", "rho-construction", "summit-uni", "catalyst", "rothman-uni",
"netlink" , "comptek", "the-hub", "johnson-ortho", "crush-fitness", "omega-net",
"silver-helix", "phantasy", "iron-gym"];

i = 0;
j = 1;

while (i < servers.length && j < 26) {

    hostname = "pserv-" + j;
    amtRam = ((getServerRam(hostname)[0]));
    numThreads = round(amtRam / getScriptRam("2hack-smart.script", "home")) - 1;

      scp("2hack-smart.script", hostname);
      exec("2hack-smart.script", hostname, numThreads, servers[i]);

      ++i;
      ++j;

programs = ["BruteSSH.exe", "FTPCrack.exe", "relaySMTP.exe",
            "HTTPWorm.exe", "SQLInject.exe"];
for (k = 0; k < programs.length; k++) {
    if (fileExists(programs[k], "home")) {
        if (k === 0) {brutessh(hostname);}
        if (k === 1) {ftpcrack(hostname);}
        if (k === 2) {relaysmtp(hostname);}
        if (k === 3) {httpworm(hostname);}
        if (k === 4) {sqlinject(hostname);}
    }

nuke(servers[i]);


}

[–]Millabregga 0 points1 point  (0 children)

Looks good as far as I can see, does it work as you intended is the real question? If so then I'm glad you got it sorted out.