tModLoader How to make a weapon shoot different projectiles?

KaDi

Terrarian
Hello, I decided to make a simple mod and ran into a problem.
How can I make my rifle shoot both bullets and custom projectile at the same time?

C#:
using Terraria;
using Terraria.Audio;
using Microsoft.Xna.Framework;
using Terraria.ID;
using Terraria.DataStructures;
using Terraria.ModLoader;
using KadiloSnuper.Dusts;
using KadiloSnuper.Projectiles;

namespace KadiloSnuper.Items
{
    public class Kadilo : ModItem
    {

        public override void SetDefaults()
        {
            Item.damage = 2000;
            Item.DamageType = DamageClass.Ranged;
            Item.width = 40;
            Item.height = 40;
            Item.scale = 1.6f;
            Item.useTime = 120;
            Item.useAnimation = 120;
            Item.useStyle = 5;         
            Item.knockBack = 10;
            Item.shoot = ModContent.ProjectileType<Beam>();
            Item.shootSpeed = 20;   
            Item.useAmmo = AmmoID.Bullet;
            Item.value = 100000;
            Item.rare = ItemRarityID.Yellow;
            Item.UseSound = SoundID.Item1;
            Item.autoReuse = true;
            Item.noMelee = true;

            Item.UseSound = new SoundStyle($"{nameof(KadiloSnuper)}/Assets/Sounds/Items/Guns/Kadilo")
            {
                Volume = 0.9f,
                PitchVariance = 0.2f,
                MaxInstances = 3,
            };   
                
        }

    
        public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback)
        {
        

            const int NumProjectiles = 3;

            for (int i = 0; i < NumProjectiles; i++)
            {
                Vector2 newVelocity = velocity.RotatedByRandom(MathHelper.ToRadians(1));

                newVelocity *= 1f - Main.rand.NextFloat(0.1f);

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

            return false;
        }


        
        public override Vector2? HoldoutOffset()
        {
            return new Vector2(-9, 3);
        }

        public override void AddRecipes()
        {
            Recipe recipe = CreateRecipe();
            recipe.AddIngredient(ItemID.IllegalGunParts, 1);
            recipe.AddIngredient(ItemID.LunarBar, 5);
            recipe.AddIngredient(ItemID.HallowedBar, 30);
            recipe.AddTile(TileID.Anvils);
            recipe.Register();
        }
    }
}
 
return true

also Item.shoot = ProjectileID.MusketBall (or whatever the bullet is). So shoot the custom projectile in Shoot and then return true, and set Item.shoot to something vanilla. That might work.
 
return true

also Item.shoot = ProjectileID.MusketBall (or whatever the bullet is). So shoot the custom projectile in Shoot and then return true, and set Item.shoot to something vanilla. That might work.
To be honest, I've been working on mods and code for three days of my life and I don't understand what needs to be fixed, so I'll be very grateful if you show me how it looks like in the finished code.
 
cool. Yeah sure, but you'll have to find out what the explicit name is... or rather, look at this:

**Tag: learncs2 (Owner: stormytuna#0000)**
It's recommended that you learn the fundamentals of C# **before** learning to mod with tModLoader, many of the resources you will use to learn the API assume you have prior knowledge of C#. Here are some resources you can use to learn C#:
Understanding C#, a free Udemy course <https://www.udemy.com/course/understandingc/>
C# for absolute beginners, a video series <C# Fundamentals for Absolute Beginners>
C# documentation, including some more learning resources <C# docs - get started, tutorials, reference.>
C# yellow book, if you prefer reading <C# Yellow Book — robmiles.com>
SharpLab, a tool for quick C# and IL experiments <SharpLab>
Practice exercises, apply what you learn to small scale problems <Codewars - Achieve mastery through coding practice and developer mentorship>
 
Back
Top Bottom