From 25722541746be451ad2ada59370a446deb691f94 Mon Sep 17 00:00:00 2001 From: CrystalMoogle Date: Wed, 5 Dec 2012 13:39:47 +0000 Subject: [PATCH 1/8] Generate function Pokemon.prototype.generate(id, level) generates a pokemon id at level Also moved somethings into the global namespace, Pokemon, EVs, IVs Added new function rand(min,max) which generates a random number between min/max (I don't like sys.rand :3) --- scripts/pokeinfo.js | 51 ++++++++++++++++++++++++++++++++++++++++++ scripts/teamChanger.js | 6 ++--- scripts/utilities.js | 4 ++++ 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/scripts/pokeinfo.js b/scripts/pokeinfo.js index cff7de4..ba1ead8 100644 --- a/scripts/pokeinfo.js +++ b/scripts/pokeinfo.js @@ -1,5 +1,55 @@ var pokeinfo = {}; +Pokemon.prototype.generate = function (id, level) { + this.num = id; + this.level = level; + this.evs = new EVs(0, 0, 0, 0, 0, 0); + this.ivs = new IVs(rand(0, 31), rand(0, 31), rand(0, 31), rand(0, 31), rand(0, 31), rand(0, 31)); + this.nick = sys.pokemon(id); + var ratio = sys.pokeGenders(id); + var gender = 0; + if (ratio.hasOwnProperty("male") && ratio.hasOwnProperty("female")) { + if (ratio.male <= rand(0, 100)) { + gender = 1; + } + else { + gender = 2; + } + } + else if (ratio.hasOwnProperty("male") && !ratio.hasOwnProperty("female")) { + gender = 1; + } + else if (!ratio.hasOwnProperty("male") && ratio.hasOwnProperty("female")) { + gender = 2; + } + this.gender = gender; + this.nature = rand(0, 24); + this.shiny = (0 === rand(0, 8192)); + var moves = pokeinfo.levelupMoves(id).sort(); + var movelist = []; + var i = moves.length - 1; + var j = 0; + while (i-- && j < 4) { + var line = moves[i].split(' - '); + if (line[0].indexOf('_') !== -1) { + line[0] = line[0].substring(0, line[0].indexOf('_')); + } + if (level >= line[0]) { + movelist.push(line[1]); + j++; + } + } + this.moves = movelist; + if (sys.pokeAbility(id, 1) === 0) { + this.ability = sys.pokeAbility(id, 0); + } + else { + this.ability = sys.pokeAbility(id, rand(0, 1)); + } + this.happiness = 70; //placeholder for when base happiness data is added + this.item = 0; +}; + pokeinfo.loadLevelMoves = function loadLevelMoves() { pokeinfo.levelMoves = {}; pokeinfo.maxOrder = 0; @@ -104,4 +154,5 @@ pokeinfo.baseEffortValues = function baseEffortValues(num) { } return evs; }; + ret = pokeinfo; \ No newline at end of file diff --git a/scripts/teamChanger.js b/scripts/teamChanger.js index 2cabe5b..5a47306 100644 --- a/scripts/teamChanger.js +++ b/scripts/teamChanger.js @@ -11,7 +11,7 @@ var Team = function (pokes){ }; //All of the information is stored as numbers -var Pokemon = function (num,nick,gender,ability,item,level,ivs,evs,moves,nature,shiny,happiness){ +Pokemon = function (num,nick,gender,ability,item,level,ivs,evs,moves,nature,shiny,happiness){ this.num=num; this.nick=nick; this.gender=gender; @@ -27,7 +27,7 @@ var Pokemon = function (num,nick,gender,ability,item,level,ivs,evs,moves,nature, }; //IVs are numbers between 0 and 31 -var IVs = function(hp,att,def,spAtt,spDef,speed){ +IVs = function(hp,att,def,spAtt,spDef,speed){ this.hp=hp; this.att=att; this.def=def; @@ -37,7 +37,7 @@ var IVs = function(hp,att,def,spAtt,spDef,speed){ }; //EVs are numbers between 0 and 31 -var EVs = function(hp,att,def,spAtt,spDef,speed){ +EVs = function(hp,att,def,spAtt,spDef,speed){ this.hp=hp; this.att=att; this.def=def; diff --git a/scripts/utilities.js b/scripts/utilities.js index 93cc24f..42fd8ee 100644 --- a/scripts/utilities.js +++ b/scripts/utilities.js @@ -5,3 +5,7 @@ String.prototype.startsWithLetter = function() { User.prototype.name = function() { return sys.name(this.id); } + +rand = function rand(min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min; +} \ No newline at end of file From d5b4cb7a3f3d49f95d74d63884ac41060cd97122 Mon Sep 17 00:00:00 2001 From: CrystalMoogle Date: Wed, 5 Dec 2012 13:44:45 +0000 Subject: [PATCH 2/8] Correct comparasion error --- scripts/pokeinfo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pokeinfo.js b/scripts/pokeinfo.js index ba1ead8..390f335 100644 --- a/scripts/pokeinfo.js +++ b/scripts/pokeinfo.js @@ -9,7 +9,7 @@ Pokemon.prototype.generate = function (id, level) { var ratio = sys.pokeGenders(id); var gender = 0; if (ratio.hasOwnProperty("male") && ratio.hasOwnProperty("female")) { - if (ratio.male <= rand(0, 100)) { + if (ratio.male >= rand(0, 100)) { gender = 1; } else { From c359c3515023d8f22549dc42710a3c8785f2d5d7 Mon Sep 17 00:00:00 2001 From: CrystalMoogle Date: Wed, 5 Dec 2012 14:12:52 +0000 Subject: [PATCH 3/8] Fixing another error It was previously slightly weighted towards the male side --- scripts/pokeinfo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pokeinfo.js b/scripts/pokeinfo.js index 390f335..29534de 100644 --- a/scripts/pokeinfo.js +++ b/scripts/pokeinfo.js @@ -9,7 +9,7 @@ Pokemon.prototype.generate = function (id, level) { var ratio = sys.pokeGenders(id); var gender = 0; if (ratio.hasOwnProperty("male") && ratio.hasOwnProperty("female")) { - if (ratio.male >= rand(0, 100)) { + if (ratio.male >= rand(1, 100)) { gender = 1; } else { From e5d8f8b084f0f1eb2e55c6fe81901e4cb4dfbf72 Mon Sep 17 00:00:00 2001 From: CrystalMoogle Date: Thu, 6 Dec 2012 11:59:20 +0000 Subject: [PATCH 4/8] Adding base happiness --- data/pokemon_base_happiness.csv | 650 ++++++++++++++++++++++++++++++++ scripts/pokeinfo.js | 43 ++- 2 files changed, 677 insertions(+), 16 deletions(-) create mode 100644 data/pokemon_base_happiness.csv diff --git a/data/pokemon_base_happiness.csv b/data/pokemon_base_happiness.csv new file mode 100644 index 0000000..358cea8 --- /dev/null +++ b/data/pokemon_base_happiness.csv @@ -0,0 +1,650 @@ +id,base_happiness +1,70 +2,70 +3,70 +4,70 +5,70 +6,70 +7,70 +8,70 +9,70 +10,70 +11,70 +12,70 +13,70 +14,70 +15,70 +16,70 +17,70 +18,70 +19,70 +20,70 +21,70 +22,70 +23,70 +24,70 +25,70 +26,70 +27,70 +28,70 +29,70 +30,70 +31,70 +32,70 +33,70 +34,70 +35,140 +36,140 +37,70 +38,70 +39,70 +40,70 +41,70 +42,70 +43,70 +44,70 +45,70 +46,70 +47,70 +48,70 +49,70 +50,70 +51,70 +52,70 +53,70 +54,70 +55,70 +56,70 +57,70 +58,70 +59,70 +60,70 +61,70 +62,70 +63,70 +64,70 +65,70 +66,70 +67,70 +68,70 +69,70 +70,70 +71,70 +72,70 +73,70 +74,70 +75,70 +76,70 +77,70 +78,70 +79,70 +80,70 +81,70 +82,70 +83,70 +84,70 +85,70 +86,70 +87,70 +88,70 +89,70 +90,70 +91,70 +92,70 +93,70 +94,70 +95,70 +96,70 +97,70 +98,70 +99,70 +100,70 +101,70 +102,70 +103,70 +104,70 +105,70 +106,70 +107,70 +108,70 +109,70 +110,70 +111,70 +112,70 +113,140 +114,70 +115,70 +116,70 +117,70 +118,70 +119,70 +120,70 +121,70 +122,70 +123,70 +124,70 +125,70 +126,70 +127,70 +128,70 +129,70 +130,70 +131,70 +132,70 +133,70 +134,70 +135,70 +136,70 +137,70 +138,70 +139,70 +140,70 +141,70 +142,70 +143,70 +144,35 +145,35 +146,35 +147,35 +148,35 +149,35 +150,0 +151,100 +152,70 +153,70 +154,70 +155,70 +156,70 +157,70 +158,70 +159,70 +160,70 +161,70 +162,70 +163,70 +164,70 +165,70 +166,70 +167,70 +168,70 +169,70 +170,70 +171,70 +172,70 +173,140 +174,70 +175,70 +176,70 +177,70 +178,70 +179,70 +180,70 +181,70 +182,70 +183,70 +184,70 +185,70 +186,70 +187,70 +188,70 +189,70 +190,70 +191,70 +192,70 +193,70 +194,70 +195,70 +196,70 +197,35 +198,35 +199,70 +200,35 +201,70 +202,70 +203,70 +204,70 +205,70 +206,70 +207,70 +208,70 +209,70 +210,70 +211,70 +212,70 +213,70 +214,70 +215,35 +216,70 +217,70 +218,70 +219,70 +220,70 +221,70 +222,70 +223,70 +224,70 +225,70 +226,70 +227,70 +228,35 +229,35 +230,70 +231,70 +232,70 +233,70 +234,70 +235,70 +236,70 +237,70 +238,70 +239,70 +240,70 +241,70 +242,140 +243,35 +244,35 +245,35 +246,35 +247,35 +248,35 +249,0 +250,0 +251,100 +252,70 +253,70 +254,70 +255,70 +256,70 +257,70 +258,70 +259,70 +260,70 +261,70 +262,70 +263,70 +264,70 +265,70 +266,70 +267,70 +268,70 +269,70 +270,70 +271,70 +272,70 +273,70 +274,70 +275,70 +276,70 +277,70 +278,70 +279,70 +280,35 +281,35 +282,35 +283,70 +284,70 +285,70 +286,70 +287,70 +288,70 +289,70 +290,70 +291,70 +292,70 +293,70 +294,70 +295,70 +296,70 +297,70 +298,70 +299,70 +300,70 +301,70 +302,35 +303,70 +304,35 +305,35 +306,35 +307,70 +308,70 +309,70 +310,70 +311,70 +312,70 +313,70 +314,70 +315,70 +316,70 +317,70 +318,35 +319,35 +320,70 +321,70 +322,70 +323,70 +324,70 +325,70 +326,70 +327,70 +328,70 +329,70 +330,70 +331,35 +332,35 +333,70 +334,70 +335,70 +336,70 +337,70 +338,70 +339,70 +340,70 +341,70 +342,70 +343,70 +344,70 +345,70 +346,70 +347,70 +348,70 +349,70 +350,70 +351,70 +352,70 +353,35 +354,35 +355,35 +356,35 +357,70 +358,70 +359,35 +360,70 +361,70 +362,70 +363,70 +364,70 +365,70 +366,70 +367,70 +368,70 +369,70 +370,70 +371,35 +372,35 +373,35 +374,35 +375,35 +376,35 +377,35 +378,35 +379,35 +380,90 +381,90 +382,0 +383,0 +384,0 +385,100 +386,0 +387,70 +388,70 +389,70 +390,70 +391,70 +392,70 +393,70 +394,70 +395,70 +396,70 +397,70 +398,70 +399,70 +400,70 +401,70 +402,70 +403,70 +404,100 +405,70 +406,70 +407,70 +408,70 +409,70 +410,70 +411,70 +412,70 +413,70 +414,70 +415,70 +416,70 +417,100 +418,70 +419,70 +420,70 +421,70 +422,70 +423,70 +424,100 +425,70 +426,70 +427,0 +428,140 +429,35 +430,35 +431,70 +432,70 +433,70 +434,70 +435,70 +436,70 +437,70 +438,70 +439,70 +440,140 +441,35 +442,70 +443,70 +444,70 +445,70 +446,70 +447,70 +448,70 +449,70 +450,70 +451,70 +452,70 +453,100 +454,70 +455,70 +456,70 +457,70 +458,70 +459,70 +460,70 +461,35 +462,70 +463,70 +464,70 +465,70 +466,70 +467,70 +468,70 +469,70 +470,35 +471,35 +472,70 +473,70 +474,70 +475,35 +476,70 +477,35 +478,70 +479,70 +480,140 +481,140 +482,140 +483,0 +484,0 +485,100 +486,0 +487,0 +488,100 +489,70 +490,70 +491,0 +492,100 +493,0 +494,100 +495,70 +496,70 +497,70 +498,70 +499,70 +500,70 +501,70 +502,70 +503,70 +504,70 +505,70 +506,70 +507,70 +508,70 +509,70 +510,70 +511,70 +512,70 +513,70 +514,70 +515,70 +516,70 +517,70 +518,70 +519,70 +520,70 +521,70 +522,70 +523,70 +524,70 +525,70 +526,70 +527,70 +528,70 +529,70 +530,70 +531,70 +532,70 +533,70 +534,70 +535,70 +536,70 +537,70 +538,70 +539,70 +540,70 +541,70 +542,70 +543,70 +544,70 +545,70 +546,70 +547,70 +548,70 +549,70 +550,70 +551,70 +552,70 +553,70 +554,70 +555,70 +556,70 +557,70 +558,70 +559,35 +560,70 +561,70 +562,70 +563,70 +564,70 +565,70 +566,70 +567,70 +568,70 +569,70 +570,70 +571,70 +572,70 +573,70 +574,70 +575,70 +576,70 +577,70 +578,70 +579,70 +580,70 +581,70 +582,70 +583,70 +584,70 +585,70 +586,70 +587,70 +588,70 +589,70 +590,70 +591,70 +592,70 +593,70 +594,70 +595,70 +596,70 +597,70 +598,70 +599,70 +600,70 +601,70 +602,70 +603,70 +604,70 +605,70 +606,70 +607,70 +608,70 +609,70 +610,35 +611,35 +612,35 +613,70 +614,70 +615,70 +616,70 +617,70 +618,70 +619,70 +620,70 +621,70 +622,70 +623,70 +624,35 +625,35 +626,70 +627,70 +628,70 +629,35 +630,35 +631,70 +632,70 +633,35 +634,35 +635,35 +636,70 +637,70 +638,35 +639,35 +640,35 +641,90 +642,90 +643,0 +644,0 +645,90 +646,0 +647,35 +648,100 +649,0 \ No newline at end of file diff --git a/scripts/pokeinfo.js b/scripts/pokeinfo.js index 29534de..5f21dff 100644 --- a/scripts/pokeinfo.js +++ b/scripts/pokeinfo.js @@ -6,6 +6,16 @@ Pokemon.prototype.generate = function (id, level) { this.evs = new EVs(0, 0, 0, 0, 0, 0); this.ivs = new IVs(rand(0, 31), rand(0, 31), rand(0, 31), rand(0, 31), rand(0, 31), rand(0, 31)); this.nick = sys.pokemon(id); + this.happiness = pokeinfo.getBaseHappiness(id); + this.item = 0; + this.nature = rand(0, 24); + this.shiny = (0 === rand(0, 8192)); + if (sys.pokeAbility(id, 1) === 0) { + this.ability = sys.pokeAbility(id, 0); + } + else { + this.ability = sys.pokeAbility(id, rand(0, 1)); + } var ratio = sys.pokeGenders(id); var gender = 0; if (ratio.hasOwnProperty("male") && ratio.hasOwnProperty("female")) { @@ -23,8 +33,6 @@ Pokemon.prototype.generate = function (id, level) { gender = 2; } this.gender = gender; - this.nature = rand(0, 24); - this.shiny = (0 === rand(0, 8192)); var moves = pokeinfo.levelupMoves(id).sort(); var movelist = []; var i = moves.length - 1; @@ -40,14 +48,6 @@ Pokemon.prototype.generate = function (id, level) { } } this.moves = movelist; - if (sys.pokeAbility(id, 1) === 0) { - this.ability = sys.pokeAbility(id, 0); - } - else { - this.ability = sys.pokeAbility(id, rand(0, 1)); - } - this.happiness = 70; //placeholder for when base happiness data is added - this.item = 0; }; pokeinfo.loadLevelMoves = function loadLevelMoves() { @@ -122,12 +122,7 @@ pokeinfo.loadEVs = function loadEVs() { if (!pokeinfo.effortValues.hasOwnProperty(pokemon)) { pokeinfo.effortValues[pokemon] = {}; } - pokeinfo.effortValues[pokemon][0] = line[1]; //hp - pokeinfo.effortValues[pokemon][1] = line[2]; //atk - pokeinfo.effortValues[pokemon][2] = line[3]; //def - pokeinfo.effortValues[pokemon][3] = line[4]; //spatk - pokeinfo.effortValues[pokemon][4] = line[5]; //spdef - pokeinfo.effortValues[pokemon][5] = line[6]; //speed + pokeinfo.effortValues[pokemon] = line.slice(1); } }; @@ -155,4 +150,20 @@ pokeinfo.baseEffortValues = function baseEffortValues(num) { return evs; }; +pokeinfo.loadHappiness = function loadHappiness() { + pokeinfo.baseHappiness = {}; + var values = sys.getFileContent('data/pokemon_base_happiness.csv').split('\n'); + for (var x = 0; x < values.length; x++) { + var line = values[x].split(','); + pokeinfo.baseHappiness[line[0]] = line[1]; + } +}; + +pokeinfo.getBaseHappiness = function getBaseHappiness(num) { + if (!pokeinfo.baseHappiness.hasOwnProperty(num)) { + return "Incorrect Pokemon"; + } + return pokeinfo.baseHappiness[num]; +}; + ret = pokeinfo; \ No newline at end of file From a5657814f686e144f1d0871308a039806c28b0f5 Mon Sep 17 00:00:00 2001 From: CrystalMoogle Date: Thu, 6 Dec 2012 13:23:26 +0000 Subject: [PATCH 5/8] Load data on script reload/server startup and fix sorting for levelup moves --- scripts.js | 3 +++ scripts/pokeinfo.js | 27 +++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/scripts.js b/scripts.js index 8f7cfec..9e50f77 100644 --- a/scripts.js +++ b/scripts.js @@ -12,6 +12,7 @@ function User(id) require ("utilities.js"); require ("printer.js"); require ("teamChanger.js"); +pokeinfo = require ("pokeinfo.js"); commands = require ("commands.js"); SESSION.identifyScriptAs("RPG Script"); @@ -30,6 +31,8 @@ function testClearChat() { } } +pokeinfo.loadData(); //loads all the data from pokeinfo + poScripts = ({ afterLogIn : function(source) { diff --git a/scripts/pokeinfo.js b/scripts/pokeinfo.js index 5f21dff..6ece88c 100644 --- a/scripts/pokeinfo.js +++ b/scripts/pokeinfo.js @@ -33,7 +33,7 @@ Pokemon.prototype.generate = function (id, level) { gender = 2; } this.gender = gender; - var moves = pokeinfo.levelupMoves(id).sort(); + var moves = pokeinfo.levelupMoves(id); var movelist = []; var i = moves.length - 1; var j = 0; @@ -50,6 +50,12 @@ Pokemon.prototype.generate = function (id, level) { this.moves = movelist; }; +pokeinfo.loadData = function loadData() { + pokeinfo.loadLevelMoves(); + pokeinfo.loadEVs(); + pokeinfo.loadHappiness(); +}; + pokeinfo.loadLevelMoves = function loadLevelMoves() { pokeinfo.levelMoves = {}; pokeinfo.maxOrder = 0; @@ -110,7 +116,24 @@ pokeinfo.levelupMoves = function levelupMoves(num) { moves.push(x + " - " + data[x]); } } - return moves; + var sortMoves = function (a, b) { + a = a.substring(0, a.indexOf(" - ")); + b = b.substring(0, b.indexOf(" - ")); + var c, d; + if (a.indexOf('_') !== -1) { + c = a.substring(a.indexOf('_') + 1); + a = a.substring(0, a.indexOf('_')); + } + if (b.indexOf('_') !== -1) { + d = b.substring(b.indexOf('_') + 1) + b = b.substring(0, b.indexOf('_')); + } + if (c !== undefined && d !== undefined) { + return c - d; + } + return a - b; + }; + return moves.sort(sortMoves); }; pokeinfo.loadEVs = function loadEVs() { From 6bd29bad058f3b634c64f8847b46202b423505c5 Mon Sep 17 00:00:00 2001 From: CrystalMoogle Date: Thu, 6 Dec 2012 13:51:29 +0000 Subject: [PATCH 6/8] If this.channel is undefined, making the message global --- scripts/pokeinfo.js | 2 +- scripts/printer.js | 36 ++++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/scripts/pokeinfo.js b/scripts/pokeinfo.js index 6ece88c..c949ca1 100644 --- a/scripts/pokeinfo.js +++ b/scripts/pokeinfo.js @@ -125,7 +125,7 @@ pokeinfo.levelupMoves = function levelupMoves(num) { a = a.substring(0, a.indexOf('_')); } if (b.indexOf('_') !== -1) { - d = b.substring(b.indexOf('_') + 1) + d = b.substring(b.indexOf('_') + 1); b = b.substring(0, b.indexOf('_')); } if (c !== undefined && d !== undefined) { diff --git a/scripts/printer.js b/scripts/printer.js index bff58b6..a86b4f0 100644 --- a/scripts/printer.js +++ b/scripts/printer.js @@ -20,16 +20,32 @@ var colors = [ ]; function is_undefined(val) { - return typeof(val) === 'undefined' || val === null; -}; + return typeof (val) === 'undefined' || val === null; +} -User.prototype.print = function(bot, message) { +User.prototype.print = function (bot, message) { + var sendMessage = function (id, message, channel) { + if (!is_undefined(channel)) { + sys.sendMessage(id, message, channel); + } + else { + sys.sendMessage(id, message); + } + }; + var sendHtmlMessage = function (id, message, channel) { + if (!is_undefined(channel)) { + sys.sendHtmlMessage(id, message, channel); + } + else { + sys.sendHtmlMessage(id, message); + } + }; if (bot === "blank") { - sys.sendMessage(this.id, message, this.channel); + sendMessage(this.id, message, this.channel); return; } if (bot === "***") { - sys.sendMessage(this.id, "*** " + message + " ***", this.channel); + sendMessage(this.id, "*** " + message + " ***", this.channel); return; } @@ -45,9 +61,9 @@ User.prototype.print = function(bot, message) { } if (is_undefined(color)) { - sys.sendMessage(this.id, bot + ": " + message, this.channel); - } else { - sys.sendHtmlMessage(this.id, "" - + "" + bot + ": " + message, this.channel); + sendMessage(this.id, bot + ": " + message, this.channel); } -}; + else { + sendHtmlMessage(this.id, "" + "" + bot + ": " + message, this.channel); + } +}; \ No newline at end of file From ad462b8b85fa8ea7b0473b6a095d86e7b155fcde Mon Sep 17 00:00:00 2001 From: CrystalMoogle Date: Fri, 7 Dec 2012 10:06:49 +0000 Subject: [PATCH 7/8] Use the default channel param instead, to make the message appear --- scripts.js | 3 ++- scripts/printer.js | 24 ++++-------------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/scripts.js b/scripts.js index 9e50f77..c6ccb78 100644 --- a/scripts.js +++ b/scripts.js @@ -35,8 +35,9 @@ pokeinfo.loadData(); //loads all the data from pokeinfo poScripts = ({ -afterLogIn : function(source) { +afterLogIn : function(source, chan) { var user = SESSION.users(source); + user.channel = sys.channelId(chan); user.print("Abra", "Type /commands to get a list of commands!"); user.print("blank", ""); } diff --git a/scripts/printer.js b/scripts/printer.js index a86b4f0..59097d0 100644 --- a/scripts/printer.js +++ b/scripts/printer.js @@ -24,28 +24,12 @@ function is_undefined(val) { } User.prototype.print = function (bot, message) { - var sendMessage = function (id, message, channel) { - if (!is_undefined(channel)) { - sys.sendMessage(id, message, channel); - } - else { - sys.sendMessage(id, message); - } - }; - var sendHtmlMessage = function (id, message, channel) { - if (!is_undefined(channel)) { - sys.sendHtmlMessage(id, message, channel); - } - else { - sys.sendHtmlMessage(id, message); - } - }; if (bot === "blank") { - sendMessage(this.id, message, this.channel); + sys.sendMessage(this.id, message, this.channel); return; } if (bot === "***") { - sendMessage(this.id, "*** " + message + " ***", this.channel); + sys.sendMessage(this.id, "*** " + message + " ***", this.channel); return; } @@ -61,9 +45,9 @@ User.prototype.print = function (bot, message) { } if (is_undefined(color)) { - sendMessage(this.id, bot + ": " + message, this.channel); + sys.sendMessage(this.id, bot + ": " + message, this.channel); } else { - sendHtmlMessage(this.id, "" + "" + bot + ": " + message, this.channel); + sys.sendHtmlMessage(this.id, "" + "" + bot + ": " + message, this.channel); } }; \ No newline at end of file From d9d37ad409b7cdcb78798e46be64e1cae62f1cb3 Mon Sep 17 00:00:00 2001 From: CrystalMoogle Date: Fri, 7 Dec 2012 16:18:50 +0000 Subject: [PATCH 8/8] Fixing a slight problem with move generation and if channel is undefined, using 0 --- scripts.js | 3 +-- scripts/pokeinfo.js | 2 +- scripts/printer.js | 3 +++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts.js b/scripts.js index c6ccb78..9e50f77 100644 --- a/scripts.js +++ b/scripts.js @@ -35,9 +35,8 @@ pokeinfo.loadData(); //loads all the data from pokeinfo poScripts = ({ -afterLogIn : function(source, chan) { +afterLogIn : function(source) { var user = SESSION.users(source); - user.channel = sys.channelId(chan); user.print("Abra", "Type /commands to get a list of commands!"); user.print("blank", ""); } diff --git a/scripts/pokeinfo.js b/scripts/pokeinfo.js index c949ca1..7822e06 100644 --- a/scripts/pokeinfo.js +++ b/scripts/pokeinfo.js @@ -35,7 +35,7 @@ Pokemon.prototype.generate = function (id, level) { this.gender = gender; var moves = pokeinfo.levelupMoves(id); var movelist = []; - var i = moves.length - 1; + var i = moves.length; var j = 0; while (i-- && j < 4) { var line = moves[i].split(' - '); diff --git a/scripts/printer.js b/scripts/printer.js index 59097d0..823ed8f 100644 --- a/scripts/printer.js +++ b/scripts/printer.js @@ -24,6 +24,9 @@ function is_undefined(val) { } User.prototype.print = function (bot, message) { + if (is_undefined(this.channel)) { + this.channel = 0; + } if (bot === "blank") { sys.sendMessage(this.id, message, this.channel); return;