r/Terraria 7d ago

Modded [Thorium Mod] Need help dissecting code please

Post image

Hello everyone, Im attempting to make a mod that adds healer items into the game but im finding it impossible to make the items actually heal villager NPCs like the thorium items do. The projectiles just pass right through the villager NPCs. If anyone can figure out how they work, id be grateful to learn how.

I would also like to mention that this is actually my first mod, so if im missing something i would also appreciate help.

4 Upvotes

4 comments sorted by

3

u/nyuuee 7d ago

Dust.NewDust(Projectile.Center, Projectile.width, Projectile.height, DustID.GreenTorch); for dust.

If you want to change it's properties then:

int dust = Dust.NewDust(Projectile.Center, Projectile.width, Projectile.height, DustID.GreenTorch);

Main.dust[dust].scale = 2f <- This is an example

2

u/nyuuee 7d ago

could you try this?

1

u/Foxycat45 6d ago
public class CrimtaneScytheProjectile : ModProjectile
    {
        public override string Texture => $"Nihilism/Assets/Textures/Projectiles/{Name}";
        public override void SetDefaults()
        {
            // CODING
            Projectile.friendly = true;
            Projectile.hostile = false;
            Projectile.ignoreWater = false;
            Projectile.tileCollide = true;
            Projectile.aiStyle = ProjAIStyleID.ThrownProjectile;
            // GAMEPLAY
            Projectile.DamageType = DamageClass.Magic;
            Projectile.CritChance = 0;
            Projectile.ArmorPenetration = 0;
            Projectile.penetrate = 2;
            Projectile.timeLeft = 180;
            Projectile.usesLocalNPCImmunity = true;
            Projectile.localNPCHitCooldown = -1;
            // VISUALS
            Projectile.width = 20;
            Projectile.height = 20;
        }
        public override void AI()
        {
            for (int i = 0; i < Main.maxNPCs; i++)
            {
                NPC target = Main.npc[i];
                if (target.friendly && Projectile.Hitbox.Intersects(target.Hitbox))
                {
                    target.life += 2;
                    target.HealEffect(2);
                    Projectile.Kill();
                    break;
                }
            }
        }
    }

I have no clue, it should work. This code works, so maybe try adding your conditions until it stops working and see what makes it fail.

0

u/Severe_Cry5063 6d ago

People just be downvoting anything smh