Standalone [1.3] tModLoader - A Modding API

Oh...
[DOUBLEPOST=1457572949,1457572723][/DOUBLEPOST]What about flying AI? Would that be different in any way
Yeah, totally different.
Now I wrote something for you (a lot of it is just copy+pasta) which may make your life easier with the fighter AI.
NOTE: I had some of this code laying 'bout. If you want more challenging AI, you'll really have to figure it out for yourself (also WARNING: untested).
Take a look at the following:
Code:
using System;

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MyMod.NPCs
{
    public static class MyModNPCAIExtras
    {
        public delegate void MyModExtraAction();
       
        public static void FighterAI(int index, float speed = 0.1F, float acceleration = 0.1F, MyModExtraAction extraAction = null)
        {
            NPC npc = Main.npc[index];
            bool idle = false;
            if ((double)npc.velocity.X == 0.0)
                idle = true;
            if (npc.justHit)
                idle = false;

            int cooldown = 60; // Not sure if this is cooldown yet.
            bool moving = false; // Not sure if this is moving yet.

            // If the NPC is grounded and moving.
            if( (double)npc.velocity.Y == 0.0 && ( (double)npc.velocity.X > 0.0 && npc.direction < 0 || (double)npc.velocity.X < 0.0 && npc.direction > 0 ) )
                moving = true;

            if ((double)npc.position.X == (double)npc.oldPosition.X || (double)npc.ai[3] >= (double)cooldown || moving)
                ++npc.ai[3];
            else if ((double)Math.Abs(npc.velocity.X) > 0.9 && (double)npc.ai[3] > 0.0)
                --npc.ai[3];

            if ((double)npc.ai[3] > (double)(cooldown * 10))
                npc.ai[3] = 0.0f;
            if (npc.justHit)
                npc.ai[3] = 0.0f;
            if ((double)npc.ai[3] == (double)cooldown)
                npc.netUpdate = true;

            // Find the closest target
            npc.TargetClosest(true);

            if ((double)npc.velocity.X < -(double)speed || (double)npc.velocity.X > (double)speed)
            {
                if( (double)npc.velocity.Y == 0.0 )
                {
                    float vecX = npc.velocity.X * 0.8f;
                    float vecY = npc.velocity.Y * 0.8f;
                    npc.velocity.X = vecX;
                    npc.velocity.Y = vecY;
                }
            }
            else if ((double)npc.velocity.X < (double)speed && npc.direction == 1)
            {
                npc.velocity.X = npc.velocity.X + acceleration;
                if ((double)npc.velocity.X > (double)speed)
                    npc.velocity.X = speed;
            }
            else if ((double)npc.velocity.X > -(double)speed && npc.direction == -1)
            {
                npc.velocity.X = npc.velocity.X - acceleration;
                if ((double)npc.velocity.X < -(double)speed)
                    npc.velocity.X = -speed;
            }

            bool flag11 = false;

            if ((double)npc.velocity.Y == 0.0)
            {
                int index1 = (int)((double)npc.position.Y + (double)npc.height + 7.0) / 16;
                int num1 = (int)npc.position.X / 16;
                int num2 = (int)((double)npc.position.X + (double)npc.width) / 16;
                for(int index2 = num1; index2 < num2; ++index2)
                {
                    if (Main.tile[index2, index1] == null)
                        return;
                    if(Main.tile[index2, index1].nactive() && Main.tileSolid[(int)Main.tile[index2, index1].type])
                    {
                        flag11 = true;
                        break;
                    }
                }
            }

            if( (double)npc.velocity.Y >= 0.0 )
            {
                int num1 = 0;
                if ((double)npc.velocity.X < 0.0)
                    num1 = -1;
                if ((double)npc.velocity.X > 0.0)
                    num1 = 1;
                float posX = npc.position.X;
                float posY = npc.position.Y;
                posX += npc.velocity.X;

                int index1 = (int)(((double)posX + (double)(npc.width / 2) + (double)((npc.width / 2 + 1) * num1)) / 16.0);
                int index2 = (int)(((double)posY + (double)npc.height - 1.0) / 16.0);
                if (Main.tile[index1, index2] == null)
                    Main.tile[index1, index2] = new Tile();
                if (Main.tile[index1, index2 - 1] == null)
                    Main.tile[index1, index2 - 1] = new Tile();
                if (Main.tile[index1, index2 - 2] == null)
                    Main.tile[index1, index2 - 2] = new Tile();
                if (Main.tile[index1, index2 - 3] == null)
                    Main.tile[index1, index2 - 3] = new Tile();
                if (Main.tile[index1, index2 + 1] == null)
                    Main.tile[index1, index2 + 1] = new Tile();
                if (Main.tile[index1 - num1, index2 - 3] == null)
                    Main.tile[index1 - num1, index2 - 3] = new Tile();

                if ((double)(index1 * 16) < (double)posX + (double)npc.width && (double)(index1 * 16 + 16) > (double)posX && (Main.tile[index1, index2].nactive() && !Main.tile[index1, index2].topSlope() && (!Main.tile[index1, index2 - 1].topSlope() && Main.tileSolid[(int)Main.tile[index1, index2].type]) && !Main.tileSolidTop[(int)Main.tile[index1, index2].type] || Main.tile[index1, index2 - 1].halfBrick() && Main.tile[index1, index2 - 1].nactive()) && ((!Main.tile[index1, index2 - 1].nactive() || !Main.tileSolid[(int)Main.tile[index1, index2 - 1].type] || Main.tileSolidTop[(int)Main.tile[index1, index2 - 1].type] || Main.tile[index1, index2 - 1].halfBrick() && (!Main.tile[index1, index2 - 4].nactive() || !Main.tileSolid[(int)Main.tile[index1, index2 - 4].type] || Main.tileSolidTop[(int)Main.tile[index1, index2 - 4].type])) && ((!Main.tile[index1, index2 - 2].nactive() || !Main.tileSolid[(int)Main.tile[index1, index2 - 2].type] || Main.tileSolidTop[(int)Main.tile[index1, index2 - 2].type]) && (!Main.tile[index1, index2 - 3].nactive() || !Main.tileSolid[(int)Main.tile[index1, index2 - 3].type] || Main.tileSolidTop[(int)Main.tile[index1, index2 - 3].type]) && (!Main.tile[index1 - num1, index2 - 3].nactive() || !Main.tileSolid[(int)Main.tile[index1 - num1, index2 - 3].type]))))
                {
                    float num2 = (float)(index2 * 16);
                    if (Main.tile[index1, index2].halfBrick())
                        num2 += 8f;
                    if (Main.tile[index1, index2 - 1].halfBrick())
                        num2 -= 8f;
                    if ((double)num2 < (double)posY + (double)npc.height)
                    {
                        float num3 = posY + (float)npc.height - num2;
                        float num4 = 16.1f;

                        if ((double)num3 <= (double)num4)
                        {
                            npc.gfxOffY += npc.position.Y + (float)npc.height - num2;
                            npc.position.Y = num2 - (float)npc.height;
                            npc.stepSpeed = (double)num3 >= 9.0 ? 2f : 1f;
                        }
                    }
                }
            }

            if (flag11)
            {
                int index1 = (int)(((double)npc.position.X + (double)(npc.width / 2) + (double)(15 * npc.direction)) / 16.0);
                int index2 = (int)(((double)npc.position.Y + (double)npc.height - 15.0) / 16.0);

                if (Main.tile[index1, index2] == null)
                    Main.tile[index1, index2] = new Tile();
                if (Main.tile[index1, index2 - 1] == null)
                    Main.tile[index1, index2 - 1] = new Tile();
                if (Main.tile[index1, index2 - 2] == null)
                    Main.tile[index1, index2 - 2] = new Tile();
                if (Main.tile[index1, index2 - 3] == null)
                    Main.tile[index1, index2 - 3] = new Tile();
                if (Main.tile[index1, index2 + 1] == null)
                    Main.tile[index1, index2 + 1] = new Tile();
                if (Main.tile[index1 + npc.direction, index2 - 1] == null)
                    Main.tile[index1 + npc.direction, index2 - 1] = new Tile();
                if (Main.tile[index1 + npc.direction, index2 + 1] == null)
                    Main.tile[index1 + npc.direction, index2 + 1] = new Tile();
                if (Main.tile[index1 - npc.direction, index2 + 1] == null)
                    Main.tile[index1 - npc.direction, index2 + 1] = new Tile();
                Main.tile[index1, index2 + 1].halfBrick();
                if (Main.tile[index1, index2 - 1].nactive() && ((int)Main.tile[index1, index2 - 1].type == 10 || (int)Main.tile[index1, index2 - 1].type == 388))
                {
                    ++npc.ai[2];
                    npc.ai[3] = 0.0f;
                    if ((double)npc.ai[2] >= 60.0)
                    {
                        npc.velocity.X = 0.5f * -(float)npc.direction;
                        int num1 = 5;
                        if ((int)Main.tile[index1, index2 - 1].type == 388)
                            num1 = 2;
                        npc.ai[1] += (float)num1;
                        if (npc.type == 27)
                            ++npc.ai[1];
                        if (npc.type == 31 || npc.type == 294 || (npc.type == 295 || npc.type == 296))
                            npc.ai[1] += 6f;
                        npc.ai[2] = 0.0f;
                        bool flag6 = false;
                        if ((double)npc.ai[1] >= 10.0)
                        {
                            flag6 = true;
                            npc.ai[1] = 10f;
                        }
                        if (npc.type == 460)
                            flag6 = true;
                        WorldGen.KillTile(index1, index2 - 1, true, false, false);
                        if ((Main.netMode != 1 || !flag6) && (flag6 && Main.netMode != 1))
                        {
                            if (TileLoader.OpenDoorID(Main.tile[index1, index2 - 1]) >= 0)
                            {
                                bool flag7 = WorldGen.OpenDoor(index1, index2 - 1, npc.direction);
                                if (!flag7)
                                {
                                    npc.ai[3] = (float)cooldown;
                                    npc.netUpdate = true;
                                }
                                if (Main.netMode == 2 && flag7)
                                    NetMessage.SendData(19, -1, -1, "", 0, (float)index1, (float)(index2 - 1), (float)npc.direction, 0, 0, 0);
                            }
                            if ((int)Main.tile[index1, index2 - 1].type == 388)
                            {
                                bool flag7 = WorldGen.ShiftTallGate(index1, index2 - 1, false);
                                if (!flag7)
                                {
                                    npc.ai[3] = (float)cooldown;
                                    npc.netUpdate = true;
                                }
                                if (Main.netMode == 2 && flag7)
                                    NetMessage.SendData(19, -1, -1, "", 4, (float)index1, (float)(index2 - 1), 0.0f, 0, 0, 0);
                            }
                        }
                    }
                }
                else
                {
                    if ((double)npc.velocity.X < 0.0 && npc.spriteDirection == -1 || (double)npc.velocity.X > 0.0 && npc.spriteDirection == 1)
                    {
                        if (npc.height >= 32 && Main.tile[index1, index2 - 2].nactive() && Main.tileSolid[(int)Main.tile[index1, index2 - 2].type])
                        {
                            if (Main.tile[index1, index2 - 3].nactive() && Main.tileSolid[(int)Main.tile[index1, index2 - 3].type])
                            {
                                npc.velocity.Y = -8f;
                                npc.netUpdate = true;
                            }
                            else
                            {
                                npc.velocity.Y = -7f;
                                npc.netUpdate = true;
                            }
                        }
                        else if (Main.tile[index1, index2 - 1].nactive() && Main.tileSolid[(int)Main.tile[index1, index2 - 1].type])
                        {
                            npc.velocity.Y = -6f;
                            npc.netUpdate = true;
                        }
                        else if ((double)npc.position.Y + (double)npc.height - (double)(index2 * 16) > 20.0 && Main.tile[index1, index2].nactive() && (!Main.tile[index1, index2].topSlope() && Main.tileSolid[(int)Main.tile[index1, index2].type]))
                        {
                            npc.velocity.Y = -5f;
                            npc.netUpdate = true;
                        }
                        else if (npc.directionY < 0 && (!Main.tile[index1, index2 + 1].nactive() || !Main.tileSolid[(int)Main.tile[index1, index2 + 1].type]) && (!Main.tile[index1 + npc.direction, index2 + 1].nactive() || !Main.tileSolid[(int)Main.tile[index1 + npc.direction, index2 + 1].type]))
                        {
                            npc.velocity.Y = -8f;
                            npc.velocity.X = npc.velocity.X * 1.5f;
                            npc.netUpdate = true;
                        }
                        else
                        {
                            npc.ai[1] = 0.0f;
                            npc.ai[2] = 0.0f;
                        }
                        if ((double)npc.velocity.Y == 0.0 && idle && (double)npc.ai[3] == 1.0)
                            npc.velocity.Y = -5f;
                    }
                }
            }
            else
            {
                npc.ai[1] = 0.0f;
                npc.ai[2] = 0.0f;
            }
       
            if(extraAction != null)
                extraAction();
        }       
    }
}
That's a LOOOOT of code, right (not really though)?
Anyway, what you want to do is create a new file in your mods root folder and call it MyModNPCAIExtras.cs.
After that, you'll want to copy+ paste this code into your newly made file.
Then on your NPC you'll want to do something like the following:
Code:
public override bool PreAI()
{
    MyModNPCAIExtras.FighterAI(npc.whoAmI, 3, 0.1F, null);
    return false;
}
If all is fine, your NPC will behave like a fighter. By changing the second and third parameter of the FighterAI function you can change the speed and acceleration (respectively) of the AI. Just ignore the last parameter for now, we can come back to that when you want to start spawning projectiles.
 
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace Enderuim.NPCs
{
    public class BruteZombie : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Brutish Zombie";
            npc.displayName = "Brutish Zombie";
            npc.width = 26;
            npc.height = 26;
            npc.damage = 80;
            npc.defense = 7;
            npc.lifeMax = 1000;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.value = 60f;
            npc.knockBackResist = 0.5f;
        }
            public override bool PreAI()
{
    MyModNPCAIExtras.FighterAI(npc.whoAmI, 5, 0.3F, null);
    return false;
}           
        public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
if(((myModPlayer)player.GetModPlayer(mod, "myModPlayer")).accessoryOn== true);
{
return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 100f : 100f;
}
return 0f;
}}}
c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\NPCs\LaserDrone.cs(32,78) : warning CS0642: Possible mistaken empty statement

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\NPCs\LaserDrone.cs(32,18) : error CS0103: The name 'player' does not exist in the current context
 
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace Enderuim.NPCs
{
    public class BruteZombie : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Brutish Zombie";
            npc.displayName = "Brutish Zombie";
            npc.width = 26;
            npc.height = 26;
            npc.damage = 80;
            npc.defense = 7;
            npc.lifeMax = 1000;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.value = 60f;
            npc.knockBackResist = 0.5f;
        }
            public override bool PreAI()
{
    MyModNPCAIExtras.FighterAI(npc.whoAmI, 5, 0.3F, null);
    return false;
}          
        public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
if(((myModPlayer)player.GetModPlayer(mod, "myModPlayer")).accessoryOn== true);
{
return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 100f : 100f;
}
return 0f;
}}}
c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\NPCs\LaserDrone.cs(32,78) : warning CS0642: Possible mistaken empty statement

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\NPCs\LaserDrone.cs(32,18) : error CS0103: The name 'player' does not exist in the current context
First off: why is this error being called from LaserDrone.cs??
Second, you'll want to use spawnInfo.player.GetModPlayer in the CanSpawn function.
 
First off: why is this error being called from LaserDrone.cs??
Second, you'll want to use spawnInfo.player.GetModPlayer in the CanSpawn function.
sorry, I forgot to change the file name
[DOUBLEPOST=1457577188,1457577087][/DOUBLEPOST]c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\NPCs\LaserDrone.cs(33,78) : warning CS0642: Possible mistaken empty statement

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\NPCs\LaserDrone.cs(32,1) : error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\NPCs\LaserDrone.cs(33,18) : error CS0103: The name 'player' does not exist in the current context
It just made more errors
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace Enderuim.NPCs
{
    public class BruteZombie : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Brutish Zombie";
            npc.displayName = "Brutish Zombie";
            npc.width = 26;
            npc.height = 26;
            npc.damage = 80;
            npc.defense = 7;
            npc.lifeMax = 1000;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.value = 60f;
            npc.knockBackResist = 0.5f;
        }
            public override bool PreAI()
{
    MyModNPCAIExtras.FighterAI(npc.whoAmI, 5, 0.3F, null);
    return false;
}           
        public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
spawnInfo.player.GetModPlayer;
if(((myModPlayer)player.GetModPlayer(mod, "myModPlayer")).accessoryOn== true);
{
return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 100f : 100f;
}
return 0f;
}}}
 
sorry, I forgot to change the file name
[DOUBLEPOST=1457577188,1457577087][/DOUBLEPOST]c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\NPCs\LaserDrone.cs(33,78) : warning CS0642: Possible mistaken empty statement

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\NPCs\LaserDrone.cs(32,1) : error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

c:\Users\Devin\Documents\My Games\Terraria\ModLoader\Mod Sources\Enderuim\NPCs\LaserDrone.cs(33,18) : error CS0103: The name 'player' does not exist in the current context
It just made more errors
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace Enderuim.NPCs
{
    public class BruteZombie : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Brutish Zombie";
            npc.displayName = "Brutish Zombie";
            npc.width = 26;
            npc.height = 26;
            npc.damage = 80;
            npc.defense = 7;
            npc.lifeMax = 1000;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.value = 60f;
            npc.knockBackResist = 0.5f;
        }
            public override bool PreAI()
{
    MyModNPCAIExtras.FighterAI(npc.whoAmI, 5, 0.3F, null);
    return false;
}          
        public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
spawnInfo.player.GetModPlayer;
if(((myModPlayer)player.GetModPlayer(mod, "myModPlayer")).accessoryOn== true);
{
return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 100f : 100f;
}
return 0f;
}}}
That's probably because you didn't quite get what I meant :p
You now have this:
Code:
public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
    spawnInfo.player.GetModPlayer;
    if(((myModPlayer)player.GetModPlayer(mod, "myModPlayer")).accessoryOn== true);
    {
        return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 100f : 100f;
    }
    return 0f;
}
And I meant this:
Code:
public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
    if(((myModPlayer)spawnInfo.player.GetModPlayer(mod, "myModPlayer")).accessoryOn== true);
    {
        return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 100f : 100f;
    }
    return 0f;
}
 
yeah, I lost the word for a moment
Allright, I'll explain one more time, but do make sure you save it somewhere this time:

First you want to put the following code in your SetDefaults function:
Code:
Main.npcFrameCount[npc.type] = 3; // 3 is the amount of frames inside this spritesheet.

Then you'll want to add the following function to your class:
Code:
public override void FindFrame(int frameHeight)
{
    npc.frameCounter += 0.1F; // 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;
}
 
My sprite artist is causing a holdup but Ill tell you then.
[DOUBLEPOST=1457578539,1457578329][/DOUBLEPOST]I tested with an old sprite and damn they are hilarious to watch but ya they work xD
Allright good to hear!
When you're ready for some projectile spawning let me know and I'll see if I can come up with an example for that fighter AI.
 
My pleasure

NPC code
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace Enderuim.NPCs
{
    public class BruteZombie : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Brutish Zombie";
            npc.displayName = "Brutish Zombie";
            npc.width = 26;
            npc.height = 26;
            npc.damage = 80;
            npc.defense = 7;
            npc.lifeMax = 1000;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.value = 60f;
            npc.knockBackResist = 0.5f;
            Main.npcFrameCount[npc.type] = 3;
        }
            public override bool PreAI()
{
    MyModNPCAIExtras.FighterAI(npc.whoAmI, 5, 0.3F, null);
    return false;
}           
public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
    if(((myModPlayer)spawnInfo.player.GetModPlayer(mod, "myModPlayer")).accessoryOn== true);
    {
        return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 100f : 100f;
    }
    return 0f;
    }
    public override void FindFrame(int frameHeight)
{
    npc.frameCounter += 0.1F; // 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;
}
}
}

Modplayer
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;

namespace Enderuim
{
public class myModPlayer : ModPlayer
{
public bool accessoryOn = false;


public override void PreUpdate()
{
accessoryOn = false;
}

}}

Item
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;

namespace Enderuim.Items
{
public class EnderuimTotem : ModItem
{
public override void SetDefaults()
{
item.name = "Enderuim Totem";
item.width = 30;
item.height = 30;
item.toolTip = "Awakens monsters of Dark Mode when worn";
item.value = Item.buyPrice(0, 10, 0, 0);
item.rare = 9;
item.accessory = true;
item.defense = 6;
}

public override void UpdateAccessory(Player player, bool hideVisual)
{
((myModPlayer)player.GetModPlayer(mod, "myModPlayer")).accessoryOn= true;
}


}
}
 
My pleasure

NPC code
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using System;

namespace Enderuim.NPCs
{
    public class BruteZombie : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Brutish Zombie";
            npc.displayName = "Brutish Zombie";
            npc.width = 26;
            npc.height = 26;
            npc.damage = 80;
            npc.defense = 7;
            npc.lifeMax = 1000;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.value = 60f;
            npc.knockBackResist = 0.5f;
            Main.npcFrameCount[npc.type] = 3;
        }
            public override bool PreAI()
{
    MyModNPCAIExtras.FighterAI(npc.whoAmI, 5, 0.3F, null);
    return false;
}          
public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
    if(((myModPlayer)spawnInfo.player.GetModPlayer(mod, "myModPlayer")).accessoryOn== true);
    {
        return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 100f : 100f;
    }
    return 0f;
    }
    public override void FindFrame(int frameHeight)
{
    npc.frameCounter += 0.1F; // 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;
}
}
}

Modplayer
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;

namespace Enderuim
{
public class myModPlayer : ModPlayer
{
public bool accessoryOn = false;


public override void PreUpdate()
{
accessoryOn = false;
}

}}

Item
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;

namespace Enderuim.Items
{
public class EnderuimTotem : ModItem
{
public override void SetDefaults()
{
item.name = "Enderuim Totem";
item.width = 30;
item.height = 30;
item.toolTip = "Awakens monsters of Dark Mode when worn";
item.value = Item.buyPrice(0, 10, 0, 0);
item.rare = 9;
item.accessory = true;
item.defense = 6;
}

public override void UpdateAccessory(Player player, bool hideVisual)
{
((myModPlayer)player.GetModPlayer(mod, "myModPlayer")).accessoryOn= true;
}


}
}
Allright well for one, I'd replace PreUpdate on your ModPlayer with ResetEffects.

Then the following line:
Code:
return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 100f : 100f;
Will make sure that even if it's daytime the NPC will spawn. If you want to change this, change the second 100 to 0.
 
how do I make the monster more or less common?
[DOUBLEPOST=1457579349,1457579328][/DOUBLEPOST]and what was the 100f : 100f ratio dong?
[DOUBLEPOST=1457579457][/DOUBLEPOST]OH my god they are still spawning even when the Totem is taken out of my inventory
 
how do I make the monster more or less common?
[DOUBLEPOST=1457579349,1457579328][/DOUBLEPOST]and what was the 100f : 100f ratio dong?
It's an alternate 'if' statement, meaning that this:
Code:
return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 100f : 100f;
Is practically the same as this:
Code:
if(spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime)
    return 100;
else
    return 100;

And oh wth... Your syntax is wrong:
Code:
public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
    if(((myModPlayer)spawnInfo.player.GetModPlayer(mod, "myModPlayer")).accessoryOn== true); // That last ; here is not supposed to be there!
    {
        return spawnInfo.spawnTileY < Main.rockLayer && !Main.dayTime ? 100f : 100f;
    }
    return 0f;
}
 
Back
Top Bottom