Modding Resources: Installing Mods | Creating Mods | Basic Code Examples | Creating a Character | Audio and Visual Effects | The Automator | User Interface | Graph Editor

The Automator

Unlocking the Automator

The automator can be unlocked for a character using the onAutomatorUnlocked function:

	
	CH2.currentCharacter.onAutomatorUnlocked();
	

The above line of code can be used in a node's purchaseFunction to unlock the automator through the skill tree (see Example Automator Node below). The automator is not much use without any gems or stones, though, so you will probably want to add at least one of each at the same time the automator is unlocked.

Creating Automator Gems

Skill Gems

Gems that automate skills can be created using the addSkillGem function, which only requires a unique string id and the the skill it will automate.

	
	CH2.currentCharacter.automator.addSkillGem("gem_exampleSkill", exampleSkill);
	

The above will add a new gem, "gem_exampleSkill", to the current character that is linked to the example skill created in the Creating a Skill section. Gems need to be added within a node's setupFunction, which is run when the character is created. If a gem has been created and added to the character's list of possible gems, it can later be unlocked and added to the automator tab using the unlockGem function:

	
	CH2.currentCharacter.automator.unlockGem("gem_exampleSkill");
	

The above line of code can be used in a node's purchaseFunction to unlock the gem that was added in the setupFunction. See Creating a Level Graph for more information about creating nodes.

Custom Gems

You can create other kinds of gems using the addGem function in the onSetup function:

	
	public function addGem(id:String, name:String, iconId:Number, description:String, onActivate:Function, canActivate:Function, cooldownMs:Number = 0) : void
	

The id is a unique string id like before, the name is the in-game name of the stone that will show on tooltips, the iconId is the id for the gem's graphical icon (currently not working for mods, you can just put null or any random number and it will use a default "?" icon for now), the description is the tooltip description of the stone, onActivate is the function where you will write the code that will execute when the gem is activated by the automator, canActivate is the function where you will write the code to set the conditions needed for your gem to be able to activate (should return a boolean), and cooldownMs is an optional field if you want to give your gem a cooldown in milliseconds.

Once added, custom gems can be unlocked using the same unlockGem function as above.

Creating Automator Stones

Cooldown Stones

Cooldown stones are stones like the "4s Cooldown" stone which activate every time their cooldown is up. These can be created using the addCooldownStone function which only requires a unique string id and the desired cooldown in milliseconds:

	
	CH2.currentCharacter.automator.addCooldownStone("stone_ExampleCooldown", 5000);
	

The above will add a new stone, "stone_ExampleCooldown", and set its cooldown to 5 seconds. Like gems, stones need to be added within a node's setupFunction, which is run when the character is created. If a stone has been created and added to the character's list of possible stones, it can later be unlocked and added to the automator tab using the unlockStone function:

	
	CH2.currentCharacter.automator.unlockStone("stone_ExampleCooldown");
	

The above line of code can be used in a node's purchaseFunction to unlock the stone that was added in the setupFunction. See Creating a Level Graph for more information about creating nodes.

Custom Stones

You can create other kinds of stones using the addStone function:

	
	public function addStone(id:String, name:String, label:String, description:String, onActivate:Function, cooldownMs:Number = 16) : void
	

The id is a unique string id like before, the name is the in-game name of the stone that will show on tooltips, the label is the text that will be displayed on the stone in the automator panel, the description is the tooltip description of the stone, onActivate is the function where you will write the code to set the conditions needed for your stone to be able to activate (should return a boolean), and cooldownMs is an optional field if you want the cooldown of your custom stone to be different from the default 16 milliseconds.

Once added, custom stones can be unlocked using the same unlockStone function as above.

Example Automator Node

See ExampleCharacterMain.as in the Clicker Heroes 2\mods\examples folder for a mod made using the code described here.

Here is an example node that will unlock the automator, add a gem to automate Example Skill, add a 5 second cooldown stone, and then unlock the gem and stone. See Creating a Level Graph for more information about creating nodes and using the setupFunction:

	
	"AN": { 
		"name": "Automator Examples",
		"tooltip": "Unlocks the Automator, Example Skill Gem, and Example Cooldown Stone" ,
		"flavorText": null,
		"alwaysAvailable": false,
		"setupFunction": function() {    
			CH2.currentCharacter.automator.addCooldownStone("stone_ExampleCooldown", 5000);
			CH2.currentCharacter.automator.addSkillGem("gem_exampleSkill", exampleSkill);
		},
		"purchaseFunction": function() {
			CH2.currentCharacter.onAutomatorUnlocked();
			CH2.currentCharacter.automator.unlockStone("stone_ExampleCooldown");
			CH2.currentCharacter.automator.unlockGem("gem_exampleSkill");
		},
		"icon": ""
	}
	

Adding Automator and Components without the Skill Tree

You can add and unlock the automator, gems, and stones for a character by default in onCharacterCreated, if you don't want to have them unlocked through the skill tree.

If you want to add a skill gem, the required skill will need to be already added to the character for the gem to work, see the Adding Skills section for more information.

This is also a good way to add new gems and stones to pre-existing characters such as Cid. You will want to add a mod dependency when adding new components this way, so that character saves created with the mod installed will indicate that the mod is required to load the save (see the Mod Dependencies section for more information).

Here is an example of how to add the skill gem and cooldown stone examples from above to Cid using onCharacterCreated, assuming the skill exampleSkill has already been created and added (See Creating a Skill and Editing Pre-Existing Characters for examples of how to do this):

	
	public function onCharacterCreated(characterInstance:Character):void 
	{
		if (characterInstance.name == "Helpful Adventurer") 
		{
			characterInstance.modDependencies[MOD_INFO["name"]] = true;
		
			characterInstance.automator.addSkillGem("gem_exampleSkill", exampleSkill);
			characterInstance.automator.addCooldownStone("stone_exampleCooldown", 5000); 
		
			if (!characterInstance.getTrait("Example Components Added")) 
			{
				characterInstance.automator.unlockGem("gem_exampleSkill");
				characterInstance.automator.unlockStone("stone_exampleCooldown");
				
				characterInstance.setTrait("Example Components Added",1);
			}
		}
	}
	

The above uses a trait to make sure that the gem and stone only get unlocked once, otherwise they will get unlocked again every time the game is loaded and the character will keeping getting more stones and gems. To learn more about traits see Creating and Using Traits.

Note: You may need to restart the game once after adding the mod for automator components added this way to show up for the first time.