PC I need help making a rat shoot people

Bean_Lord

Terrarian
I have some old code for a rat that shoots people at high speeds. I'm trying to upgrade it so that it works with 1.4 tmodloader but i'm how trouble with the whole IEntitySource thing.

C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
using Terraria.ModLoader.Utilities;

namespace Skellington.NPCs.Enemies
{
    public class GunSwavy : ModNPC
    {
        public override void SetStaticDefaults()
        {

            DisplayName.SetDefault("Gun Swavy");

            Main.npcFrameCount[NPC.type] = 1;
        }


        public override void SetDefaults()
        {
            NPC.width = 18;
            NPC.height = 26;

            NPC.lifeMax = 200;

            NPC.damage = 50;
            NPC.defense = 2;

            NPC.HitSound = SoundID.NPCHit1;
            NPC.DeathSound = SoundID.NPCDeath4;

            NPC.value = 10f;

            NPC.knockBackResist = 0.3f;

            NPC.aiStyle = 0;

            AIType = 0;

        }
        public override void AI()
        {
            NPC.TargetClosest();
            if (NPC.HasValidTarget && Main.netMode != NetmodeID.MultiplayerClient)
            {
                Vector2 position = NPC.Center;
                Vector2 targetPosition = Main.player[NPC.target].Center;
                Vector2 direction = targetPosition - position;
                direction.Normalize();
                float speed = 10f;
                int type = ProjectileID.BulletDeadeye;
                int damage = NPC.damage;
                // I think i need to like add "NPC.GetSource_FromAI()" some how
                Projectile.NewProjectile(position, direction * speed, type, damage, Main.myPlayer);
                
            }
        }

        public override float SpawnChance(NPCSpawnInfo spawnInfo)
        {
            return SpawnCondition.OverworldDaySlime.Chance * 0.5f;
        }
    }
}
 
by the way if you haven't guessed from the title, its the projectile.newprojectile part that's not working.(CS1501 error)
 
You were correct, change:
Projectile.NewProjectile(position, direction * speed, type, damage, Main.myPlayer);
to
Projectile.NewProjectile(NPC.GetSource_FromAI(), position, direction * speed, type, damage, Main.myPlayer);
 
You were correct, change:
Projectile.NewProjectile(position, direction * speed, type, damage, Main.myPlayer);
to
Projectile.NewProjectile(NPC.GetSource_FromAI(), position, direction * speed, type, damage, Main.myPlayer);
I just realized that the rat rapid fires. how do i make like a timer or something so he shoots every couple seconds.
 
Just create a variable to track it. Increment the variable every tick of AI, which is 60 per second, then when it reaches a certain amount, shoot the projectile and reset the variable to 0.
 
Back
Top Bottom