tModLoader [Tutorial] Projectile Guide and Implementation: tModLoader Edition

How do I get a boomerang to pierce? I changed the projectile.penetrate and projectile.maxPenetrate to 3, but it still returns the boomerang after it hits one enemy
using Terraria;
using Terraria.ModLoader;

namespace DarkestNightsMod.Projectiles
{
public class SpineBreakerProj : ModProjectile
{

public override void SetDefaults()
{
projectile.Name = "Spine Breaker";
projectile.width = 22;
projectile.height = 22;
projectile.aiStyle = 3;
projectile.friendly = true;
projectile.melee = true;
projectile.magic = false;
projectile.penetrate = 3;
projectile.maxPenetrate = 3;
projectile.timeLeft = 600;
projectile.extraUpdates = 1;

}

public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
projectile.velocity.X *= .5f;
projectile.velocity.Y *= .5f;
}

}
}
 
this should work maybe

Code:
using Terraria;
using Terraria.ModLoader;

namespace DarkestNightsMod.Projectiles
{
public class SpineBreakerProj : ModProjectile
{

public override void SetDefaults()
{
projectile.Name = "Spine Breaker";
projectile.width = 22;
projectile.height = 22;
projectile.aiStyle = 3;
projectile.friendly = true;
projectile.melee = true;
projectile.magic = false;
projectile.penetrate = -1;
projectile.maxPenetrate = -1;
projectile.timeLeft = 600;
projectile.extraUpdates = 1;

}

public const int Hits = 0;

public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
Hits++;
if (Hits == 3) //number of enemies needed to be hit before the returns code runs and also i think you should add something to call it back if you don't hit anything.
{
projectile.velocity.X *= .5f;
projectile.velocity.Y *= .5f;
Hits = 0;
}
}

}
}
 
Last edited:
for the homing projectiles, the "if (target.hostiles)" at the beginning says that NPC doesn't contain a definition for "hostiles." any reason why?
 
for the homing projectiles, the "if (target.hostiles)" at the beginning says that NPC doesn't contain a definition for "hostiles." any reason why?
npc only has friendly, not hostile. Something that is !friendly is hostile. Projectiles are different, they have both friendly and hostile bools because some projectiles, like bombs, can damage both the player and enemies.
 
Greetings. Is anybody here ? I’m trying to learn how to make mods myself, but so far it’s going badly. I want to ask for help on several issues. I wanted to change the attack speed, but in addition to the change, an inscription was also added. -150 speed. I tried to change a couple of code lines. The inscription faded or changed. But the speed of the scythe also returned to its original one. I just wanted to make a very slow weapon, but this inscription is simply not needed at all.
MKzQoQQsh2E.jpg
How can it be removed ? Here is the code :
using Terraria.ID;
using Terraria.ModLoader;

namespace Wares.Items
{
public class Basa : ModItem
{
public override void SetStaticDefaults()
{

Tooltip.SetDefault("Interesting scythe, crafted from diamonds and platinum bars. Brings some really sharp harvest");
}

public override void SetDefaults()
{
item.damage = 45;
item.melee = true;
item.width = 60;
item.height = 50;
item.useTime = 20;
item.useAnimation = 50;
item.useStyle = 1;
item.knockBack = 6;
item.value = 10000;
item.rare = 5;
item.UseSound = SoundID.Item71;
item.autoReuse = true;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 10);
recipe.AddTile(TileID.WorkBenches);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
 
Greetings. Is anybody here ? I’m trying to learn how to make mods myself, but so far it’s going badly. I want to ask for help on several issues. I wanted to change the attack speed, but in addition to the change, an inscription was also added. -150 speed. I tried to change a couple of code lines. The inscription faded or changed. But the speed of the scythe also returned to its original one. I just wanted to make a very slow weapon, but this inscription is simply not needed at all.View attachment 236973 How can it be removed ? Here is the code :
using Terraria.ID;
using Terraria.ModLoader;

namespace Wares.Items
{
public class Basa : ModItem
{
public override void SetStaticDefaults()
{

Tooltip.SetDefault("Interesting scythe, crafted from diamonds and platinum bars. Brings some really sharp harvest");
}

public override void SetDefaults()
{
item.damage = 45;
item.melee = true;
item.width = 60;
item.height = 50;
item.useTime = 20;
item.useAnimation = 50;
item.useStyle = 1;
item.knockBack = 6;
item.value = 10000;
item.rare = 5;
item.UseSound = SoundID.Item71;
item.autoReuse = true;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 10);
recipe.AddTile(TileID.WorkBenches);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}

Change item.useTime to match the useAnimation
 
Hey there everyone! I'm having a bit of a predicament with a projectile I'm trying to make.
Basically, it's suppose to be the High Velocity Projectile but it inflicts the 'On Fire!' de-buff when hitting a enemy, and make the light it gives off orange.
Here's the code:

C#:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

// TODO : Fix this!
namespace TechAndScalesMod.Projectiles
{
    class LavaHighVelocity : ModProjectile
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Lava High Velocity");
            ProjectileID.Sets.TrailCacheLength[projectile.type] = 5;
            ProjectileID.Sets.TrailingMode[projectile.type] = 0;
        }

        public override void SetDefaults()
        {
            projectile.width = 136;
            projectile.height = 2;
            projectile.aiStyle = 1; // The AI this projectile has.
            projectile.friendly = true;
            projectile.hostile = false;
            projectile.ranged = true; // Is this shot out of a ranged weapon?
            projectile.penetrate = 1; // If this projectile has penetration. Set to 0 to disable.
            projectile.timeLeft = 600; // Life of the projectile. 60 = 1 sec.
            projectile.alpha = 255; // The alpha of the bullet.
            projectile.light = 1f; // How bright the light this projectile emits. Set to 0 for none.
            projectile.tileCollide = true; // Can this projectile hit tiles?
            projectile.extraUpdates = 8; // How often the projectile checks for a movement update. Higher makes the projectile faster. Musket ball = 1, High Vel = 8.
            aiType = ProjectileID.Bullet; // Makes the project act like a normal Bullet.
        }

        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            if (!target.HasBuff(BuffID.OnFire))
            {
                target.AddBuff(BuffID.OnFire, 60 * 3); // Inflict 'On Fire!' for 3 seconds
            }
        }

        public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
        {
            lightColor = new Color(1, 1, 0); // Seems to do nothing?
            Vector2 drawOrigin = new Vector2(Main.projectileTexture[projectile.type].Width * 0.5f, projectile.height * 0.5f);
            for (int k = 0; k < projectile.oldPos.Length; k++)
            {
                Vector2 drawPos = projectile.oldPos[k] - Main.screenPosition + drawOrigin + new Vector2(0f, projectile.gfxOffY);
                Color color = projectile.GetAlpha(lightColor) * ((float)(projectile.oldPos.Length - k) / (float)projectile.oldPos.Length);
                spriteBatch.Draw(Main.projectileTexture[projectile.type], drawPos, null, color, projectile.rotation, drawOrigin, projectile.scale, SpriteEffects.None, 0f);
            }
            return true;
        }

        public override void Kill(int timeLeft)
        {
            Collision.HitTiles(projectile.position + projectile.velocity, projectile.velocity, projectile.width, projectile.height);
            Main.PlaySound(SoundID.Item10, projectile.position);
        }
    }
}
I am using the ExampleMod's code, but it doesn't seem to be working right. It shots and applies the de-buff just fine, but the light stays white and something seems off with the sprite.
Any help is appreciated, thank you!
 
Change item.useTime to match the useAnimation
Thank you friend. I hope this works. I'm sorry I couldn't say thank you for a long time . I have other questions (One of which I will ask now), but I will ask them if they turn into a big problem. Thanks again.
 
I have another question. How can I make ammunition ? I tried to make an infinite bag of ammo, but it produced 33 errors. How do I make an infinite bag for example with chlorophyte bullets ? I tried to find an example in other mods, but the files are patched into modloader files. The bullet example on Github also produced 30 errors. Maybe I can find a resource Bank somewhere ? Such codes as are written for mod items ?
 
I need help whit my projectile, so:
How do i give a delay to the projectile?

To elaborate the question, notice how the enchanted sword doesn't shoot every time, it has a delay, and i want to do a delay too.
My script:

using Terraria.ID;
using Terraria.ModLoader;

namespace PossibleAdds.Items.Weapons
{
public class EnchantedFury : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Enchanted Fury"); // By default, capitalization in classnames will add spaces to the display name. You can customize the display name here by uncommenting this line.
Tooltip.SetDefault("The combination of magic!");
}

public override void SetDefaults()
{
item.damage = 46;
item.melee = true;
item.width = 40;
item.height = 40;
item.useTime = 18;
item.useAnimation = 18;
item.useStyle = 1;
item.knockBack = 5;
item.value = 150000;
item.rare = 3;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
item.shoot = 173;
item.shootSpeed = 6f;
}
}
}
 
I need help whit my projectile, so:
How do i give a delay to the projectile?

To elaborate the question, notice how the enchanted sword doesn't shoot every time, it has a delay, and i want to do a delay too.
My script:

using Terraria.ID;
using Terraria.ModLoader;

namespace PossibleAdds.Items.Weapons
{
public class EnchantedFury : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Enchanted Fury"); // By default, capitalization in classnames will add spaces to the display name. You can customize the display name here by uncommenting this line.
Tooltip.SetDefault("The combination of magic!");
}

public override void SetDefaults()
{
item.damage = 46;
item.melee = true;
item.width = 40;
item.height = 40;
item.useTime = 18;
item.useAnimation = 18;
item.useStyle = 1;
item.knockBack = 5;
item.value = 150000;
item.rare = 3;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
item.shoot = 173;
item.shootSpeed = 6f;
}
}
}
Isnt it the shootspeed at the end?
 
I have another question. How can I make ammunition ? I tried to make an infinite bag of ammo, but it produced 33 errors. How do I make an infinite bag for example with chlorophyte bullets ? I tried to find an example in other mods, but the files are patched into modloader files. The bullet example on Github also produced 30 errors. Maybe I can find a resource Bank somewhere ? Such codes as are written for mod items ?

Code?
 
I have only github example :
using ExampleMod.Tiles;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;

namespace ExampleMod.Items.Weapons
{
public class ExampleBullet : ModItem
{
public override void SetStaticDefaults() {
Tooltip.SetDefault("This is a modded bullet ammo.");
}

public override void SetDefaults() {
item.damage = 12;
item.ranged = true;
item.width = 8;
item.height = 8;
item.maxStack = 999;
item.consumable = true;
item.knockBack = 1.5f;
item.value = 10;
item.rare = 2;
item.shoot = ProjectileType<Projectiles.ExampleBullet>();
item.shootSpeed = 16f;
item.ammo = AmmoID.Bullet;
}


public override void OnConsumeAmmo(Player player) {
if (Main.rand.NextBool(5)) {
player.AddBuff(BuffID.Wrath, 300);
}
}

public override void AddRecipes() {
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.MusketBall, 50);
recipe.AddIngredient(ItemType<ExampleItem>(), 1);
recipe.AddTile(TileType<ExampleWorkbench>());
recipe.SetResult(this, 50);
recipe.AddRecipe();
}
}
}
I tried to change it in "chlorophyte" but recevied only errors. How can i turn it into endless chlorophyte bullets ? Im trying to make endless ammunition
 
Back
Top Bottom