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;
}
}
}