Standalone [1.3] tModLoader - A Modding API

so, what are you trrying to do that you need a homing projctile
I Have this weapon that shoots this slow projectile, and so It usually misses, so I want to make it a more viable choice by making it home in on enemies. I have no code in any of it attempting homing accept for
Code:
ProjectileID.Sets.Homing[projectile.type] = true;
which doesn't do any thing
 
Help how to fix this if my npc stay on the grass and its hammered come so thin black line above him and if he come to normal dirt block it disappears??
 
I Have this weapon that shoots this slow projectile, and so It usually misses, so I want to make it a more viable choice by making it home in on enemies. I have no code in any of it attempting homing accept for
Code:
ProjectileID.Sets.Homing[projectile.type] = true;
which doesn't do any thing
You'll probably need to write your own AI then, but I can show you some code snippets to get you started. When I wanted to make a homing projectile of my own, I started by writing a function that iterates through all NPCs to select which one to target.
//Find the nearest NPC
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++) //Do once for each NPC in the world
{
if (Terraria.Main.npc.friendly == true)//Don't target town NPCs
continue;
if (Terraria.Main.npc.active == false)//Don't target dead NPCs
continue;
if (Terraria.Main.npc.damage == 0)//Don't target non-aggressive NPCs
continue;
if (nearest == null) //if no NPCs have made it past the previous few checks
nearest = Terraria.Main.npc; //become the nearest NPC
else
{
oldDist = Vector2.Distance(pos, nearest.position);//Check the distance to the nearest NPC that's earlier in the loop
newDist = Vector2.Distance(pos, Terraria.Main.npc.position);//Check the distance to the current NPC in the loop
if (newDist < oldDist)//If closer than the previous NPC in the loop
nearest = Terraria.Main.npc;//Become the nearest NPC
}
}
return nearest; //return the npc that is nearest to the vector 'pos'
}
Then I'd simply need to write "NPC nearestNPC = FindNearest(projectile.Center);" in my AI to find which NPC is nearest to the projectile's center. But recently I looked through the games code, and found the following code snippet.
int num3;
for (int num33 = 0; num33 < 200; num33 = num3 + 1)
{
if (Main.npc[num33].CanBeChasedBy(this, false))
{
float num34 = Main.npc[num33].position.X + (float)(Main.npc[num33].width / 2);
float num35 = Main.npc[num33].position.Y + (float)(Main.npc[num33].height / 2);
float num36 = Math.Abs(this.position.X + (float)(this.width / 2) - num34) + Math.Abs(this.position.Y + (float)(this.height / 2) - num35);
if (num36 < 800f && Collision.CanHit(new Vector2(this.position.X + (float)(this.width / 2), this.position.Y + (float)(this.height / 2)), 1, 1, Main.npc[num33].position, Main.npc[num33].width, Main.npc[num33].height))
{
num31 = num34;
num32 = num35;
flag = true;
}
}
num3 = num33;
}
This uses NPC.CanBeChasedBy() to exclude any NPC's that you don't want to target and Collision.CanHit() to check if it has line of sight with each NPC, which my function didn't.

Once I know which NPC I'm targeting, I like to spawn dust at it's location simply so that I have a visual indication of which NPC is being targeted.

Also, here's some code that makes a projectile home in on the mouse's position. It's not quite self contained, but there's enough there to work with.
//mPos = Main.mouseWorld;//get the mouses position in the world
targPos = findTarget(); //Find the thing I want to home in on -- use your target's position instead
toMouse = (float)Math.Atan2(targPos.Y - projectile.position.Y, targPos.X - projectile.position.X); //calculate a bearing to that thing

if (Main.player[projectile.owner].gravDir == -1f) //if my player is upside down
targPos.Y = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY;//reverse the vertical position of my mouse

//accelerate towards my target
projectile.velocity.X += (float)Math.Cos(toMouse) * acel * randVel; //acel is a float that controls how fast the projectile accelerates. randVel is a random modifier to the acceleration.
projectile.velocity.Y += (float)Math.Sin(toMouse) * acel * randVel;

if (Math.Sqrt(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y) > maxSpeed) //if going too fast
{
//Main.NewText("Max!");
projectile.velocity *= 1 - (acel / maxSpeed); //slow down a little bit
}
None of this code is going to work straight off, it will all need work to suit your needs. But I hope you find it helpful.

Edit: huh, looks like spoiler tags aren't the things to put code into.
 
Last edited:
Am I the only person having trouble downloading the 8.1.2 update? for some reason whenever I try to launch the program, i can use the 8.0 update but not anything new, is there something I can do to make it work?
 
Help how to fix this if my npc stay on the grass and its hammered come so thin black line above him and if he come to normal dirt block it disappears??
screenshot :
Link- https://s31.postimg.org/zb7tryhob/20160618161050_1.jpg

20160618161050_1.jpg
 
Missing mod: MadCrafter/Items/Dreams
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.Mod.SetupContent()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

I get this error with everything I do, no one tells me how to fix it.
tModLoader cannot find the texture for the item, make sure the namespace is as specific as possible. For example, say TestDinosaur.png is in Dinosauria/Items/Test. If the namespace is Dinosauria.Items, it won't work because tModLoader will look for the texture in Dinosauria/Items, not Dinosauria/Items/Test. In this case the namespace must be Dinosauria.Items.Test for it to look for the texture in the Test folder.
 
Anybody know how to set the dimensions of tiles correctly? I am trying to add this texture into the game:
DinosaurForge.png


I got this instead:
20160618095950_1.jpg

(The pink tile on the left is what gets placed down, the transparent one is what the tile looks like before being placed.)
Here's the code, I'm not sure if I am missing parameters or any code for defining the tile.
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ObjectData;

namespace DinosauriaPrimal.Tiles
{
    public class DinosaurForge : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolidTop[Type] = true;
            Main.tileFrameImportant[Type] = true;
            Main.tileNoAttach[Type] = true;
            Main.tileLavaDeath[Type] = true;
            TileObjectData.newTile.CopyFrom(TileObjectData.Style3x4);
            TileObjectData.newTile.CoordinateHeights = new int[] { 16 };
            TileObjectData.addTile(Type);
            TileObjectData.newTile.Height = 54;
            TileObjectData.newTile.Width = 90;
            AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch);
            AddMapEntry(new Color(200, 200, 200), "Saurus Forge");
            dustType = 2;
            disableSmartCursor = true;
            adjTiles = new int[] { TileID.WorkBenches };
        }

        public override void NumDust(int i, int j, bool fail, ref int num)
        {
            num = fail ? 1 : 3;
        }

        public override void KillMultiTile(int i, int j, int frameX, int frameY)
        {
            Item.NewItem(i * 90, j * 54, 90, 54, mod.ItemType("Saurus Forge"));
        }
    }
}


If anybody could help me out it would be very appreciated.
 
Anybody know how to set the dimensions of tiles correctly? I am trying to add this texture into the game:
View attachment 119026

I got this instead:
View attachment 119028
(The pink tile on the left is what gets placed down, the transparent one is what the tile looks like before being placed.)
Here's the code, I'm not sure if I am missing parameters or any code for defining the tile.
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ObjectData;

namespace DinosauriaPrimal.Tiles
{
    public class DinosaurForge : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolidTop[Type] = true;
            Main.tileFrameImportant[Type] = true;
            Main.tileNoAttach[Type] = true;
            Main.tileLavaDeath[Type] = true;
            TileObjectData.newTile.CopyFrom(TileObjectData.Style3x4);
            TileObjectData.newTile.CoordinateHeights = new int[] { 16 };
            TileObjectData.addTile(Type);
            TileObjectData.newTile.Height = 54;
            TileObjectData.newTile.Width = 90;
            AddToArray(ref TileID.Sets.RoomNeeds.CountsAsTorch);
            AddMapEntry(new Color(200, 200, 200), "Saurus Forge");
            dustType = 2;
            disableSmartCursor = true;
            adjTiles = new int[] { TileID.WorkBenches };
        }

        public override void NumDust(int i, int j, bool fail, ref int num)
        {
            num = fail ? 1 : 3;
        }

        public override void KillMultiTile(int i, int j, int frameX, int frameY)
        {
            Item.NewItem(i * 90, j * 54, 90, 54, mod.ItemType("Saurus Forge"));
        }
    }
}


If anybody could help me out it would be very appreciated.
Read the Tile guide in my signature and ask if you still have questions. For one thing, your coordinate heights is wrong.
 
So I was trying to make my own mod and everything was goin great, then i got this error


c:\Users\Brady\Documents\My Games\Terraria\ModLoader\Mod Sources\OPMod\OPMod.cs(8,11) : error CS0234: The type or namespace name 'Items' does not exist in the namespace 'MOD' (are you missing an assembly reference?)

HALP!
 
Back
Top Bottom