Standalone [1.3] tModLoader - A Modding API

It's the entire code of that specific weapon.
BTW what is a directive?

A directive can be a lot of things. I'll only explain the using directive, and only in the way you'll be using it, because directives are complicated and I don't want to confuse anyone.

Essentially the using directive allows you to use the types of a specific namespace without having to type that entire namespace. For instance, if you want to use the Vector3 type of the XNA Framework, you could type this:
Code:
namespace MyNamespace
{
    class MyClass
    {
        static void Main()
        {
            Microsoft.Xna.Framework.Vector3 vector = new Microsoft.Xna.Framework.Vector3(5, 3, 1);
        }
    }
}
As you can see, this is a bit of hassle if you have to type Microsoft.Xna.Framework every time you want to use one of those types, not to mention it clutters your code. Thankfully, you can use the using directive to omit that. Observe.
Code:
using Microsoft.Xna.Framework;

namespace MyNamespace
{
    class MyClass
    {
        static void Main()
        {
            Vector3 vector = new Vector3(5, 3, 1);
        }
    }
}
What's happening in your code is that you are using the types NPC and Player, which are from the Terraria namespace, but because you're not preceding them by the namespace name (Terraria.NPC and Terraria.Player) and aren't using the Terraria namespace (using Terraria;), the compiler can't find the types you're looking for.

You can easily solve this by adding using Terraria; to the top of your code (has to be before any other elements, or you'll get another error). In future, it's good practice to add these to the top of your code every time you make a new class.
Code:
// Thes first two are pretty much mandatory, unless you're making a static class for certain calculations.
using Terraria; // This is all the stuff Terraria uses.
using Terraria.ModLoader; // This is all the stuff tModLoader uses.
using Terraria.ID; // This one you need if you want to use the IDs from items or NPCs, not always necessary.
using Microsoft.Xna.Framework; // This one you almost always need for AIs, because it contains the Vector3 type, but isn't necessary for simple things like items.
using System; // I personally like this one, mainly for the Math class, but if you don't know what it does, there's little point in using it.
I'd advise sticking to just the first three, and if you need a certain type, just search for it in the MSDN and look for which namespace it's in.
 
How would a make a gun turn any type of bullet into a specific modded bullet? (Like how the Uzi turns any bullets into high velocity bullets).
 
in SetDefaults I have this
Code:
            npc.aiStyle = 3;
            animationType = NPCID.Zombie;
            Main.npcFrameCount[npc.type] = 3;
            aiType = NPCID.Skeleton;

and for FindFrame(int frameHieght)
I have
Code:
            npc.frameCounter -= 1f;
            npc.frameCounter %= Main.npcFrameCount[npc.type];
            int frame = (int)npc.frameCounter;
            npc.frame.Y = frame * frameHeight;

            npc.spriteDirection = npc.direction;

my sprite
IS 3 frames

I've tried making aiType = NPCID.Zombie
but that just makes it always a bar instead of switching
 
spawnInfo.player.ZoneDungeon

You might not have the right amount of frames for the animationType you are using.


If you are using the ExampleWorld example, change the
WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, Main.maxTilesY),
to
WorldGen.genRand.Next(Main.maxTilesY - 200, Main.maxTilesY),

Or, for ash blocks, you can bring out those random numbers to variables, then check Main.tile[x,y].type == TileID.Ash in that for loop.


In the npc's SetDefaults: music = this.GetSoundSlot(SoundType.Music, "Sounds/Music/DriveMusic");
[doublepost=1465024767,1465024651][/doublepost]
I'm not really sure about the moving the player, maybe change player.Velocity. Anyway, I'd start out by copying all the parameters for the arkhalis projectile and item from the spreadsheets on the github wiki, see what you can get working.


Thank you so much!

That actually helps out a lot for my ore generation in the Jungle as well. Since I could just change the ID to Mud for that :D
 
How would a make a gun turn any type of bullet into a specific modded bullet? (Like how the Uzi turns any bullets into high velocity bullets).

jopojelly made a really good post about that here.
in SetDefaults I have this
Code:
            npc.aiStyle = 3;
            animationType = NPCID.Zombie;
            Main.npcFrameCount[npc.type] = 3;
            aiType = NPCID.Skeleton;

and for FindFrame(int frameHieght)
I have
Code:
            npc.frameCounter -= 1f;
            npc.frameCounter %= Main.npcFrameCount[npc.type];
            int frame = (int)npc.frameCounter;
            npc.frame.Y = frame * frameHeight;

            npc.spriteDirection = npc.direction;

my sprite
IS 3 frames

I've tried making aiType = NPCID.Zombie
but that just makes it always a bar instead of switching
Wild guess, but the negative might be messing with the frame. Try += (or ++) instead of -=.
 
Hello everyone! In my mod drawn texture that depends by the variable. On client it's okay, but on server drawn is always the same texture. (I have counter for variable.)
 
New error, yaaaaaay.
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace CakeMod.Items.Weapons
{
    public class IncendiaryBullet : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Incendiary Bullet";
            item.damage = 10;
            item.ranged = true;
            item.width = 8;
            item.height = 8;
            item.maxStack = 999;
            item.toolTip = "ARGHHHH IT'S SO HOT!";
            item.consumable = true;
            item.knockBack = 1.5f;
            item.value = 10;
            item.rare = 2;
            item.shoot = mod.ProjectileType("IncendiaryBullet");
            item.shootSpeed = 16f;
            item.ammo = ProjectileID.Bullet;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.MusketBall, 70);
            recipe.AddIngredient(ItemID.HellstoneBar, 1);
            recipe.AddTile(null, "ExampleWorkbench");
            recipe.SetResult(this, 50);
            recipe.AddRecipe();
        }

        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(BuffID.OnFire, 5);
        }

    }
}

c:\Users\Administrator\Documents\My Games\Terraria\ModLoader\Mod Sources\CakeMod\Items\Weapons\R20S.cs(41,55) : error CS0246: The type or namespace name 'Vector2' could not be found (are you missing a using directive or an assembly reference?)
 
New error, yaaaaaay.
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace CakeMod.Items.Weapons
{
    public class IncendiaryBullet : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Incendiary Bullet";
            item.damage = 10;
            item.ranged = true;
            item.width = 8;
            item.height = 8;
            item.maxStack = 999;
            item.toolTip = "ARGHHHH IT'S SO HOT!";
            item.consumable = true;
            item.knockBack = 1.5f;
            item.value = 10;
            item.rare = 2;
            item.shoot = mod.ProjectileType("IncendiaryBullet");
            item.shootSpeed = 16f;
            item.ammo = ProjectileID.Bullet;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.MusketBall, 70);
            recipe.AddIngredient(ItemID.HellstoneBar, 1);
            recipe.AddTile(null, "ExampleWorkbench");
            recipe.SetResult(this, 50);
            recipe.AddRecipe();
        }

        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(BuffID.OnFire, 5);
        }

    }
}

c:\Users\Administrator\Documents\My Games\Terraria\ModLoader\Mod Sources\CakeMod\Items\Weapons\R20S.cs(41,55) : error CS0246: The type or namespace name 'Vector2' could not be found (are you missing a using directive or an assembly reference?)
Show us the File "R20S.cs"
 
Code:
public override void PostWorldGen()
{
if (downedDesertScourge = true)
{
Main.NewText("The underground is shimmering with blue light!", Color.Blue.R, Color.Blue.G, Color.Blue.B);
for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)
{
WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceHigh, Main.maxTilesY), (double)WorldGen.genRand.Next(2, 3), WorldGen.genRand.Next(2, 4), mod.TileType("AerialiteOre"), false, 0f, 0f, false, true);
}
}
if (downedSlimeGod = true)
{
Main.NewText("Ancient ice ore has formed in the caverns!", Color.Purple.R, Color.Purple.G, Color.Purple.B);
for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++)
{
WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)(Main.maxTilesY * .5f), (int)(Main.maxTilesY * .8f)), (double)WorldGen.genRand.Next(2, 3), WorldGen.genRand.Next(2, 4), mod.TileType("CryonicOre"), false, 0f, 0f, false, true);
}
}

Alright, my ore generates when these two bosses are defeated. But the message doesn't appear when they are defeated o_O

Could I just write the message code in the boss NPC files in the NPCLoot method, like where it changes the boolean "downedBossName" from false to true?

EDIT: Yup, that did it.
 
Last edited:
How can I slow down the enemy's animation.
right now the legs are moving super fast, and I the enemy is moving at the right speed, but looks slower because of how fast the legs are moving


Also, How can I make homing projectiles
and How can I make a weapon leach life
 
New error, yaaaaaay.
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace CakeMod.Items.Weapons
{
    public class IncendiaryBullet : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Incendiary Bullet";
            item.damage = 10;
            item.ranged = true;
            item.width = 8;
            item.height = 8;
            item.maxStack = 999;
            item.toolTip = "ARGHHHH IT'S SO HOT!";
            item.consumable = true;
            item.knockBack = 1.5f;
            item.value = 10;
            item.rare = 2;
            item.shoot = mod.ProjectileType("IncendiaryBullet");
            item.shootSpeed = 16f;
            item.ammo = ProjectileID.Bullet;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.MusketBall, 70);
            recipe.AddIngredient(ItemID.HellstoneBar, 1);
            recipe.AddTile(null, "ExampleWorkbench");
            recipe.SetResult(this, 50);
            recipe.AddRecipe();
        }

        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(BuffID.OnFire, 5);
        }

    }
}

c:\Users\Administrator\Documents\My Games\Terraria\ModLoader\Mod Sources\CakeMod\Items\Weapons\R20S.cs(41,55) : error CS0246: The type or namespace name 'Vector2' could not be found (are you missing a using directive or an assembly reference?)

Vector2 is a XNA type, so you'll want to add using Microsoft.Xna.Framework; to the top of the R20S class.
 
Seeing all these bug reports i'm glad i haven't updated yet, besides not all the mods i have are supported anymore ;-;
 
Seeing all these bug reports i'm glad i haven't updated yet, besides not all the mods i have are supported anymore ;-;
where are not many Bugs
There are more Fixes than Bugs
Mostly People only post Bug Reports from Bugs that are already known
 
Pls can you make it that not just steam users can use it? If you can Thanks!

@Jeckel has been looking into (looking into, mind you) a GOG version, he might be able to tell you more.

If you're referring to other platforms, then I'm afraid that's not possible and/or allowed in some cases.
 
c:\Users\John\Documents\my games\Terraria\ModLoader\Mod Sources\Mutation\Items\MutantBunny.cs(7,30) : error CS0115: 'Mutation.Items.MutationBunny.SetDefaults()': no suitable method found to override

c:\Users\John\Documents\my games\Terraria\ModLoader\Mod Sources\Mutation\Items\MutantBunny.cs(28,30) : error CS0115: 'Mutation.Items.MutationBunny.AddRecipes()': no suitable method found to override

c:\Users\John\Documents\my games\Terraria\ModLoader\Mod Sources\Mutation\Items\MutationBottle.cs(7,30) : error CS0115: 'Mutation.Items.MutationBottle.SetDefaults()': no suitable method found to override

c:\Users\John\Documents\my games\Terraria\ModLoader\Mod Sources\Mutation\Items\MutationBottle.cs(13,30) : error CS0115: 'Mutation.Items.MutationBottle.AddRecipes()': no suitable method found to override
I got these errors. What do they want?
 
c:\Users\John\Documents\my games\Terraria\ModLoader\Mod Sources\Mutation\Items\MutantBunny.cs(7,30) : error CS0115: 'Mutation.Items.MutationBunny.SetDefaults()': no suitable method found to override

c:\Users\John\Documents\my games\Terraria\ModLoader\Mod Sources\Mutation\Items\MutantBunny.cs(28,30) : error CS0115: 'Mutation.Items.MutationBunny.AddRecipes()': no suitable method found to override

c:\Users\John\Documents\my games\Terraria\ModLoader\Mod Sources\Mutation\Items\MutationBottle.cs(7,30) : error CS0115: 'Mutation.Items.MutationBottle.SetDefaults()': no suitable method found to override

c:\Users\John\Documents\my games\Terraria\ModLoader\Mod Sources\Mutation\Items\MutationBottle.cs(13,30) : error CS0115: 'Mutation.Items.MutationBottle.AddRecipes()': no suitable method found to override
I got these errors. What do they want?
Show ous the Code
 
Code:
using Terraria.ModLoader;

namespace Mutation.Items
{
    public class MutationBottle
    {
        public override void SetDefaults()
        {
            base.SetDefaults();
            item.name = "Mutation Bottle";
            item.toolTip = "Used to make fun mutant things.";
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(null, Bottle, 5);
            recipe.AddIngredient(ItemID.Mushroom, 10);
            recipe.AddIngredient(ItemID.ViciosMushroom, 2);
            recipe.AddIngredient(ItemID.TissueSample, 2);
            recipe.AddTile(null, DyeVat);
            recipe.SetResult(this, 5);
            recipe.AddRecipe();
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(null, Bottle, 5);
            recipe.AddIngredient(ItemID.Mushroom, 10);
            recipe.AddIngredient(ItemID.VileMushroom, 2);
            recipe.AddIngredient(ItemID.ShadowScale, 2);
            recipe.AddTile(null, DyeVat);
            recipe.SetResult(this, 5);
            recipe.AddRecipe();
        }
    }
}
Code:
using Terraria.ModLoader;

namespace Mutation.Items
{
    public class MutationBunny
    {
        public override void SetDefaults()
        {
            base.SetDefaults();
            item.name = "Mutant Bunny";
            item.toolTip = "A vicious bunny.";
            item.useSound = 3;
            item.useStyle = 2;
            item.useTurn = true;
            item.useAnimation = 17;
            item.useTime = 17;
            item.maxStack = 30;
            item.consumable = true;
            item.width = 20;
            item.height = 28;
            item.value = 1000;
            item.rare = 1;
            item.shoot = mod.ProjectileType("MutantBunny");
            item.buffType = mod.BuffType("MutantBunny");
            item.buffTime = 300;
            return;
        }
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(null, Bunny, 1);
            recipe.AddIngredient(ItemID.MutationBottle, 1);
            recipe.AddTile(null, CookingPot);
            recipe.SetResult(this, 1);
            recipe.AddRecipe();
        }
    }
}
 
Back
Top Bottom