How to activate my custom command in chat

#1

Hey guys, i grabbed a custom bot command and i need some help. i am unsure how to activate the command. I see it is enabled but i have no idea how to start the command [05-08-2019 @ 15:13:07.825 GMT] Loaded module: commands/bossAtkCommand.js (Enabled)

below is the command prepare as its long (function() {
var BASE_BOSS_HP = 1400000;
var BASE_VIEWER_HP = 98000;
var MAX_HIT = 10000;

function attackBoss(sender, dmg) {
	var currentHP = parseInt($.inidb.get('bossatk', 'bosshp')),
		viewerHP = parseInt($.inidb.get('bossatk', 'viewerhp'));
	
	if(viewerHP <= 0) {
		$.say('You do not have any health to attack the boss! Use !bossrstr to regenerate HP!');
		return;
	}
	
	if(currentHP < 1) {
		$.say('The boss has already been defeated. The streamer must reset the boss for the next attack!');
		return;
	}
	
	if(currentHP < 1) {
		$.say('The boss has already been defeated. The streamer must reset the boss for the next attack!');
		return;
	}
	
	if((currentHP - dmg) <= 0) {
		currentHP = 0;
	} else {
		currentHP = (currentHP - dmg);
	}
	
	if(currentHP > 0) {
		$.say(sender + ' attacks the boss for ' + dmg + ' damage, leaving the boss at ' + currentHP + ' HP!');
	} else {
		$.say(sender + ' attacked the boss with a crushing blow of ' + dmg + ' damage, and defeated the boss!');
	}
	
	$.writeToFile('' + currentHP, 'bosshp.txt', false);
	$.inidb.set('bossatk', 'bosshp', currentHP);
}

function attackUser(sender, dmg) {
	var currentHP = parseInt($.inidb.get('bossatk', 'viewerhp'));
	
	if(currentHP < 1) {
		$.say('You do not have any health to attack the boss! Use !bossrstr to regenerate HP!');
		return;
	}
	
	if((currentHP - dmg) <= 0) {
		currentHP = 0;
	} else {
		currentHP = (currentHP - dmg);
	}
	
	if(currentHP > 0) {
		$.say(sender + ' fails to attack the boss and takes ' + dmg + ' damage as a result, leaving the Viewer HP at ' + currentHP + '!');
	} else {
		$.say(sender + ' failed to attack the boss. The boss retaliates with a ' + dmg + ' damage hit, and has defeated the viewers!');
	}
	
	$.writeToFile('' + currentHP, 'viewerhp.txt', false);
	$.inidb.set('bossatk', 'viewerhp', currentHP);
}

function restoreHP(sender) {
	var viewerHP = parseInt($.inidb.get('bossatk', 'viewerhp')),
		increase = $.randRange(1, 10000);
	if(viewerHP >= BASE_VIEWER_HP) {
		$.say('You cannot regenerate any more health at this time');
		return;
	}
	
	if((viewerHP + increase) > BASE_VIEWER_HP) {
		viewerHP = BASE_VIEWER_HP;
	} else {
		viewerHP = (viewerHP + increase) ;
	}
	$.writeToFile('' + viewerHP, 'viewerhp.txt', false);
	$.inidb.set('bossatk', 'viewerhp', viewerHP);
	$.say(sender + ' has healed the Viewers by ' + increase + '! Bringing the current health to ' + viewerHP + '!');
}

/**
 * @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('bossatk')) {
		if(!action) {
			if($.randRange(1, 50) <= 25) {// about a 50/50 shot they attack
				attackBoss(sender, hit);
			} else {
				attackUser(sender, hit);
			}
		} else if(action.equalsIgnoreCase('reset')) {// admin only reset command.
			$.inidb.set('bossatk', 'bosshp', BASE_BOSS_HP);
			$.inidb.set('bossatk', 'viewerhp', BASE_VIEWER_HP);
			$.writeToFile('' + BASE_BOSS_HP, 'bosshp.txt', false);
			$.writeToFile('' + BASE_VIEWER_HP, 'viewerhp.txt', false);
		} else {
			$.say(sender + ', invalid option passed to bossatk command');
		}
    } else if (command.equalsIgnoreCase('bossrstr')) {
		restoreHP(sender);
	}
});

/**
 * @event initReady
 */
$.bind('initReady', function() {
    if ($.bot.isModuleEnabled('./custom/commands/bossAtkCommand.js')) {
        $.registerChatCommand('./custom/commands/bossAtkCommand.js', 'bossrstr', 7);
        $.registerChatCommand('./custom/commands/bossAtkCommand.js', 'bossatk', 7);
        $.registerChatSubcommand('bossatk', 'reset', 1);
    }
	var currentHP = parseInt($.inidb.get('bossatk', 'bosshp'));
	var exists = isNaN(parseInt(currentHP)) || parseInt(currentHP) === 0 ? (currentHP = 0, true) : (false);
	if(!exists || currentHP == 0) {
		$.inidb.set('bossatk', 'bosshp', BASE_BOSS_HP);
		$.inidb.set('bossatk', 'viewerhp', BASE_VIEWER_HP);
		$.writeToFile('' + BASE_BOSS_HP, 'bosshp.txt', false);
		$.writeToFile('' + BASE_VIEWER_HP, 'viewerhp.txt', false);
	}
});

})();

Catch command coding not function
#2

I’m not a coding expert, but put bossAtkCommand.js in /custom/commands/, not just /commands. Create this directory if it doesn’t exist.

#3

theres already a custom commands spot and there are a ton of commands in the field. should i add it at the bottom?

#4

The reason why I wrote that message is because of this piece of code in your script:

if ($.bot.isModuleEnabled('./custom/commands/bossAtkCommand.js')) {
    $.registerChatCommand('./custom/commands/bossAtkCommand.js', 'bossrstr', 7);
    $.registerChatCommand('./custom/commands/bossAtkCommand.js', 'bossatk', 7);
    $.registerChatSubcommand('bossatk', 'reset', 1);
}
#5

Hey superboy60,

It looks like you might’ve put your custom script in the ./scripts/commands/ directory. There are two possible fixes for this.

First would be to move your script to the ./scripts/custom/commands directory (if it doesn’t exist, create it).

Second would be to modify your script’s command location path located in the initReady event. You would change all of the ./custom/commands/bossAtkCommand.js values to ./commands/bossAtkCommand.js.

Hope this helps you out!

#6

worked! you are awesome thank you

#7

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);
	}
});

})();

#8

im pretty sure you posted the same thing here? but if you could upload the script here ill take a look at it :slight_smile: when you pasted the code it broke in the most :slight_smile:

#9

catchCommand.js (4.3 KB)

thank you

#10

well first off this function is never triggered :slight_smile: try to rename that function pokecatch as thats what the command is calling :slight_smile:

#11

I’m going to merge your topics together in case someone runs into the same issues in the future, it will be easier to find.

:slight_smile:

1 Like
#12

renamed function at top of list to BASE_POKECATCH got this back

[05-09-2019 @ 13:46:21.672 GMT] [ERROR] [init.js:325] Error with Event Handler [initReady] Script [./commands/catchComma > init.js:445] Exception [ReferenceError: “BASE_VIEWER_EXP” is not defined.]

#13

no no like this… you change the var not the function :kappa:

catchCommand.js (4.1 KB)

PS: also looks like MAX_EXP is defined but never used anywhere other then where its defined

#14

catchCommand.js (4.3 KB)

okay i replaced HIT with exp hopefully i didnt miss a step. still no command function in twitch channel though but no errors in loading

#15

to be all honest your better off re coding the script from the start and get it to do what you want

#16

thank you

#17

catchCommand.js (4.4 KB)

new coding still stuck haha no errors but cant get it to run in chat

#18
pokecatch
module status ./commands/pokecatchCommand.js
[05-11-2019 @ 09:04:41.958 MDT] [MUTED] @IllusionaryBot, That module does not exist or is not loaded!

In the script:

        if ($.bot.isModuleEnabled('./commands/pokecatchCommand.js')) {
            $.registerChatCommand('./commands/pokecatchCommand.js', 'pokecatch', 7);
            $.registerChatCommand('./commands/pokecatchCommand.js', 'pokecatch', 7);

Also, should that second “pokecatch” be potion?

So I renamed to pokecatchCommand.js and reloaded:

pokecatch
[05-11-2019 @ 09:05:26.302 MDT] [MUTED] You do not have any experience to levelup the pokemon! Use !pokecatch to gain EXP!