• PC NEWS: 1.4.2.3 update is out! More info here. Report bugs here
  • CONSOLE 1.4 NEWS: The current plan is to have Terraria: Journey's End out for Xbox and PlayStation in Q3 2021 (Jul-Sep). Switch will follow shortly afterwards. More info here. Stay up to date with console news here
  • MOBILE NEWS: Stay up to date with the latest mobile news here. Report mobile bugs here

tModLoader Returning to Modding, Have Some Questions I Could Not Answer

Long ago (last year), I tried my hand at making a mod. It was a very basic start, adding a few recolored weapons and some budget enemies. Now, silly old me managed to delete the files associated with the mod source, and stupid old me forgot to back them up. Whoops! So, I had the genius plan to just download my old mod and extract it. Unfortunately, my past self did that annoying thing where the files don't actually get extracted. So, I'm back to working from scratch. So far, I've managed to remake custom pets that use other pets as a base, and I've got two NPCs I managed to make that work as a good starting point. Now, I hit a snag with my work; I'm still just as dumb when it comes to coding as I was last year. So, I have a few small question I would hope for help on.

1. Custom Enemy, Custom Drops
I made a "ModGlobalNPC.cs" file, and I wanted to make an enemy drop items based on chance. My example was using the Demon Eye's drops of a Lens at 33.33% and a Black Lens at 1%. Now, I've tried to understand the method of doing this through the official tmodloader github as well as posts on the forums, but I have yet to get it to work. Here's what I have;

Code:
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Harblesnargits_Many_Pets.NPCs
{
  public class Harblesnargits_Many_Pets : GlobalNPC
  {
  public override void NPCLoot()
  {
  if (npc.type == mod.NPCType("enemy_eye_01"))
  {
  if (Main.rand.Next(33) == 0)
  Item.NewItem(npc.getRect(), ItemID.Lens, 1);
       }
  }
   }
}

This managed to unsurprisingly fail to work. What do I need to change to let my "enemy_eye_01" actually drop items?

2. Multiple Enemies, one .cs
Touching on the above, I'm not limited to one NPC. How would I properly edit the file to have multiple lines for separate monsters? I ASSUME that I add another "if (npc.type) line, along with accompanying parenthesis and such, but I'd like to be certain before spending an hour doing it wrong and never getting it right.

3. Spawn Chance
In examplemod provided in the TModLoader help thread, the "partyzombie" has a spawn chance of 0.5f. I used the same for the above "enemy_eye_01", but I get WAAAAAY too many of my monster spawning. Like, no other Demon Eyes spawn because it keeps picking mine. How does this number work?

4. Pet Projectile Frames
I've got a few pets that use extra sprites because I'm lazy and just copy pasted them. Thing is, why should I use four frames when two is all I want?

Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Harblesnargits_Many_Pets.Projectiles.Pets
{
   public class pet_Ocram_01 : ModProjectile
   {
     public override void SetStaticDefaults()
     {
       DisplayName.SetDefault("Baby Ocram");
       Main.projFrames[projectile.type] = 4;
       Main.projPet[projectile.type] = true;
     }

     public override void SetDefaults()
     {
       projectile.CloneDefaults(ProjectileID.ZephyrFish);
       aiType = ProjectileID.ZephyrFish;
     }

     public override bool PreAI()
     {
       Player player = Main.player[projectile.owner];
       player.zephyrfish = false; // Relic from aiType
       return true;
     }

     public override void AI()
     {
       Player player = Main.player[projectile.owner];
       MyPlayer modPlayer = player.GetModPlayer<MyPlayer>(mod);
       if (player.dead)
       {
         modPlayer.pet_Ocram_01 = false;
       }
       if (modPlayer.pet_Ocram_01)
       {
         projectile.timeLeft = 2;
       }
     }
   }
}

My example here shows that I'm using the Zephyr Fish as a base. However, lazy little me wants to only use two frames. I've tried changing "Main.projFrames[projectile.type] = 4;" to 2, and using a different sprite to test, but it still shows all four frames. What should I do in this case?


------------------------

Any assistance would be greatly appreciated. I spent a few hours getting to where I am, but I've gotten stuck as far as I am unfortunately.
 
Top Bottom