tModLoader Official tModLoader Help Thread

Hey, i'm back and have two questions~
One, how do I make a mob spawn during an eclipse/event~?
I've been trying a lot looking through the example mod and internet but haven't found anything which works
Code:
        public override float CanSpawn(NPCSpawnInfo spawnInfo)
        {
            Tile tile = Main.tile[spawnInfo.spawnTileX, spawnInfo.spawnTileY];
            return spawnInfo.invasion.Maineclipse ? 0.5f : 0f;
        }

Two, what makes an npc spawn other npcs?
I have some code but it doesn't seem to work~
Code:
            if (npc.ai[0] % 600 == 3)

            {
                NPC.NewNPC((int)npc.position.X, (int)npc.position.Y, mod.NPCType("GreaterPixie"));
            }
            npc.ai[1] += 0;

If you want to test for a solar eclipse you could try Main.eclipse
It's also used in the original source code.
 
If you want to test for a solar eclipse you could try Main.eclipse
It's also used in the original source code.
I've tried that but to no success~
Anyways, the original source code doesn't like just doesn't like me~ ;w;

Edit: this is the reason, no idea why it thinks I'm asking for a bool but it is~
0tVqpVZ.jpg
 
Last edited:
Okay, I have some questions.
1. How do I make a projectile give off colored light?
2. How do I change the hitbox of the projectile, but still have the same width and height?
 
Last edited:
Uhhhhh....

My Fennekin is stuck in the ground.

21ee9a91e0.png


I tried a few things - none of which actually worked. Does anyone know how to fix this (or have a shovel I can borrow)?

Here is Fennekin's code

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

namespace PokemonVanity.Projectiles.Pets
{
    public class FennekinPet : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(ProjectileID.Bunny);
            projectile.name = "Fennekin Pet";
            aiType = ProjectileID.Bunny;
            Main.projFrames[projectile.type] = 8;
            Main.projPet[projectile.type] = true;
        }

        public override bool PreAI()
        {
            Player player = Main.player[projectile.owner];
            player.bunny = false; // Relic from aiType
            return true;
        }

        public override void AI()
        {
            Player player = Main.player[projectile.owner];
            PokemonPlayer modPlayer = player.GetModPlayer<PokemonPlayer>(mod);
            if (player.dead)
            {
                modPlayer.fennekinPet = false;
            }
            if (modPlayer.fennekinPet)
            {
                projectile.timeLeft = 2;
            }
        }
    }
}
 
Okay, I have some questions.
1. How do I make a projectile give off colored light?
2. How do I change the hitbox of the projectile, but still have the same width and height?
Width and height are the hitbox dimensions. The width and height of the texture is the size of what is drawn.

You can use this and similar to position the hitbox's top left corner. https://github.com/bluemagic123/tModLoader/wiki/ModProjectile#public-int-draworiginoffsety

Uhhhhh....

My Fennekin is stuck in the ground.

21ee9a91e0.png


I tried a few things - none of which actually worked. Does anyone know how to fix this (or have a shovel I can borrow)?

Here is Fennekin's code

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

namespace PokemonVanity.Projectiles.Pets
{
    public class FennekinPet : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(ProjectileID.Bunny);
            projectile.name = "Fennekin Pet";
            aiType = ProjectileID.Bunny;
            Main.projFrames[projectile.type] = 8;
            Main.projPet[projectile.type] = true;
        }

        public override bool PreAI()
        {
            Player player = Main.player[projectile.owner];
            player.bunny = false; // Relic from aiType
            return true;
        }

        public override void AI()
        {
            Player player = Main.player[projectile.owner];
            PokemonPlayer modPlayer = player.GetModPlayer<PokemonPlayer>(mod);
            if (player.dead)
            {
                modPlayer.fennekinPet = false;
            }
            if (modPlayer.fennekinPet)
            {
                projectile.timeLeft = 2;
            }
        }
    }
}

Mess around with this value: https://github.com/bluemagic123/tModLoader/wiki/ModProjectile#public-int-draworiginoffsety
 
Uhhhhh....

My Fennekin is stuck in the ground.

21ee9a91e0.png


I tried a few things - none of which actually worked. Does anyone know how to fix this (or have a shovel I can borrow)?

Here is Fennekin's code

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

namespace PokemonVanity.Projectiles.Pets
{
    public class FennekinPet : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.CloneDefaults(ProjectileID.Bunny);
            projectile.name = "Fennekin Pet";
            aiType = ProjectileID.Bunny;
            Main.projFrames[projectile.type] = 8;
            Main.projPet[projectile.type] = true;
        }

        public override bool PreAI()
        {
            Player player = Main.player[projectile.owner];
            player.bunny = false; // Relic from aiType
            return true;
        }

        public override void AI()
        {
            Player player = Main.player[projectile.owner];
            PokemonPlayer modPlayer = player.GetModPlayer<PokemonPlayer>(mod);
            if (player.dead)
            {
                modPlayer.fennekinPet = false;
            }
            if (modPlayer.fennekinPet)
            {
                projectile.timeLeft = 2;
            }
        }
    }
}
Looks like you use the Bunny AI for your pet. But your pet is bigger(in pixels) than a bunny. Can it still move right and left freely ?
 
Looks like you use the Bunny AI for your pet. But your pet is bigger(in pixels) than a bunny. Can it still move right and left freely ?

Yes it can. Is there another way to do pet AI that would fit my sprite?

EDIT: oh, and I used the bunny's original spritesheet as a base for Fennekin's
 
Last edited:
Could you show line 34 in the file OrigamiMan ?
That is line 34~
Just to save you some time, (^NPCSpawnInfo is the part it's pointing to~
The ^ arrow should signify it~

And just to save you some more time~
Code:
34    public override float CanSpawn(NPCSpawnInfo spawnInfo)
35    {
36    Tile tile = Main.tile[spawnInfo.spawnTileX, spawnInfo.spawnTileY];
37    return spawnInfo.invasion.Maineclipse ? 0.5f : 0f;
38    }
 
That is line 34~
Just to save you some time, (^NPCSpawnInfo is the part it's pointing to~
The ^ arrow should signify it~

And just to save you some more time~
Code:
34    public override float CanSpawn(NPCSpawnInfo spawnInfo)
35    {
36    Tile tile = Main.tile[spawnInfo.spawnTileX, spawnInfo.spawnTileY];
37    return spawnInfo.invasion.Maineclipse ? 0.5f : 0f;
38    }

I don't remember spawnInfo.invasion being a class.

try changing
Code:
return spawnInfo.invasion.Maineclipse ? 0.5f : 0f;
to this
Code:
return Main.eclipse ? 0.5f : 0f;
 
Yes it can. Is there another way to do pet AI that would fit my sprite?

EDIT: oh, and I used the bunny's original spritesheet as a base for Fennekin's

Like jopojelly said you could mess around with the drawOriginOffset thing.
I didn't create any NPCs yet but maybe adding
Code:
drawOriginOffsetY -= 10;
to the PreAI function would work. If it's still stuck in the ground then mess around with the number at the end.
 
Like jopojelly said you could mess around with the drawOriginOffset thing.
I didn't create any NPCs yet but maybe adding
Code:
drawOriginOffsetY -= 10;
to the PreAI function would work. If it's still stuck in the ground then mess around with the number at the end.

I'll try that

EDIT: Fennekin ran away. After adding that code, Fennekin would just fly off to the east and never come back. ;(
 
Last edited:
Wait a second. East?
It should actually move north... I mean straight up.
Make sure it's called drawOriginOffsetY and not drawOriginOffsetX.
 
Last edited:
Back
Top Bottom