tModLoader Modding Tutorial 3: Some More Weapons

are you still open to questions, if so, then
How can I make it so that only musket ball projectile turn into silver bullets?
also, how do i modify the crit strike chance?
also(again), how do i change the bullet that the musket ball are turning into?, i wanted tungsten instead of silver for aestethic.

edit : you can massage me for the answer, since i can't post here anymore, not sure about you tho.
oh hey, can you please remind me tomorrow? I cannot answer rn and can forget
 
alright
1 more question, how can i make a flamethrower-like projetile? because when i used the regular one it uses hellfire, and not on fire
 
Last edited:
How can I make it so that only musket ball projectile turn into silver bullets?
C#:
                if (type == ProjectileID.Bullet)
                {
                    type = ProjectileID.SilverBullet;
                }

also, how do i modify the crit strike chance?
Item.crit = something; // Note that player by default have 4% crit chance and so if you set 0 here it will be 4% in game

also(again), how do i change the bullet that the musket ball are turning into?, i wanted tungsten instead of silver for aestethic.
just change ProjectileID.SilverBullet in there to something you wanna to. List of projectile IDs

1 more question, how can i make a flamethrower-like projetile? because when i used the regular one it uses hellfire, and not on fire
oh that's a hell thing with custom drawing, I can send you my boss' flamethrower projectile adapted from vanilla if you want
 
oh that's a hell thing with custom drawing, I can send you my boss' flamethrower projectile adapted from vanilla if you want
no, i just wanted to change the color and debuff of the projectile like the elf melter, is that possible?

the problem with tungsten bullet is, it has the same id as musket balls, and it will turn into musket balls if i used the id.
anyway, big thanks for the help!
 
no, i just wanted to change the color and debuff of the projectile like the elf melter, is that possible?
no, that's just uses different ai for one projectile, you must make your own projectile to do what you want

the problem with tungsten bullet is, it has the same id as musket balls, and it will turn into musket balls if i used the id.
anyway, big thanks for the help!
oh, I thought it was different, so IDK, maybe it is just higher damage default bullet
 
no, that's just uses different ai for one projectile, you must make your own projectile to do what you want
some more things i wanna ask if i'm gonna make my own projetile:
how do i apply debuffs to the target?
how do i change the dust's spawn location? (so it isn't in the center only)
how do i alter projetile size,color, speed or damage, and contiously alter it when the projetile is still onscreen?
how do i add life leech? (like vampire knifes)

i think this is all for now, and THANK YOU SO MUCH, your answers and tutorials are really helpful, i hope you can make one about summoner weapon soon!
 
Last edited:
how do i apply debuffs to the target?
C#:
        public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone)
        {
            target.AddBuff(BuffID.CursedInferno, time: 120); // Time in ticks (60 ticks = 1 second)
        }

how do i change the dust's spawn location? (so it isn't in the center only)
just change Position to other Vector2 you wanna use (for example, Projectile.Center + new Vector2(x: 10, y: -10) will spawn a dust with 10 pixels offset to right and 10 pixels offset to up (-Y is up))

how do i alter projetile size,color, speed or damage, and contiously alter it when the projetile is still onscreen?
size is altered by Projectile.width and Projectile.height, also you can use Projectile.scale to make projectile bigger X times (for eg, Projectile.scale = 1.7f will make projectile larger by 70%)
color can be set in GetAlpha: public override Color? GetAlpha(Color lightColor) => Color.White; or in sprite itself
for changing speed you can multiply Projectile.velocity or by changing Item.shootSpeed
damage can be changed by changing Projectile.damage but it cannot be changed in SetDefaults (it will be overwritten)
alter stats while projectile is alive you can in AI() method

how do i add life leech? (like vampire knifes)
you can just spawn vampire knives healing projectile, or heal the player manually by using player.Heal(amount);
 
i think this is all for now, and THANK YOU SO MUCH, your answers and tutorials are really helpful, i hope you can make one about summoner weapon soon!
oh ty
but I hate summoner so I don't think I'll do the guide about their weapon soon, I think I'll make a guide about mobs next (or even move from beginner guides to serious ones)
 
size is altered by Projectile.width and Projectile.height, also you can use Projectile.scale to make projectile bigger X times (for eg, Projectile.scale = 1.7f will make projectile larger by 70%)
color can be set in GetAlpha: public override Color? GetAlpha(Color lightColor) => Color.White; or in sprite itself
for changing speed you can multiply Projectile.velocity or by changing Item.shootSpeed
damage can be changed by changing Projectile.damage but it cannot be changed in SetDefaults (it will be overwritten)
alter stats while projectile is alive you can in AI() method

i wanted to, for example, after 20 frames, change width and height to 60, and spin the projetile. i also wanted to do that with other stats. do you have any idea of how?
 
i wanted to, for example, after 20 frames, change width and height to 60, and spin the projetile. i also wanted to do that with other stats. do you have any idea of how?
Just create some variable and add 1 to it in AI, then once it reaches 20 use Projectile.Resize(width, height), and make some circular velocity for proj
 
Can I somehow make the sound play multiple times. Because using sound ID 31 (clockwork assault rifle) doesnt quite work since the sound instances doesnt match the burst timing of the modded gun. Is there any way to use vanilla sounds but add instances to them or something?
 
Can I somehow make the sound play multiple times. Because using sound ID 31 (clockwork assault rifle) doesnt quite work since the sound instances doesnt match the burst timing of the modded gun. Is there any way to use vanilla sounds but add instances to them or something?
Play sound in Shoot()
To play sound, you need to use SoundEngine.PlaySound(soundID, position)
There's some reference required, I don't remember exactly, look what your IDE suggests
 
Play sound in Shoot()
To play sound, you need to use SoundEngine.PlaySound(soundID, position)
There's some reference required, I don't remember exactly, look what your IDE suggests
Thank you for the responses you're very helpful

//for (int i = 0; i < 1; i++)
//{
SoundEngine.PlaySound(SoundID.Item11, position);
//New velocity for new bullets
Vector2 NewVelocity = velocity.RotatedByRandom(MathHelper.ToRadians(7));
// Some bullet speed randomization
//NewVelocity *= 1f - Main.rand.NextFloat(0.2f);
// our gun has a 1/5 chance to replace default bullets with silver bullets
if (Main.rand.NextBool(5))
{
type = ProjectileID.SilverBullet;
}
//Creating new projectile
Projectile.NewProjectileDirect(
source,
position,
NewVelocity,
type,
damage,
knockback,
player.whoAmI
);
//}

This works perfectly!!!!

P.S. Ignore most of the commented out code. I was just playing around with all the techniques in this guide and seeing what difference what makes. I prefer learning that way.


:)
 
Last edited:
hey, i encountered a problem, i followed this tutorial a few months back, and my weapons isnt consuming ammo anymore. it worked fine before,
but just a few days ago when i reloaded the mod, every ammo consuming weapon i made isn't consuming ammo anymore.
i wrote the code like this :public override bool CanConsumeAmmo(Item ammo, Player player) => Main.rand.Next(101) <= 20;
 
hey, i encountered a problem, i followed this tutorial a few months back, and my weapons isnt consuming ammo anymore. it worked fine before,
but just a few days ago when i reloaded the mod, every ammo consuming weapon i made isn't consuming ammo anymore.
i wrote the code like this :public override bool CanConsumeAmmo(Item ammo, Player player) => Main.rand.Next(101) <= 20;
This looks alright, send the full code please
 
This looks alright, send the full code please
C#:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;
using Terraria.GameContent.Creative;
using TalesOfTheKingMod.Content.Projectiles.OnFireFlame;

namespace TalesOfTheKingMod.Content.Items.Ranged.FossilFuel
{
    public class FossilFuel : ModItem
    {
        
        public override void SetDefaults()
        {
            // Combat prop
            Item.damage = 11;
            Item.DamageType = DamageClass.Ranged;
            Item.crit = 0;
            Item.useTime = 2;
            Item.useAnimation = 30;
            Item.knockBack = 0.1f;
            Item.autoReuse = true;
            Item.reuseDelay = 10;
            Item.consumeAmmoOnLastShotOnly = true;

            // Visual prop
            Item.width = 58;
            Item.height = 18;
            Item.scale = 1f;
            Item.useStyle = ItemUseStyleID.Shoot;
            Item.rare = ItemRarityID.Green;

            // Other prop
            Item.value = Item.sellPrice(0, 0, 40, 0);
            Item.UseSound = SoundID.Item34;
            Item.noMelee = true;
            Item.shoot = ProjectileID.PurificationPowder;
            Item.shootSpeed = 21f;
            Item.useAmmo = AmmoID.Gel;
        }

        public override bool CanUseItem(Player player)
        {
        return !player.wet;
        }

        public override void AddRecipes()
        {
            Recipe recipe1 = Recipe.Create(ModContent.ItemType<FossilFuel>());
            recipe1.AddIngredient(ItemID.FossilOre, 12);
            recipe1.AddIngredient(ItemID.Torch, 20);
            recipe1.AddRecipeGroup(RecipeGroupID.IronBar, 8);
            recipe1.AddTile(TileID.Anvils);
            recipe1.Register();
        }
         public override void SetStaticDefaults()
        {
            CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1; // How many items need for research in Journey Mode
        }
        public override bool CanConsumeAmmo(Item ammo, Player player) => Main.rand.Next(101) <= 20; // Chance in % to not consume ammo
        public override Vector2? HoldoutOffset() => new Vector2(-3f, 0f); // Offset editor in pixel

        public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
        {
            velocity = velocity.RotatedByRandom(MathHelper.ToRadians(0));

            int NumProjectiles = Main.rand.Next(1, 1);
            for (int i = 0; i < NumProjectiles; i++)
            {
                Vector2 NewVelocity = velocity.RotatedByRandom(MathHelper.ToRadians(2));

                NewVelocity *= 1f - Main.rand.NextFloat(0.2f);

                if (type == ProjectileID.PurificationPowder)
                {
                    type = ModContent.ProjectileType<OnFireFlame>();
                }

                Projectile.NewProjectileDirect(
                    source,
                    position,
                    NewVelocity,
                    type,
                    damage,
                    knockback,
                    player.whoAmI
                    );
            }

            return false;

        }

    }
}
 
Oh, consumeAmmoOnLastShotOnly works weirdly wtih CanConsumeAmmo for some reason. My flamethrowers had this problem too, remind me later and I'll send my solution
 
Back
Top Bottom