Standalone [1.3] tModLoader - A Modding API

Besides, I use it so I know it works.

lmao I just read the list of versions it allowed me to switch between - didn't see that at the top. Do you know if the save location issue is still a problem, or if I can change the save location? Surely I must be able to...
 
lmao I just read the list of versions it allowed me to switch between - didn't see that at the top. Do you know if the save location issue is still a problem, or if I can change the save location? Surely I must be able to...
It seems like the path is hardcoded. I guess tModLoader changes the map format no matter what mods you have.
EDIT: wait! It seems like you could change the save path by changing the -savedirectory argument when you launch Terraria.exe. It's probably worth a try?
 
Last edited:
What exactly happens to your characters and worlds when you download this with other mods? What happens to your new characters when you uninstall? I just want to be safe here.
 
What exactly happens to your characters and worlds when you download this with other mods? What happens to your new characters when you uninstall? I just want to be safe here.
Every item from the mod becomes "unloaded".




I need help. How do I get it so my NPC, randomly shoots 4 different projectiles. I have the code for it to shoot 2, but I need more than that.
Code:
        npc.ai[0]++;
            if (npc.ai[0] > 80)
            {
                if (npc.HasValidTarget && Main.player[npc.target].Distance(npc.Center) < 500f)
                {
                    Vector2 direction = Main.player[npc.target].Center - npc.Center;
                    direction.Normalize();
                    if (Main.rand.Next(2) == 0)
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicOrb"), 10, 1, Main.myPlayer, 0, 0);
                    }
                    else
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicDagger"), 10, 1, Main.myPlayer, 0, 0);
                    }
                    npc.ai[0] = 0;
                }
            }
And second, how do you make the boss summon minions?
 
Every item from the mod becomes "unloaded".




I need help. How do I get it so my NPC, randomly shoots 4 different projectiles. I have the code for it to shoot 2, but I need more than that.
Code:
        npc.ai[0]++;
            if (npc.ai[0] > 80)
            {
                if (npc.HasValidTarget && Main.player[npc.target].Distance(npc.Center) < 500f)
                {
                    Vector2 direction = Main.player[npc.target].Center - npc.Center;
                    direction.Normalize();
                    if (Main.rand.Next(2) == 0)
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicOrb"), 10, 1, Main.myPlayer, 0, 0);
                    }
                    else
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicDagger"), 10, 1, Main.myPlayer, 0, 0);
                    }
                    npc.ai[0] = 0;
                }
            }
And second, how do you make the boss summon minions?
That's very simple, you'll just want to apply the same logic for four different projectiles:
Code:
int rand = Main.rand.Next(0, 4);
if(rand == 0)
{
    // Projectile 1
}
else if(rand == 1)
{
    // Projectile 2
}
else if(rand == 2)
{
    // Projectile 3
}
else 
{
    // Projectile 4
}
 
That's very simple, you'll just want to apply the same logic for four different projectiles:
Code:
int rand = Main.rand.Next(0, 4);
if(rand == 0)
{
    // Projectile 1
}
else if(rand == 1)
{
    // Projectile 2
}
else if(rand == 2)
{
    // Projectile 3
}
else
{
    // Projectile 4
}
What Method do I put that under, and how do I call the projectile again? The same way from my other boss code?
[DOUBLEPOST=1453832143,1453832076][/DOUBLEPOST]
What Method do I put that under, and how do I call the projectile again? The same way from my other boss code?
Im assuming i put it under AI dont I
 
What Method do I put that under, and how do I call the projectile again? The same way from my other boss code?
[DOUBLEPOST=1453832143,1453832076][/DOUBLEPOST]
Im assuming i put it under AI dont I
Code:
if (npc.HasValidTarget && Main.player[npc.target].Distance(npc.Center) < 500f)
{
    Vector2 direction = Main.player[npc.target].Center - npc.Center;
    direction.Normalize();
    // Right here
    npc.ai[0] = 0;
}
And yeah, you'll want to use the same code for the projectiles (with different projectile types, ofc).
 
Ok, and one last thing. Say I want it to act the twins, where loot only drops when they are both dead. How would I get that effect? My Monsters are gonna be call Codex1 Codex2 Codex3 and Codex4. sorry for all of these questions
 
Ok, and one last thing. Say I want it to act the twins, where loot only drops when they are both dead. How would I get that effect? My Monsters are gonna be call Codex1 Codex2 Codex3 and Codex4. sorry for all of these questions
Hang on, so you've got 4 monsters and you want only the last one to drop the loot? Just checking.
 
yup. Also, Is there any way to slow down the spawning of projectiles? I just crashed from the immense amount of them
Code:
if (npc.ai[0] > 80)
See this check in your code? This basically checks if it's time to spawn another projectile. Increasing the '80' will result in a slower spawn rate of the projectiles.

Then there's the spawning of loot. The twins just keep track of each others index in the Main.npc array and resolve that by checking if that NPC is still active. This is in your case, however, not possible (or at least not practical). I'd advice the following (while it's probably still not the best way to go about it, you can be sure that it works:
Code:
public override void NPCLoot()
{
    if(!NPC.AnyNPCs(mod.NPCType("Codex2")) && !NPC.AnyNPCs(mod.NPCType("Codex3")) && !NPC.AnyNPCs(mod.NPCType("Codex4"))
    {
         // Spawn your loot.
    } 
}
Now this code is only for the Codex1 NPC, since it checks if none of the other Codex's are active. You'll want to also place this code in the other NPCs, but of course change the types around.

P.S.
Some little advice for the future: if someone gives you code, instead of straight away copy-pasting it, try 'copying' it by typing it out yourself. That way it might give you a little more insight in what's going on.
 
Code:
if (npc.ai[0] > 80)
See this check in your code? This basically checks if it's time to spawn another projectile. Increasing the '80' will result in a slower spawn rate of the projectiles.

Then there's the spawning of loot. The twins just keep track of each others index in the Main.npc array and resolve that by checking if that NPC is still active. This is in your case, however, not possible (or at least not practical). I'd advice the following (while it's probably still not the best way to go about it, you can be sure that it works:
Code:
public override void NPCLoot()
{
    if(!NPC.AnyNPCs(mod.NPCType("Codex2")) && !NPC.AnyNPCs(mod.NPCType("Codex3")) && !NPC.AnyNPCs(mod.NPCType("Codex4"))
    {
         // Spawn your loot.
    }
}
Now this code is only for the Codex1 NPC, since it checks if none of the other Codex's are active. You'll want to also place this code in the other NPCs, but of course change the types around.

P.S.
Some little advice for the future: if someone gives you code, instead of straight away copy-pasting it, try 'copying' it by typing it out yourself. That way it might give you a little more insight in what's going on.
Ok, thanks. Your really helpful.
[DOUBLEPOST=1453834511,1453834121][/DOUBLEPOST]
Ok, thanks. Your really helpful.
accully, I dont have that peice of code
 
the If (npc.ai[0] > 80)
You did in the piece of code you showed me:
Code:
if (npc.ai[0] > 80) // <----- HERE
{
    if (npc.HasValidTarget && Main.player[npc.target].Distance(npc.Center) < 500f)
    {
        Vector2 direction = Main.player[npc.target].Center - npc.Center;
        direction.Normalize();
        if (Main.rand.Next(2) == 0)
        {
            Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicOrb"), 10, 1, Main.myPlayer, 0, 0);
        }
        else
        {
            Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicDagger"), 10, 1, Main.myPlayer, 0, 0);
        }
        npc.ai[0] = 0;
    }
}
 
You did in the piece of code you showed me:
Code:
if (npc.ai[0] > 80) // <----- HERE
{
    if (npc.HasValidTarget && Main.player[npc.target].Distance(npc.Center) < 500f)
    {
        Vector2 direction = Main.player[npc.target].Center - npc.Center;
        direction.Normalize();
        if (Main.rand.Next(2) == 0)
        {
            Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicOrb"), 10, 1, Main.myPlayer, 0, 0);
        }
        else
        {
            Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicDagger"), 10, 1, Main.myPlayer, 0, 0);
        }
        npc.ai[0] = 0;
    }
}
Oh I mustve forgoten to copy that
[DOUBLEPOST=1453835298,1453834937][/DOUBLEPOST]
Code:
    using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Enderuim.NPCs
{
    //ported from my tAPI mod because I'm lazy
    public class Codex2 : ModNPC
    {
        public override void SetDefaults()
        {
            npc.displayName = "Phantom Codex";
            npc.aiStyle = -1;
            npc.lifeMax = 50000;
            npc.damage = 10;
            npc.defense = 10;
            npc.knockBackResist = 0f; //Immune to knockback
            npc.width = 200;
            npc.height = 200;
            npc.value = Item.buyPrice(0, 2, 0, 0);
            npc.boss = true;
            npc.lavaImmune = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            music = MusicID.Boss2;
        }

        public override void AI()
        {
            npc.TargetClosest(true);
            if (npc.ai[0] > 80)
                if (npc.HasValidTarget && Main.player[npc.target].Distance(npc.Center) < 500f)
                    {
                        Vector2 direction = Main.player[npc.target].Center - npc.Center;
                        direction.Normalize();
                        int rand = Main.rand.Next(0, 4);
                        if(rand == 0)
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicOrb"), 10, 1, Main.myPlayer, 0, 0);
                    }
                    else if(rand == 1)
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicOrb"), 10, 1, Main.myPlayer, 0, 0);
                    }
                    else if(rand == 2)
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicOrb"), 10, 1, Main.myPlayer, 0, 0);
                    }
                    else
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicOrb"), 10, 1, Main.myPlayer, 0, 0);
                    }
                        npc.ai[0] = 0;
                    }
            Player player = Main.player[npc.target];
            Vector2 moveTo = player.Center + new Vector2(0f, 200f);
            float speed = 5f; //make this whatever you want
            Vector2 move = moveTo - npc.Center; //this is how much your boss wants to move
            float magnitude = (float) Math.Sqrt(move.X * move.X + move.Y * move.Y);
            move *= speed / magnitude; //this adjusts your boss's speed so that its speed is always constant
            npc.velocity = move;
           
        }
       
    }
The Npc is no longer shooting the projectile at all.
 
Oh I mustve forgoten to copy that
[DOUBLEPOST=1453835298,1453834937][/DOUBLEPOST]
Code:
    using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Enderuim.NPCs
{
    //ported from my tAPI mod because I'm lazy
    public class Codex2 : ModNPC
    {
        public override void SetDefaults()
        {
            npc.displayName = "Phantom Codex";
            npc.aiStyle = -1;
            npc.lifeMax = 50000;
            npc.damage = 10;
            npc.defense = 10;
            npc.knockBackResist = 0f; //Immune to knockback
            npc.width = 200;
            npc.height = 200;
            npc.value = Item.buyPrice(0, 2, 0, 0);
            npc.boss = true;
            npc.lavaImmune = true;
            npc.noGravity = true;
            npc.noTileCollide = true;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            music = MusicID.Boss2;
        }

        public override void AI()
        {
            npc.TargetClosest(true);
            if (npc.ai[0] > 80)
                if (npc.HasValidTarget && Main.player[npc.target].Distance(npc.Center) < 500f)
                    {
                        Vector2 direction = Main.player[npc.target].Center - npc.Center;
                        direction.Normalize();
                        int rand = Main.rand.Next(0, 4);
                        if(rand == 0)
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicOrb"), 10, 1, Main.myPlayer, 0, 0);
                    }
                    else if(rand == 1)
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicOrb"), 10, 1, Main.myPlayer, 0, 0);
                    }
                    else if(rand == 2)
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicOrb"), 10, 1, Main.myPlayer, 0, 0);
                    }
                    else
                    {
                        Projectile.NewProjectile(npc.Center.X, npc.Center.Y, direction.X * 5f, direction.Y * 5f, mod.ProjectileType("DemonicOrb"), 10, 1, Main.myPlayer, 0, 0);
                    }
                        npc.ai[0] = 0;
                    }
            Player player = Main.player[npc.target];
            Vector2 moveTo = player.Center + new Vector2(0f, 200f);
            float speed = 5f; //make this whatever you want
            Vector2 move = moveTo - npc.Center; //this is how much your boss wants to move
            float magnitude = (float) Math.Sqrt(move.X * move.X + move.Y * move.Y);
            move *= speed / magnitude; //this adjusts your boss's speed so that its speed is always constant
            npc.velocity = move;
          
        }
      
    }
The Npc is no longer shooting the projectile at all.
That's because you're not even adding values to the npc.ai[0]...
Above this line: 'if (npc.ai[0] > 80)' add:
Code:
npc.ai[0]++;
 
Back
Top Bottom