Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //in parser.js
- shuffle: function(array) {
- var counter = array.length, temp, index;
- while (counter > 0) {
- index = Math.floor(Math.random() * counter);
- counter--;
- temp = array[counter];
- array[counter] = array[index];
- array[index] = temp;
- }
- return array;
- },
- //in commands.js
- randstats: function(arg, by, room, con, shuffle) {
- var text = '';
- var stat = [];
- if (!arg) {
- var bst = Math.floor(580 * Math.random()) + 200;
- } else {
- if (isNaN(arg)) return this.say(con, room, "Specified BST must be a number. Leave blank for a random BST.");
- var bst = Math.floor(arg);
- if (bst < 30) return this.say(con, room, "Specified BST must be a greater than 30.");
- if (bst > 800) return this.say(con, room, "Specified BST must be a less than 800.");
- }
- var remaining = bst
- for (i = 0; i < 6; i++) {
- if (remaining > 200) {
- stat[i] = Math.floor(194 * Math.random()) + 5;
- } else {
- stat[i] = Math.floor((remaining - ((6 - i) * 5 )) * Math.random()) + 5;
- }
- remaining = remaining - stat[i];
- }
- if (remaining !== 0) {
- if (remaining < 100) {
- for (i = 0; i < 6; i++) {
- if (stat[i] < 100) stat[i] = stat[i] + remaining;
- }
- } else {
- var share = Math.floor(remaining / 6);
- var total = '';
- for (i = 0; i < 6; i++) {
- stat[i] = stat[i] + (share);
- total = total + stat[i];
- }
- remaining = (bst - total);
- stat[0] = stat[0] + remaining;
- }
- }
- ranStats = this.shuffle(stat);
- text += 'Random stats: ``HP:`` ' + ranStats[0] + ' ``Atk:`` ' + ranStats[1] + ' ``Def:`` ' + ranStats[2] + ' ``SpA:`` ' + ranStats[3] + ' ``SpD:`` ' + ranStats[4] + ' ``Spe:`` ' + ranStats[5] + ' BST: ' + bst + '.';
- this.say(con, room, text);
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement