Creating a custom pet/pets?

jessicaksch

Terrarian
Hey guys, I love the game but would really love for myself to have two pet cats ingame :(

I found a youtube video about it:

Creating custom pets:


I have done some modding with "stardew Valley" and Minecraft, and I love Terraria and would love to get my own custom pet.

I found a video where someone goes through the steps, I just don't understand how he got the scripts that are in the folder :( I have already drawn my own animations and have modloader.
 
ooh ok, so just copy the files from the youtube vid into the Modloader folder?


Thank you so much! But I came with another problem: aparently someone said this vid is about flying pets, I don't want it flying around and also he said that this mod doesn't work anymore? Can someone confirm this?
 
The videos are about the older tModLoader version, there's some changes in the new one. The wiki is a good place to look for examples, especially the Example Mod. There's also examples for pets.
Also, if you haven't already, I advise you to start your Terraria modding career here, to know where to put what and to learn the basics.
 
Hi, thank you so much, the Example Mod really helped though there is one thing that confused me: the player.cs.

Also, I want to create an item dropped by zombies to spawn my pet. I already created a projectiles folder and script and png, a pet buff and script and png and Item script and png.

I created an "item" and called it PetCall and made the script connected to it.

I am just confused about the files before going into the "ExampleMod" folder. the player.cs file and the examplemod.cs files I think are just relevant to my mod specifically. How do I modify them to just be relevant as a pet mod without the extras?
 
Hm, I've actually never made a pet myself, but I'll try to help you as much as I can.

For the ExamplePlayer.cs, you should consult this part of the turotial video.
So delete everything except the lines you need and it'll look like this:
Code:
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;
using ExampleMod.NPCs.PuritySpirit;
using Terraria.ModLoader.IO;
using Terraria.GameInput;
namespace ExampleMod
{
public class ExamplePlayer : ModPlayer
{
private const int saveVersion = 0;
public bool examplePet = false;

public override void ResetEffects()
{
examplePet = false;
}
}
}
That should bee enough, I guess. I not, try adding the lines from the video.

If you downloaded the Mod Skeleton from here, you should already have a .cs file with your mod name that should suffice, the only thing left is letting an enemy drop your item.

For that, you need GlobalNPC.cs in your "NPCs" subfolder with this:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace YourModName.NPCs
{
   public class GlobalNPC : GlobalNPC
   {

  public override void NPCLoot(NPC npc)
     {
  if (npc.type == NPCID.Zombie && Main.rand.Next(100) == 0) { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("PetCall")); }
}
}
The number after Main.rand.Next is your drop chance, so in this example 1 in 101 (cause is starts counting at 0).

I hope that's everything you need! :)

edit: one tip, if you haven't already, I'll suggest you to use jopojelly's Cheat Sheet Mod. You can use it to spawn your item(s) via the mod's menu, so you won't have to find it in-game to see if it works correctly.
 
Last edited:
ok, so I made a few changes so you can see how for example I set it all up:

in my "Mod Sources" folder, I have my mod called "Blue":

In that folder I have:

Folders:

.vs ,bin, Buffs, Items, NPC , obj , Projectiles,

Files:

App.config , Blue.cs , Blue.csproj, Blue.csproj.user , Blue.sln , build.txt , description.txt , MyPlayer.cs


BUFFS folder: the png called "PetBuff" and the cs file called "PetBuff":

Code:
using Terraria;
using Terraria.ModLoader;
namespace YourModName.Buffs
{
    public class PetBuff : ModBuff
    {
        public override void SetDefaults()
        {
            Main.buffName[Type] = "Blue";
            Main.buffTip[Type] = "This is a Cool Pet";
            Main.buffNoTimeDisplay[Type] = true;
            Main.vanityPet[Type] = true;
        }
        public override void Update(Player player, ref int buffIndex)
        {
            player.buffTime[buffIndex] = 18000;
            player.GetModPlayer<MyPlayer>(mod).Pet = true;
            bool petProjectileNotSpawned = player.ownedProjectileCounts[mod.ProjectileType("Blue")] <= 0;
            if (petProjectileNotSpawned && player.whoAmI == Main.myPlayer)
            {
                Projectile.NewProjectile(player.position.X + (float)(player.width / 2), player.position.Y + (float)(player.height / 2), 0f, 0f, mod.ProjectileType("PetName"), 0, 0f, player.whoAmI, 0f, 0f);
            }
        }
    }
}



ITEMS folder : the png called "PetCall" and the cs file called "PetCall":

Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace YourModName.Items
{
    public class PetCall : ModItem
    {
        public override void SetDefaults()
        {
            item.CloneDefaults(ItemID.ZephyrFish);
            item.name = "Blue";
            item.toolTip = "Summons a Cool Pet to follow you";
            item.shoot = mod.ProjectileType("Blue");
            item.buffType = mod.BuffType("PetCall");
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.DirtBlock, 1);
            recipe.AddTile(null, "WBName");
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
        public override void UseStyle(Player player)
        {
            if (player.whoAmI == Main.myPlayer && player.itemTime == 0)
            {
                player.AddBuff(item.buffType, 3600, true);
            }
        }
    }
}


PROJECTILES folder: a png called "Blue" of the pet's movement, and the cs file called "Blue":

Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace Blue.Projectiles
{
    public class Blue : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(ProjectileID.Bunny);
            projectile.name = "Blue";
            aiType = ProjectileID.Bunny;
            Main.projFrames[projectile.type] = 4;
            Main.projPet[projectile.type] = true;
        }
        public override bool PreAI()
        {
            Player player = Main.player[projectile.owner];
            player.Bunny = false;
            return true;
        }
        public override void AI()
        {
            Player player = Main.player[projectile.owner];
            MyPlayer modPlayer = player.GetModPlayer<MyPlayer>(mod);
            if (player.dead)
            {
                modPlayer.Pet = false;
            }
            if (modPlayer.Pet)
            {
                projectile.timeLeft = 2;
            }
        }
    }
}



Thanks again!
 
In the PetBuff and PetCall codes, you'll have to change your namespace accordingly, to Blue.Buffs and Blue.Items (maybe in the GlobalNPC.cs, too)

And you seem to still use some things that won't work well with the new ModLoader, like item.name and projectile.name, see the Migration Guide or the Example Mod for how it works now.

Apart from that, I guess it looks good, just go into your game, into mod sources and build the mod. If there are any errors, try working through them until they're no errors left ;)

You can just Alt+Tab out of the game, change your code, save it, go into the game and build again, no need to exit the game first.
 
sweet I've been doing that but thank you so much, I was not sure which lines still worked or not or what was "allowed" to be changed :)

I'll give it a try when I get home tonite.
 
OK, I've been working on the code and now I get this error:

The game has crashed!
Could not find a part of the path 'C:\Program Files (x86)\Steam\steamapps\common\Terraria\ModCompile\tModLoaderMac.exe'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Mono.Cecil.ModuleDefinition.GetFileStream(String fileName, FileMode mode, FileAccess access, FileShare share)
at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
at Terraria.ModLoader.ModCompile.GetTerrariaReferences(String tempDir, Boolean forWindows)
at Terraria.ModLoader.ModCompile.CompileMod(BuildingMod mod, List`1 refMods, Boolean forWindows, Byte[]& dll, Byte[]& pdb)
at Terraria.ModLoader.ModCompile.Build(BuildingMod mod, IBuildStatus status)
at Terraria.ModLoader.ModCompile.Build(String modFolder, IBuildStatus status)
at Terraria.ModLoader.ModLoader.<>c.<BuildMod>b__65_0(Object _)
 
ok sweet, thank you so much for your help! I'm making a mod for a pet dragon. Is there any way I can find out how to draw my dragon's animation in squence of animation? Everytime ingame the pet seems to draw blanks when climbing hills etc...
 
hey I just wanted to find out if the item drops from a zombie, so would I have to change it to this for it to drop 100%?

(npc.type == NPCID.Zombie && Main.rand.Next(100) == 100)
 
No, that wouldn't actually change anything :D
The number in brackets is drop chance, that one after that means that if the generated number is equal to that (100) the item drops. doesn't matter if its 100, 0, or 52, all of those numbers are generated randomly.

If you want 100% drop chance, you can just delete the random part altogether: (npc.type == NPCID.Zombie)
That's good enough.
 
No, that wouldn't actually change anything :D
The number in brackets is drop chance, that one after that means that if the generated number is equal to that (100) the item drops. doesn't matter if its 100, 0, or 52, all of those numbers are generated randomly.

If you want 100% drop chance, you can just delete the random part altogether: (npc.type == NPCID.Zombie)
That's good enough.

oh how would that look in the coding? Somehow it still isn't dropped by zombies and I rebuilt and reloaded the mod. I can still find it when cheating but it won't drop by zombies:



Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Dragon.NPCs
{
   public class DragonGlobalNPC : GlobalNPC
   {

  public override void NPCLoot(NPC npc)
     {
  if (npc.type == NPCID.Zombie) { Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("PetCall")); }
}
}
}
 
Last edited:
The code looks solid, there shouldn't be any problems as far as I can see.

Are you positive the item that should be dropped is named "PetCall"? That's the only thing that comes to mind.
 
Back
Top Bottom