-
Notifications
You must be signed in to change notification settings - Fork 0
Mod Emote
Town NPCs will talk to each other and the player by displaying an emote above them. All Town NPCs in vanilla have an emote of themselves. Let's make one for our Town NPC.
We need to create a sprite sheet for our emote. Each frame of the emote is going to be 34x28 (real) pixels and we'll want at two frames for our emote. Below is the sprite sheet that we will be using for our Tutorial Town NPC Emote:

Here is a template to help better visualize how the emote will fit on the emote bubbles. You'll want to make sure your emote doesn't overlap or extend past the outside of the bubble's outline.

We are going to create a new class for our Emote that inherits ModEmoteBubble. For this tutorial, our class will be placed in TownNPCGuide/Content/EmoteBubbles. This code example creates a base class that can support many Town NPC emotes. The actual Town NPC emote inherits the base class and just needs to change which row it is on on the texture.
// This abstract class is used for town NPC emotes quick setup.
public abstract class ModTownEmote : ModEmoteBubble
{
// Redirecting texture path.
// Change this string to the path of your texture.
public override string Texture => "TownNPCGuide/Content/EmoteBubbles/TutorialTownNPCEmote";
public override void SetStaticDefaults() {
// Add NPC emotes to "Town" category.
AddToCategory(EmoteID.Category.Town);
}
/// <summary>
/// Which row of the sprite sheet is this NPC emote in?
/// This is used to help get the correct frame rectangle for different emotes.
/// </summary>
public virtual int Row => 0;
// You should decide the frame rectangle yourself by these two methods.
public override Rectangle? GetFrame() {
return new Rectangle(EmoteBubble.frame * 34, 28 * Row, 34, 28);
}
// Do note that you should never use EmoteBubble instance as the GetFrame() method above
// in "Emote Menu Methods" (methods with -InEmoteMenu suffix).
// Because in that case the value of EmoteBubble is always null.
public override Rectangle? GetFrameInEmoteMenu(int frame, int frameCounter) {
return new Rectangle(frame * 34, 28 * Row, 34, 28);
}
}
// This is a showcase of using the same texture for different emotes.
// Command names of these classes are defined using .hjson files in the Localization/ folder.
// This is the actual emote for our Town NPC. It inherits our base class and just needs to change which row it is on on the texture.
public class TutorialTownNPCEmote : ModTownEmote
{
public override int Row => 0;
}
// With this method, we can create several emotes for different Town NPCs with only using a single texture.
/*
public class DifferentTownNPCEmote : ModTownEmote
{
public override int Row => 1;
}
public class OtherTownNPCEmote : ModTownEmote
{
public override int Row => 2;
}
*/Next, we need to give our emote a command name by adding it to our localization file.
Mods: {
TownNPCGuide: {
# All other key value pairs have been omitted for this example.
Emotes: {
# The best practice would be to prefix the command with the name of your mod.
# That way two mods can't add the same command for different emotes.
# Example:
# Your mod is called "Awesome Farming Mod" and your Town NPC is called "Farmer".
# You could make the command "afmfarmer"
# This command is verbose just because the name of this tutorial mod and tutorial town NPC names are long.
TutorialTownNPCEmote.Command: tnpcgtutorialtownnpc
}
}
}Lastly, we need to add another NPCID.Sets to our Town NPC to register the emote to our Town NPC. That way other Town NPCs can use this emote when talking about our Town NPC.
// In SetStaticDefaults
NPCID.Sets.FaceEmote[Type] = ModContent.EmoteBubbleType<TutorialTownNPCEmote>();This is not the only way to set up an emote. Check Example Mod for more ModEmote examples.
- Previous page: Skeleton Merchant
- Next page: Preferred Emotes
Basic Guides
Intermediate Guides
Advanced Guides
- Preliminaries and What are Town NPCs?
- Spriting
- Create Your Town NPC's Class
- Spawn Condition
- Names
- Chat
- Buttons
- Shop
- Attacking
- Bestiary
- Happiness
- Profile
- Gore
- Misc
- Editing Vanilla NPCs with Global NPC