tModLoader Tmodloader and Custom NPCs on Player Team

JerryPlayz101

Terrarian
Hello All,
I have been recently trying to develop an NPC designed to work alongside the player by "surrounding" them (like a shield) and absorbing incoming damage for the player. I looked around for a bit and found a tutorial from 2016, but it seems to cause an issue that I cannot identify. (If there is any way to implement the following list of requirements into the current code structure, please be in-depth and show me how - I am new to this field within modding.):
- Must follow the player, staying precisely over them
- Prevent enemy mobs and NPCs (enemy) from coming in to attack the player
- Must force enemy AI (in this way) attack it before the player
- Has a set amount of health, say 300 Hit Points
- Be hit by all projectiles coming into the hit-box of itself
- Somehow have a custom death animation (don't worry, I have made this)
- Somehow have a custom spawn animation (I have made this too)
- prevent bosses from entering itself (this one might not be possible, but why not ask)

Here is the code the tutorial suggested:
C#:
// Code by Al0n37 originally
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

                                                           
namespace MK.NPCs
{
    public class NpcName : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Monster";
            npc.displayName = "Monster";
            npc.width = 50;
            npc.height = 40;
            npc.damage = 10;
            npc.defense = 10;
            npc.lifeMax = 200;
            npc.soundHit = 1;
            npc.soundKilled = 13;
            npc.value = 60f;
            npc.knockBackResist = 0.5f;
            npc.aiStyle = 44;
            Main.npcFrameCount[npc.type] = 3;
            aiType = NPCID.Harpy;  //npc behavior
            animationType = NPCID.Harpy;
        }

        public override float CanSpawn(NPCSpawnInfo spawnInfo)
        {
            return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 0.5f : 0.5f; //spown at day
        }
        public override void FindFrame(int frameHeight)
        {
            npc.frameCounter -= 0.5F; // Determines the animation speed. Higher value = faster animation.
            npc.frameCounter %= Main.npcFrameCount[npc.type];
            int frame = (int)npc.frameCounter;
            npc.frame.Y = frame * frameHeight;

            npc.spriteDirection = npc.direction;
        }
        public override void NPCLoot()  //Npc drop
        {
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"), 2); //Item spawn
            }

        }
    }
}

It seems to be running into an error on load:
Capture3.PNG


And if possible, can someone tell me where to find a list of all the AI types that are implemented into the game? It would help a lot.


Sorry if this sounds like a lot, but I cannot find any other thread detailing this [in detail] obviously.

Regards,
Jerry
 
Try This:





// Code by Al0n37 originally
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;


namespace MK.NPCs
{
public class NpcName : ModNPC
{
public override void SetDefaults()
{
npc.name = "Monster";
npc.displayName = "Monster";
npc.width = 50;
npc.height = 40;
npc.damage = 10;
npc.defense = 10;
npc.lifeMax = 200;
npc.soundHit = 1;
npc.soundKilled = 13;
npc.value = 60f;
npc.knockBackResist = 0.5f;
npc.aiStyle = 44;
Main.npcFrameCount[npc.type] = 3;
aiType = NPCID.Harpy; //npc behavior
animationType = NPCID.Harpy;
}


public override float SpawnChance(NPCSpawnInfo spawnInfo)
{
return SpawnCondition.OverworldDay.Chance * 0.12f;
}

public override void FindFrame(int frameHeight)
{
npc.frameCounter -= 0.5F; // Determines the animation speed. Higher value = faster animation.
npc.frameCounter %= Main.npcFrameCount[npc.type];
int frame = (int)npc.frameCounter;
npc.frame.Y = frame * frameHeight;

npc.spriteDirection = npc.direction;
}
public override void NPCLoot() //Npc drop
{
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ItemName"), 2); //Item spawn
}

}
}
}
 
Back
Top Bottom