Advertisement
Arinek

Personal Server upgrader

Nov 22nd, 2021 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This Script check if you can afford a better personal server and automatically deletes
  2. //and buys the better one.
  3. //While also resuming any scripts that were running on that pserver previously.
  4.  
  5. var ramValues = []
  6. //Here all the ramValues get added to the array.
  7. for (var i = 0; i < 20; i++){
  8.     var ram = 20 - i;
  9.     ramValues.push(2 ** ram);
  10. }
  11.  
  12. //This checks if you can afford a better one.
  13. for (var u = 0; u < getPurchasedServers().length; u++){
  14.     var hostname = getPurchasedServers()[u];
  15.     for (var d = 0; d < ramValues.length; d++){
  16.             if (getServerMoneyAvailable('home') > getPurchasedServerCost(ramValues[d]) && ramValues[d] > getServerMaxRam(getPurchasedServers()[u])){
  17.                 var ram = ramValues[d]
  18.  
  19.                 //This checks which script should be restarted
  20.                 var scripts = ps(hostname);
  21.                
  22.                 killall(hostname);
  23.                 deleteServer(hostname)
  24.                 purchaseServer(hostname, ram);
  25.                 //This runs the scripts.
  26.                  for (var f = 0; f < scripts.length; f++){
  27.                     var script = scripts[f];
  28.                     scp(script.filename, hostname);
  29.                     exec(script.filename, hostname, script.threads, ...script.args);
  30.                 }
  31.                 break
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement