Skip to content

How To: Clicker Weapons and Click Effects

Barometz edited this page Aug 10, 2022 · 4 revisions

This page walks you through the process of creating a clicker weapon.

DISCLAIMER
This page assumes you know how to mod items into Terraria. For the basics, please read this tModLoader guide.

DISCLAIMER
This page assumes you've already followed the first steps to add Clicker Class compatibility to your own mod. If not, please read this guide.

Step-By-Step

NOTE
You can find the full code for a basic clicker weapon here.

Step 1:

Create a file and a ModItem class in it.

Step 2:

Override SetStaticDefaults in it and use the RegisterClickerWeapon method:

public override void SetStaticDefaults()
{
	//You NEED to call this in SetStaticDefaults to make it count as a clicker weapon. also sets the default tooltip
	ClickerCompat.RegisterClickerWeapon(this);

	DisplayName.SetDefault("Example Clicker");
}

What this does is make the game know it belongs to the Clicker Class archetype, and is also a clicker weapon. Without it, the item will not behave like a clicker weapon (impacts too many things to list).

Step 3:

Override SetDefaults in it and use the SetClickerWeaponDefaults method:

public override void SetDefaults()
{
	//This call is mandatory as it sets common stats like useStyle which is shared between all clickers
	ClickerCompat.SetClickerWeaponDefaults(Item);

	//Other item stats assigned here
}

What this does is make the weapon actually behave like all other clicker weapons (same use style, same animation time etc.), and most importantly, makes it spawn the regular "damaging" clicker projectile responsible for damage. You should usually follow this up with assigning width, height, damage, knockback etc. yourself.

Step 4:

To make the clicker weapon unique, you can modify certain stats in SetDefaults as well; a full list can be found in the ClickerCompat class in the Item Calls region. Example: ClickerCompat.SetRadius(Item, 0.3f); will give the clicker a default radius of 30 pixels (in addition to the default 100 pixel radius the player has)


Advanced: Click Effects

Almost every clicker in Clicker Class has a special effect that occurs after a certain amount of clicks. You can add these to any clicker weapon (even more than one), and also enable them through accessories etc.

Using a Click Effect

To add an effect to a clicker, like in Step 4 you write ClickerCompat.AddEffect(Item, "ModName:InternalName");, where "ModName:InternalName" can be any effect from any mod that adds effects. Clicker Class provides multiple effects found here (Registered Effects), accessed via the ClickerClass mod prefix, and their name as the suffix, like this: "ClickerClass:Embrittle".

You can also make use of the fact that these effects can simply be toggled just like other things on a player (aswell as checking if they are enabled). Use ClickerCompat.EnableClickEffect(player, "ModName:InternalName") and ClickerCompat.HasClickEffect(player, "ModName:InternalName"). See ExampleClickerAccessory for basic usage.

Adding custom Click Effects

You can add your own effects to the game simply by calling ClickerCompat.RegisterClickEffect in a suitable hook (most often SetStaticDefaults). For example:

//using Microsoft.Xna.Framework;
//using Terraria;

string uniqueName = ClickerCompat.RegisterClickEffect(Mod, "ExampleEffect", "Mini Clickers", "Creates 5 Mini Clickers around the cursor for 20% damage", 6, Color.Red, delegate (Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, int type, int damage, float knockBack)
{
	Main.PlaySound(SoundID.Chat, (int)position.X, (int)position.Y, -1);
	for (int i = 0; i < 5; i++)
	{
		Projectile.NewProjectile(source, position + 20 * Vector2.UnitX.RotatedByRandom(MathHelper.TwoPi), Vector2.Zero, ModContent.ProjectileType<MiniClicker>(), (int)(damage * 0.2f), 0f, Main.myPlayer);
	}
},
preHardmode: true);

This registers the effect so you can use it anywhere you want. It is recommended to assign uniqueName (which will have the "ModName:InternalName" format) somewhere so you can reference it easier without manually having to write the string each time (this is important to do if the uniqueName representation changes in a future update!).


Clone this wiki locally