tModLoader Can someone help me with my npc?

LucLuz

Terrarian
Basically I was having problems when trying to make my goblin npc stop moving to shoot but i decided to left it for later, and here i am now, with 3 problems that i don't know how to fix, i thinked about making my own AI but it's a lot of job just to copy a fighter behavior and make it shoot.

My full code:

Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using Terraria.GameContent.Bestiary;
using Terraria.Localization;

namespace LucTerraMod.Content.NPCs
{
    public class GoblinGrenadier : ModNPC
    {
        private int shootCooldown = 120;

        public override void SetDefaults() {
            NPC.width = 28;
            NPC.height = 46;
           
            NPC.HitSound = SoundID.NPCHit1;
            NPC.DeathSound = SoundID.NPCDeath1;

            NPC.damage = 50;
            NPC.defense = 18;
            NPC.lifeMax = 200;
            NPC.knockBackResist = 0.35f;
            NPC.value = 500;

            NPC.aiStyle = 3;

            Banner = NPC.type;

            NPCID.Sets.BelongsToInvasionGoblinArmy[NPC.type] = true;
        }

        public override void AI() {
            NPC.TargetClosest(true);
            NPC.spriteDirection = NPC.direction;

            Shooting();
        }

        private void Shooting() {
            Player target = Main.player[NPC.target];

            float distance = Vector2.Distance(NPC.Center, target.Center);

            if (distance < 360) {
                //can't move here
                if (shootCooldown <= 0) {
                    Shoot(target);
                    shootCooldown = 120;
                } else {
                    shootCooldown--;
                }
            } else {
                //can move here
                shootCooldown = 120;
            }
        }

        private void Shoot(Player target) {
            Vector2 shootDir = target.Center - NPC.Center;
            shootDir.Normalize();

            Projectile.NewProjectile(NPC.GetSource_FromAI(), NPC.Center, shootDir * 7f, ProjectileID.WoodenArrowHostile, 70, 1f, Main.myPlayer);
        }

        public override void SetBestiary(BestiaryDatabase database, BestiaryEntry entry) {
            string text;
            if (Language.ActiveCulture.Name == "pt-BR") {
                text = "Peritos em explosivos, esses granadeiros arremessam granadas para bombardear seus inimigos";
            } else {
                text = "Experts in explosives, these grenadiers throw grenades to bombard their foes.";
            }
            entry.Info.AddRange(new IBestiaryInfoElement[] {
                BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Invasions.Goblins,
                new FlavorTextBestiaryInfoElement(text)
            });
        }
       
        public override float SpawnChance(NPCSpawnInfo spawnInfo) {
            if (Main.invasionType == InvasionID.GoblinArmy && spawnInfo.Player.ZoneOverworldHeight && Main.hardMode) {
                return 0.5f; //probably very high
            }
            return 0f;
        }
    }
}




My first problem was to make him stop to shoot, i tried to make it's velocity go to 0 (where the commentaries are on the shooting method) but if it jumped and i came closer it just stopped mid-air, i tried to put only X to be 0 but it became immune to knockback, i tried to multiply it by 0.9 and other floats but it just made it walk slower. And i really don't know what i could do, apparently it doesn't exist a "speed" variable that i can just set to 0 and the npc doesn't move at all.

My second problem is a bit simpler (i think), i made it shoot a woodenarrowhostile to see if it would work but i noticed that the damage instead of 70 (or something close to that) was around 120, then i put a smaller damage (20) and it worked normally. (i don't think it's a problem with the projectile type because i also changed it to cursedflames)

My last problem is that i almost don't see my npc spawning (i see like, one or two per goblin army), i tried 0.5f, 0.6f, 0.7f and even 1f, i think it's a spawn condition i forgot to put.





I would be very thankful it someone could help me with at least one of them.
 
The zombie AI is always constantly running, it doesn't pause, TML just runs your AI on top of it.
It'll never work the way you want it to unless you do something completely custom.

Terraria multiplies all projectile damage based on the world difficulty, which is why you're getting those numbers.
 
Oh, thanks. I was just insisting on fighterAI because i saw on the wiki this was the AI Goblin and Skeleton archer used.
 
Back
Top Bottom