Standalone [1.3] tModLoader - A Modding API

What exactly would you do (in tile sheet sprites) to make the tile mesh together with another custom tile?
I'm really, really confused.
EDIT: For more clarification, it's like how the Example Block meshes with the dirt block on the tile sheet.
 
What exactly would you do (in tile sheet sprites) to make the tile mesh together with another custom tile?
I'm really, really confused.
EDIT: For more clarification, it's like how the Example Block meshes with the dirt block on the tile sheet.
Code:
Main.tileMerge[Type][mod.TileType("ModTileBlock")] = true;
I'll have to dig up the vanilla block merge too.
 
Here's some very basic homing code.
Code:
public override void AI()
{
Vector2 acceleration = Vector2.Normalize(Main.MouseWorld - projectile.Center); //convert the distance from this projectile to the mouse to a unit-vector
projectile.velocity += acceleration * 1.5f; //add one and a half of my acceleration to my velocity
projectile.velocity *= 0.95f; //slow down slightly, i.e. apply drag
projectile.rotation = projectile.velocity.ToRotation(); //calculate the direction that this projectile is going and rotate to face that way.
}
I hope that's enough to get you started.

this is homing on the mouse. I'm assuming that is because of Main.MouseWorld. What would I replace that with in order to home enemies.

i tried

Code:
public NPC FindNearest(Vector2 pos)
        {
            NPC nearest = null;
            float oldDist = 1001;
            float newDist = 1000;
            for (int i = 0; i < Terraria.Main.npc.Length - 1; i++)
            {
                if (Terraria.Main.npc.friendly == true)
                    continue;
                if (Terraria.Main.npc.active == false)
                    continue;
                if (Terraria.Main.npc.damage == 0)
                    continue;
                if (nearest == null)
                    nearest = Terraria.Main.npc;
                else
                {
                    oldDist = Vector2.Distance(pos, nearest.position);
                    newDist = Vector2.Distance(pos, Terraria.Main.npc.position);
                    if (newDist < oldDist)
                        nearest = Terraria.Main.npc;
                }
            }
            return nearest;
        }
and the replaced Main.MouseWorld with nearest but then there were errors saying that friendly, active, and damage are not a things under npc.
I'm assuming there is a better way of trying this.
help pls

I am sooo lost.
 
Code:
public NPC FindNearest(Vector2 pos)
        {
            NPC nearest = null;
            float oldDist = 1001;
            float newDist = 1000;
            for (int i = 0; i < Terraria.Main.npc.Length - 1; i++)
            {
                if (Terraria.Main.npc[i].friendly == true)
                    continue;
                if (Terraria.Main.npc[i].active == false)
                    continue;
                if (Terraria.Main.npc[i].damage == 0)
                    continue;
                if (nearest == null)
                    nearest = Terraria.Main.npc[i];
                else
                {
                    oldDist = Vector2.Distance(pos, nearest.position);
                    newDist = Vector2.Distance(pos, Terraria.Main.npc[i].position);
                    if (newDist < oldDist)
                        nearest = Terraria.Main.npc[i];
                }
            }
            return nearest;
        }
        public override void AI()
        {
            Vector2 acceleration = Vector2.Normalize(nearest - projectile.Center);
            projectile.velocity += acceleration * 1.5f;
            projectile.velocity *= 0.95f;
            projectile.rotation = projectile.velocity.ToRotation();
        }
 
Those are two different methods, as the error says, 'nearest' doesn't exist inside of AI(), it is a local variable that only exists inside of FindNearest(). You have to use your new method inside AI() for it to do anything. For example, you could define a 'nearest' variable in the AI() method like:

Code:
NPC nearest = this.FindNearest(projectile.Center);

But, you couldn't do 'nearest - projectile.Center' because FindNearest() returns an NPC object and 'projectile.Center' is a Vector2 object and you can't subtract a Vector2 from a NPC. You would have to do something like 'nearest.Center - projectile.Center'.
 
v0.8.2
-Added SaveCustomData and LoadCustomData hooks for GlobalItem
-Added client/server sync hooks for ModWorld
-Added client/server sync hooks for ModPlayer custom biomes
-Added hook for complete control over all item tooltips
-Added CanUseAbility and UseAbility hooks for ModMountData
-Added RecipeFinder and RecipeEditor for easy recipe editing
-Added hook for drawing NPC health bars
-Support for preserving unloaded mod tiles
-Name property for mod textures are now assigned
-Animations for opening/closing modded chests
-Made Main.DrawHealthBar public
-Made Terraria.Graphics.Shaders.GameShaders public
-Fixed bug where ConsumeItem is called for wrong item
-RecipeGroup bugfixes

I hope I didn't make any mistake with uploading anything, v0.8.1.2 and v0.8.2 look too similar...

Anyways, I highly highly recommend backing up all your save files before using this update. It makes several changes to how stuff are saved.

With all that being said, this update's basically "everything else" that doesn't fit into any category that we didn't have time to do earlier. Hopefully this takes care of most of the miscellaneous stuff before we move onto other major features like biomes. There's lots of cool stuff here that I'm happy about, especially ModifyTooltips, RecipeFinder, RecipeEditor, and preserving unloaded tiles. There might also be tons of bugs related to these features though, so make sure to report any you find!

One more thing I want to say. Progress this summer won't be nearly as fast as the complete craziness that was last summer. Not only am I tired from a particularly exhausting year of school, but I also want to make some progress on a game of my own. I also got a graphics tablet a couple of days ago and want to teach myself how to draw. Progress will still be definitely faster than while I was in school, but it won't quite match last year when I was basically working on this all day every day.
 
my projectile is now homing in on enemies even if they are beyond walls.
is there an if statement that I can throw in FindNearest to stop this or do I have to rewrite everything?


also

YAY for the new update
 
v0.8.2
-Added SaveCustomData and LoadCustomData hooks for GlobalItem
-Added client/server sync hooks for ModWorld
-Added client/server sync hooks for ModPlayer custom biomes
-Added hook for complete control over all item tooltips
-Added CanUseAbility and UseAbility hooks for ModMountData
-Added RecipeFinder and RecipeEditor for easy recipe editing
-Added hook for drawing NPC health bars
-Support for preserving unloaded mod tiles
-Name property for mod textures are now assigned
-Animations for opening/closing modded chests
-Made Main.DrawHealthBar public
-Made Terraria.Graphics.Shaders.GameShaders public
-Fixed bug where ConsumeItem is called for wrong item
-RecipeGroup bugfixes

I hope I didn't make any mistake with uploading anything, v0.8.1.2 and v0.8.2 look too similar...

Anyways, I highly highly recommend backing up all your save files before using this update. It makes several changes to how stuff are saved.

With all that being said, this update's basically "everything else" that doesn't fit into any category that we didn't have time to do earlier. Hopefully this takes care of most of the miscellaneous stuff before we move onto other major features like biomes. There's lots of cool stuff here that I'm happy about, especially ModifyTooltips, RecipeFinder, RecipeEditor, and preserving unloaded tiles. There might also be tons of bugs related to these features though, so make sure to report any you find!

One more thing I want to say. Progress this summer won't be nearly as fast as the complete craziness that was last summer. Not only am I tired from a particularly exhausting year of school, but I also want to make some progress on a game of my own. I also got a graphics tablet a couple of days ago and want to teach myself how to draw. Progress will still be definitely faster than while I was in school, but it won't quite match last year when I was basically working on this all day every day.
Wait, does this mean that all the mods that I just installed won't work now..? Dayum.
 
my projectile is now homing in on enemies even if they are beyond walls.
is there an if statement that I can throw in FindNearest to stop this or do I have to rewrite everything?


also

YAY for the new update
You'll need to add the following to the list of if checks.
Code:
if (!Collision.CanHit(pos, 1, 1, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height))//Don't target NPC's I can't see
    continue;
Also, I forgot to mention that my findNearest function will return null if it doesn't find anything to target, which will cause an error. Use the following inside your AI to prevent this.
Code:
NPC nearNPC = FindNearest(projectile.Center);
Vector2 acceleration = Vector2.Zero;
if (nearNPC != null)
{
    acceleration = Vector2.Normalize(nearNPC.position - projectile.Center);
} else
{
    //this bit is optional, but you can get your projectile to accelerate differently here
}
projectile.velocity += acceleration * 1.5f;
projectile.velocity *= 0.95f;
projectile.rotation = projectile.velocity.ToRotation();
 
Back
Top Bottom