Advertisement
SolarisFox

ranStats

Jul 22nd, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //in parser.js
  2.     shuffle: function(array) {
  3.         var counter = array.length, temp, index;
  4.         while (counter > 0) {
  5.             index = Math.floor(Math.random() * counter);
  6.             counter--;
  7.             temp = array[counter];
  8.                 array[counter] = array[index];
  9.                 array[index] = temp;
  10.         }
  11.         return array;
  12.     },
  13.  
  14. //in commands.js   
  15.     randstats: function(arg, by, room, con, shuffle) {
  16.         var text = '';
  17.         var stat = [];
  18.         if (!arg) {
  19.             var bst = Math.floor(580 * Math.random()) + 200;
  20.         } else {
  21.             if (isNaN(arg)) return this.say(con, room, "Specified BST must be a number. Leave blank for a random BST.");
  22.             var bst = Math.floor(arg);
  23.             if (bst < 30) return this.say(con, room, "Specified BST must be a greater than 30.");
  24.             if (bst > 800) return this.say(con, room, "Specified BST must be a less than 800.");
  25.         }
  26.         var remaining = bst
  27.         for (i = 0; i < 6; i++) {
  28.             if (remaining > 200) {
  29.                 stat[i] = Math.floor(194 * Math.random()) + 5;
  30.             } else {
  31.                 stat[i] = Math.floor((remaining - ((6 - i) * 5 )) * Math.random()) + 5;
  32.             }
  33.             remaining = remaining - stat[i];
  34.         }
  35.         if (remaining !== 0) {
  36.             if (remaining < 100) {
  37.                 for (i = 0; i < 6; i++) {
  38.                     if (stat[i] < 100) stat[i] = stat[i] + remaining;
  39.                 }
  40.             } else {
  41.                 var share = Math.floor(remaining / 6);
  42.                 var total = '';
  43.                 for (i = 0; i < 6; i++) {
  44.                     stat[i] = stat[i] + (share);
  45.                     total = total + stat[i];
  46.                 }
  47.             remaining = (bst - total);
  48.             stat[0] = stat[0] + remaining;
  49.             }
  50.         }
  51.         ranStats = this.shuffle(stat);
  52.         text += 'Random stats: ``HP:`` ' + ranStats[0] + ' ``Atk:`` ' + ranStats[1] + ' ``Def:`` ' + ranStats[2] + ' ``SpA:`` ' + ranStats[3] + ' ``SpD:`` ' + ranStats[4] + ' ``Spe:`` ' + ranStats[5] + ' BST: ' + bst + '.';
  53.         this.say(con, room, text);
  54.     },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement