Catch command coding not function

#1

Hey guys, i have coded a catch command to level up pokemon. well my only thing is i have no errors, phantom bot runs the command however nothing appears in chat. Not sure what im coding wrong if anyone has any ideas? The only command should be !pokecatch and

(function() {
var BASE_POKEMON_EXP = 1;
var BASE_VIEWER_EXP = 1;
var MAX_EXP = 10000;

function viewerexppokemon(sender, pokecatch) {
	var currentEXP = parseInt($.inidb.get('pokecatch', 'pokemonexp')),
		viewerexp = parseInt($.inidb.get('pokecatch', 'viewerexp'));
	
	if(viewerexp <= 0) {
		$.say('You are level 1 with no viewerexp! Use !pokecatch to level up!');
		return;
	}
	
	if(currentviewerexp < 1) {
		$.say('All Pokemon have been caught. The streamer must find the next field!');
		return;
	}
	
	if((currentEXP + pokecatch) <= 0) {
		currentEXP = 0;
	} else {
		currentEXP = (currentEXP + pokecatch);
	}
	
	if(currentEXP > 0) {
		$.say(sender + ' viewerexp ' + pokecatch + ' pokecatch, leaving the field at ' + currentEXP + ' EXP!');
	} else {
		$.say(sender + ' caught ' + pokecatch + ' viewerexp, and cleared the field!');
	}
	
	$.writeToFile('' + currentEXP, 'EXP.txt', false);
	$.inidb.set('pokecatch', 'EXP', currentEXP);
}

function attackUser(sender, stole) {
	var currentEXP = parseInt($.inidb.get('pokecatch', 'viewerexp'));
	
	if(currentEXP < 1) {
		$.say('You do not have any viewerexp to pokecatch the pokemon! Use !pokecatch to gain EXP!');
		return;
	}
	
	if((currentEXP + pokecatch) <= 0) {
		currentEXP = 0;
	} else {
		currentEXP = (currentEXP + pokecatch);
	}
	
	if(currentEXP > 0) {
		$.say(sender + ' fails to pokecatch the pokemon and takes ' + pokecatch + ' damage as a result, leaving the Viewer EXP at ' + currentEXP + '!');
	} else {
		$.say(sender + ' failed to pokecatch the pokemon. The pokemon retaliates with a ' + pokecatch + ' damage hit, and has defeated the viewers!');
	}
	
	$.writeToFile('' + currentEXP, 'viewerexp.txt', false);
	$.inidb.set('pokecatch', 'viewerexp', currentEXP);
}

function restoreEXP(sender) {
	var viewerexp = parseInt($.inidb.get('pokecatch', 'viewerexp')),
		increase = $.randRange(1, 10000);
	if(viewerexp >= BASE_VIEWER_EXP) {
		$.say('You cannot gain any viewerexp at this time');
		return;
	}
	
	if((viewerexp + increase) > BASE_VIEWER_EXP) {
		viewerexp = BASE_VIEWER_EXP;
	} else {
		viewerexp = (viewerexp + increase) ;
	}
	$.writeToFile('' + viewerexp, 'viewerexp.txt', false);
	$.inidb.set('pokecatch', 'viewerexp', viewerexp);
	$.say(sender + ' has healed the Viewers by ' + increase + '! Bringing the current health to ' + viewerexp + '!');
}

/**
 * @event command
 */
$.bind('command', function(event) {
    var sender = event.getSender().toLowerCase(),
        command = event.getCommand(),
        args = event.getArgs(),
        action = args[0],
		hit = $.randRange(1, MAX_HIT);
		
    if (command.equalsIgnoreCase('pokecatch')) {
		if(!action) {
			if($.randRange(1, 50) <= 25) {// about a 50/50 shot they attack
				pokecatch(sender, hit);
			} else {
				attackUser(sender, hit);
			}
		} else if(action.equalsIgnoreCase('reset')) {// admin only reset command.
			$.inidb.set('pokecatch', 'EXP', BASE_BOSS_EXP);
			$.inidb.set('pokecatch', 'viewerexp', BASE_VIEWER_EXP);
			$.writeToFile('' + BASE_POKEMON_EXP, 'EXP.txt', false);
			$.writeToFile('' + BASE_VIEWER_EXP, 'viewerexp.txt', false);
		} else {
			$.say(sender + ', invalid option passed to pokecatch command');
		}
    } else if (command.equalsIgnoreCase('potion')) {
		restoreEXP(sender);
	}
});

/**
 * @event initReady
 */
$.bind('initReady', function() {
    if ($.bot.isModuleEnabled('./commands/pokecatchCommand.js')) {
        $.registerChatCommand('./commands/pokecatchCommand.js', 'potion', 7);
        $.registerChatCommand('./commands/pokecatchCommand.js', 'pokecatch', 7);
        $.registerChatSubcommand('pokecatch', 'reset', 1);
    }
	var currentEXP = parseInt($.inidb.get('pokecatch', 'EXP'));
	var exists = isNaN(parseInt(currentEXP)) || parseInt(currentEXP) === 0 ? (currentEXP = 0, true) : (false);
	if(!exists || currentEXP == 0) {
		$.inidb.set('pokecatch', 'EXP', BASE_POKEMON_EXP);
		$.inidb.set('pokecatch', 'viewerexp', BASE_VIEWER_EXP);
		$.writeToFile('' + BASE_POKEMON_EXP, 'EXP.txt', false);
		$.writeToFile('' + BASE_VIEWER_EXP, 'viewerexp.txt', false);
	}
});

})();

split this topic #2

5 posts were merged into an existing topic: How to activate my custom command in chat

closed #3