tModLoader Official tModLoader Help Thread

It now shows up as a full sprite but 2nd frame is 2 lines for some reason and it still doesnt fly with AIStyle = 5
 
It now shows up as a full sprite but 2nd frame is 2 lines for some reason and it still doesnt fly with AIStyle = 5
You might also want to use aiType, then. Try setting aiType = 6; in the SetDefaults too.
About the animation: think you can make a .gif to show us what's wrong?
 
For the AI aiType = 6 or aiType = 5 didnt work.
TerrariaGIF.gif
 
For the AI aiType = 6 or aiType = 5 didnt work. View attachment 156276
Allright, first of all lets go for some animation code I'm almost completely sure will work:
Code:
public override void FindFrame(int frameHeight)
{
    if (npc.frameCounter++ >= 10)
    {
        npc.frame.Y = (npc.frame.Y + frameHeight) % (Main.npcFrameCount[npc.type] * frameHeight);
        npc.frameCounter = 0;
    }
    npc.spriteDirection = npc.direction;
}
Replace your current method with this one.
Now about the AI: It really should work at this point (if you were to ask me). Could you post the whole NPC code here?
You can just copy (Ctrl+C) + paste (Ctrl+V) your code here, instead of making screenshots.
 
The Sprites work but the AI still doesnt :/ it still is standing in one place

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

using System.Threading.Tasks;

namespace MiscItems.NPCs
{
class PuritySpirit : ModNPC
{
public override void SetDefaults()
{
npc.name = "PuritySpirit";
npc.displayName = "Purity Spirit";
npc.width = 80;
npc.height = 320;
npc.damage = 50;
npc.defense = 5;
npc.lifeMax = 400;
npc.value = 60f;
npc.knockBackResist = 0.5f;
aiType = NPCID.EaterofSouls;
Main.npcFrameCount[npc.type] = 2;
}

public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
if (spawnInfo.player.ZoneHoly)
return 0.5F;
return 0;
}
public override void NPCLoot() //Npc drop
{
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("SoulOfPurity"), 2); //Item spawn
}

}
public override void FindFrame(int frameHeight)
{
if (npc.frameCounter++ >= 10)
{
npc.frame.Y = (npc.frame.Y + frameHeight) % (Main.npcFrameCount[npc.type] * frameHeight);
npc.frameCounter = 0;
}
npc.spriteDirection = npc.direction;
}
public override void AI()
{
npc.ai[0]++;
Player P = Main.player[npc.target];
if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
{
npc.TargetClosest(true);
}
npc.netUpdate = true;

npc.ai[1]++;
if (npc.ai[1] >= 150) // 230 is projectile fire rate
{
float Speed = 10f; //projectile speed
Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
int damage = 30; //projectile damage
int type = mod.ProjectileType("PuritySpiritProjectile"); //put your projectile
Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
npc.ai[1] = 0;
}
}
}
}
 
The Sprites work but the AI still doesnt :/ it still is standing in one place

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

using System.Threading.Tasks;

namespace MiscItems.NPCs
{
class PuritySpirit : ModNPC
{
public override void SetDefaults()
{
npc.name = "PuritySpirit";
npc.displayName = "Purity Spirit";
npc.width = 80;
npc.height = 320;
npc.damage = 50;
npc.defense = 5;
npc.lifeMax = 400;
npc.value = 60f;
npc.knockBackResist = 0.5f;
aiType = NPCID.EaterofSouls;
Main.npcFrameCount[npc.type] = 2;
}

public override float CanSpawn(NPCSpawnInfo spawnInfo)
{
if (spawnInfo.player.ZoneHoly)
return 0.5F;
return 0;
}
public override void NPCLoot() //Npc drop
{
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("SoulOfPurity"), 2); //Item spawn
}

}
public override void FindFrame(int frameHeight)
{
if (npc.frameCounter++ >= 10)
{
npc.frame.Y = (npc.frame.Y + frameHeight) % (Main.npcFrameCount[npc.type] * frameHeight);
npc.frameCounter = 0;
}
npc.spriteDirection = npc.direction;
}
public override void AI()
{
npc.ai[0]++;
Player P = Main.player[npc.target];
if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
{
npc.TargetClosest(true);
}
npc.netUpdate = true;

npc.ai[1]++;
if (npc.ai[1] >= 150) // 230 is projectile fire rate
{
float Speed = 10f; //projectile speed
Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
int damage = 30; //projectile damage
int type = mod.ProjectileType("PuritySpiritProjectile"); //put your projectile
Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
npc.ai[1] = 0;
}
}
}
}
Allright, the AI code you have might actually interfere with the vanilla AI you're calling.
Take a look at the following:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

using System.Threading.Tasks;

namespace MiscItems.NPCs
{
    class PuritySpirit : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "PuritySpirit";
            npc.displayName = "Purity Spirit";
            npc.width = 80;
            npc.height = 320;
            npc.damage = 50;
            npc.defense = 5;
            npc.lifeMax = 400;
            npc.value = 60f;
            npc.knockBackResist = 0.5f;
            aiType = NPCID.EaterofSouls;
            Main.npcFrameCount[npc.type] = 2;
        }

        public override float CanSpawn(NPCSpawnInfo spawnInfo)
        {
            if (spawnInfo.player.ZoneHoly)
                return 0.5F;
            return 0;
        }
        public override void NPCLoot() //Npc drop
        {
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("SoulOfPurity"), 2); //Item spawn
        }
      
        public override void FindFrame(int frameHeight)
        {
            if (npc.frameCounter++ >= 10)
            {
                npc.frame.Y = (npc.frame.Y + frameHeight) % (Main.npcFrameCount[npc.type] * frameHeight);
                npc.frameCounter = 0;
            }
            npc.spriteDirection = npc.direction;
        }
      
        int timer;
        public override void AI()
        {
            Player P = Main.player[npc.target];
            if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
            {
                npc.TargetClosest(true);
            }
            npc.netUpdate = true;

            timer++;
            if (timer >= 150) // 230 is projectile fire rate
            {
                float Speed = 10f; //projectile speed
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                int damage = 30; //projectile damage
                int type = mod.ProjectileType("PuritySpiritProjectile"); //put your projectile
                Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
                float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
                int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
                timer = 0;
            }
        }
    }
}
As you can see, I replaced npc.ai[0] with a variable called timer. This will make sure that this code does not interfere with the vanilla AI.

EDIT:
Do note that this newly created timer variable does not automatically sync over network. You'll have to do that manually.
 
Do any of you know how to make a custom health potion i will like to know
That's actually fairly simple. If you know how to create a 'normal' item, all you want to add is:
Code:
public override void SetDefaults()
{
    // Things like name, width, height, etc.
    
    item.useStyle = 2;
    item.useAnimation = 17;
    item.useTime = 17;

    item.useTurn = false;

    // The amount of life that's healed when using the potion.
    this.healLife = 15;

    this.consumable = true;
    this.potion = true;
}

Now that thing moves but... its going backwards and staying on the ground...
So it's more like a fighter AI?
 
Hey, I'm trying to make it so when I swing a weapon it has a custom sound, but even though there are no errors, when I swing it, there is no sound...
Here's some code.

Sound code:
Code:
using Microsoft.Xna.Framework.Audio;
using Terraria;
using Terraria.ModLoader;

namespace ModOfRandomness.Sounds
{
    public class TheViolinSound : ModSound
    {
        public override SoundEffectInstance PlaySound(ref SoundEffectInstance soundInstance, float volume, float pan, SoundType type)
        {
            soundInstance = sound.CreateInstance();
            soundInstance.Volume = volume * .5f;
            soundInstance.Pan = pan;
            soundInstance.Pitch = -1.0f;
            return soundInstance;
        }
    }
}

Item code:
Code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace ModOfRandomness.Items
{
    public class TheViolin : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "The Violin";     //the name displayed when hovering over the Weapon ingame.
            item.damage = 24;     //The damage stat for the Weapon.
            item.melee = true;      //This defines if it does Melee damage and if its effected by Melee increasing Armor/Accessories.
            item.width = 58;   //The size of the width of the hitbox in pixels.
            item.height = 58;  //The size of the height of the hitbox in pixels.
            item.toolTip = "There is someone out there who uses a violin for smashing zombies faces in...";    //The description of the Weapon shown when hovering over the Weapon ingame.
            item.useTime = 10;   //How fast the Weapon is used.
            item.useAnimation = 10;     //How long the Weapon is used for.
            item.useStyle = 1;            //The way your Weapon will be used, 1 is the regular sword swing for example
            item.knockBack = 6;  //The knockback stat of your Weapon.
            item.value = Item.buyPrice(0, 1, 0, 0); // How much the item is worth, in copper coins, when you sell it to a merchant. It costs 1/5th of this to buy it back from them. An easy way to remember the value is platinum, gold, silver, copper or PPGGSSCC (so this item price is 10gold)
            item.rare = 2;    //The color the title of your Weapon when hovering over it ingame
            item.UseSound = mod.GetLegacySoundSlot(SoundType.Item, "Sounds/TheViolinSound");
            item.autoReuse = true; //Weather your Weapon will be used again after use while holding down, if false you will need to click again after use to use it again.
        }
    }
}

It might be the format of the audio file, I've tried .mp3 and .wav but nothing.
 
Also if any1 knows how pls tell me - how do i keep mana at 0 while keeping the mana stars with an accessory?
 
Back
Top Bottom