tModLoader Official tModLoader Help Thread

Ok, got past that problem.
I put in a fast firing gun, but when it shoots, the sound doesn't match. It plays the sound every half second even though the gun and go through a stack off 999 fast then the chain gun.
the code:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace SWBF.Items.Weapons
{
public class DLT19 : ModItem
{
public override void SetDefaults()
{
item.name = "DLT-19";
item.damage = 5;
item.ranged = true;
item.width = 48;
item.height = 18;
item.toolTip = "A weak, but fast firing gun.";
item.useTime = 8;
item.useAnimation = 20;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 4;
item.value = 10000;
item.rare = 2;
item.useSound = 11;
item.autoReuse = true;
item.shoot = 10;
item.shootSpeed = 8f;
item.useAmmo = ProjectileID.Bullet;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.AddTile(TileID.WorkBenches);
recipe.SetResult(this);
recipe.AddRecipe();
}


}
}
 
Ok, got past that problem.
I put in a fast firing gun, but when it shoots, the sound doesn't match. It plays the sound every half second even though the gun and go through a stack off 999 fast then the chain gun.
the code:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace SWBF.Items.Weapons
{
public class DLT19 : ModItem
{
public override void SetDefaults()
{
item.name = "DLT-19";
item.damage = 5;
item.ranged = true;
item.width = 48;
item.height = 18;
item.toolTip = "A weak, but fast firing gun.";
item.useTime = 8;
item.useAnimation = 20;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 4;
item.value = 10000;
item.rare = 2;
item.useSound = 11;
item.autoReuse = true;
item.shoot = 10;
item.shootSpeed = 8f;
item.useAmmo = ProjectileID.Bullet;
}

public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.AddTile(TileID.WorkBenches);
recipe.SetResult(this);
recipe.AddRecipe();
}


}
}
If you want to make the sound happen as fast as the gun fires, make the useTime and useAnimation the same. The same happened to me until i finally figured it out :)
[doublepost=1480196553,1480196533][/doublepost]how would i make a modded item use a modded item? aka, i have souls of magic and want to make a magic arrow, but what do i put in the recipe.AddIngredient();?
 
I was making a shotgun, that was also a machine gun (directed here since i was posting questions about coding on the tmodloader forums, which it wasnt about) and it doesnt autofire. You have to spamclick to work it. I dont know why, but here is the code
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TestWeapon.Items.Weapons
{
public class ShotMachineGun : ModItem
{
public override void SetDefaults()
{
item.name = "Shot-Machine-Gun";
item.damage = 50;
item.ranged = true;
item.width = 40;
item.height = 20;
item.toolTip = "This is the fastest shotgun in the house.";
item.useTime = 2;
item.useAnimation = 2;
item.useStyle = 5;
item.noMelee = true; //so the item's animation doesn't do damage
item.knockBack = 7;
item.value = 10000;
item.rare = 2;
item.useSound = 14;
item.autoReuse = false;
item.shoot = 10; //idk why but all the guns in the vanilla source have this
item.shootSpeed = 14f;
item.useAmmo = ProjectileID.Bullet;
}

public override void AddRecipes() //How to craft this gun
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1); //you need 1 DirtBlock
recipe.AddTile(TileID.WorkBenches); //at work bench
recipe.SetResult(this);
recipe.AddRecipe();

}

public static Vector2[] randomSpread(float speedX, float speedY, int angle, int num)
{
var posArray = new Vector2[num];
float spread = (float)(angle * 0.0174532925);
float baseSpeed = (float)System.Math.Sqrt(speedX * speedX + speedY * speedY);
double baseAngle = System.Math.Atan2(speedX, speedY);
double randomAngle;
for (int i = 0; i < num; ++i)
{
randomAngle = baseAngle + (Main.rand.NextFloat() - 0.5f) * spread;
posArray = new Vector2(baseSpeed * (float)System.Math.Sin(randomAngle), baseSpeed * (float)System.Math.Cos(randomAngle));
}
return (Vector2[])posArray;
}

public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
Vector2[] speeds = randomSpread(speedX, speedY, 8, 6);
for (int i = 0; i < 5; ++i)
{
Projectile.NewProjectile(position.X, position.Y, speeds.X, speeds.Y, type, damage, knockBack, player.whoAmI);
}
return false;
}
}
}
 
I was making a shotgun, that was also a machine gun (directed here since i was posting questions about coding on the tmodloader forums, which it wasnt about) and it doesnt autofire. You have to spamclick to work it. I dont know why, but here is the code
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TestWeapon.Items.Weapons
{
public class ShotMachineGun : ModItem
{
public override void SetDefaults()
{
item.name = "Shot-Machine-Gun";
item.damage = 50;
item.ranged = true;
item.width = 40;
item.height = 20;
item.toolTip = "This is the fastest shotgun in the house.";
item.useTime = 2;
item.useAnimation = 2;
item.useStyle = 5;
item.noMelee = true; //so the item's animation doesn't do damage
item.knockBack = 7;
item.value = 10000;
item.rare = 2;
item.useSound = 14;
item.autoReuse = false;
item.shoot = 10; //idk why but all the guns in the vanilla source have this
item.shootSpeed = 14f;
item.useAmmo = ProjectileID.Bullet;
}

public override void AddRecipes() //How to craft this gun
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1); //you need 1 DirtBlock
recipe.AddTile(TileID.WorkBenches); //at work bench
recipe.SetResult(this);
recipe.AddRecipe();

}

public static Vector2[] randomSpread(float speedX, float speedY, int angle, int num)
{
var posArray = new Vector2[num];
float spread = (float)(angle * 0.0174532925);
float baseSpeed = (float)System.Math.Sqrt(speedX * speedX + speedY * speedY);
double baseAngle = System.Math.Atan2(speedX, speedY);
double randomAngle;
for (int i = 0; i < num; ++i)
{
randomAngle = baseAngle + (Main.rand.NextFloat() - 0.5f) * spread;
posArray = new Vector2(baseSpeed * (float)System.Math.Sin(randomAngle), baseSpeed * (float)System.Math.Cos(randomAngle));
}
return (Vector2[])posArray;
}

public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
Vector2[] speeds = randomSpread(speedX, speedY, 8, 6);
for (int i = 0; i < 5; ++i)
{
Projectile.NewProjectile(position.X, position.Y, speeds.X, speeds.Y, type, damage, knockBack, player.whoAmI);
}
return false;
}
}
}
Autoreuse has to be true.
 
I think I may have set the record for the fastest error building a mod ever; Every time I try to build the mod ingame it strands on the build.txt file.
It gives me an 'Input string was not in a correct format'-error.
This is the exact error message:
Code:
Failed to load C:\Users\Chad\Documents\My Games\Terraria\ModLoader\Mod Sources\chadsmasks\build.txt
System.FormatException: De indeling van de invoertekenreeks is onjuist.
   bij System.Version.VersionResult.SetFailure(ParseFailureKind failure, String argument)
   bij System.Version.TryParseComponent(String component, String componentName, VersionResult& result, Int32& parsedComponent)
   bij System.Version.TryParseVersion(String version, VersionResult& result)
   bij System.Version.Parse(String input)
   bij System.Version..ctor(String version)
   bij Terraria.ModLoader.BuildProperties.ReadBuildFile(String modDir)
   bij Terraria.ModLoader.ModCompile.ReadProperties(String modFolder, IBuildStatus status)
'De indeling van de invoertekenreeks is onjuist' roughly translates to 'Input string was not in a correct format'.
My build.txt file is set up exactly like that of the example mod, so I tried building that, and it gave me the same error. I noticed that the example mod is a handful of small patches behind on tmodloader, did something change about the way you format the build.txt file lately? Or am I just being dumb?
 
I think I may have set the record for the fastest error building a mod ever; Every time I try to build the mod ingame it strands on the build.txt file.
It gives me an 'Input string was not in a correct format'-error.
This is the exact error message:
Code:
Failed to load C:\Users\Chad\Documents\My Games\Terraria\ModLoader\Mod Sources\chadsmasks\build.txt
System.FormatException: De indeling van de invoertekenreeks is onjuist.
   bij System.Version.VersionResult.SetFailure(ParseFailureKind failure, String argument)
   bij System.Version.TryParseComponent(String component, String componentName, VersionResult& result, Int32& parsedComponent)
   bij System.Version.TryParseVersion(String version, VersionResult& result)
   bij System.Version.Parse(String input)
   bij System.Version..ctor(String version)
   bij Terraria.ModLoader.BuildProperties.ReadBuildFile(String modDir)
   bij Terraria.ModLoader.ModCompile.ReadProperties(String modFolder, IBuildStatus status)
'De indeling van de invoertekenreeks is onjuist' roughly translates to 'Input string was not in a correct format'.
My build.txt file is set up exactly like that of the example mod, so I tried building that, and it gave me the same error. I noticed that the example mod is a handful of small patches behind on tmodloader, did something change about the way you format the build.txt file lately? Or am I just being dumb?
You probably have a version string that is illegal. If you have only 1 number or more than 4, or characters such as v or beta or something. In the future, please post the code in question for better help.
 
You probably have a version string that is illegal. If you have only 1 number or more than 4, or characters such as v or beta or something. In the future, please post the code in question for better help.
That was indeed the problem, thanks :)
And yes, will do that in the future.
 
If i am making a boss, how would I make it shoot a lazer?
Edit: Got past that, now this is too confusing,
c:\Users\Matthew\Documents\My Games\Terraria\ModLoader\Mod Sources\TestWeapon\Items\FrogMachine.cs(30,13) : warning CS0162: Unreachable code detected

c:\Users\Matthew\Documents\My Games\Terraria\ModLoader\Mod Sources\TestWeapon\NPCs\Boss\SillyFrog.cs(45,19) : error CS0119: 'TestWeapon.Items.Weapons' is a 'namespace', which is not valid in the given context

Here is the code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace TestWeapon.NPCs.Boss
{
public class SillyFrog : ModNPC
{
public override void SetDefaults()
{
npc.name = "Silly Frog";
npc.displayName = "Silly Frog";
npc.aiStyle = 5; //5 is the flying AI
npc.lifeMax = 1000000; //boss life
npc.damage = 100; //boss damage
npc.defense = 100; //boss defense
npc.knockBackResist = 0f;
npc.width = 100;
npc.height = 100;
animationType = NPCID.Retinazer; //this boss will behavior like the DemonEye
Main.npcFrameCount[npc.type] = 2; //boss frame/animation
npc.value = Item.buyPrice(0, 40, 75, 45);
npc.npcSlots = 1f;
npc.boss = true;
npc.lavaImmune = true;
npc.noGravity = true;
npc.noTileCollide = true;
npc.soundHit = 8;
npc.soundKilled = 14;
npc.buffImmune[24] = true;
music = MusicID.Boss2;
npc.netAlways = true;
}
public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
{
bossHeadTexture = "TestWeapon/NPCs/Boss/SillyFrog_Head_Boss"; //the boss head texture
}
public override void BossLoot(ref string name, ref int potionType)
{
potionType = ItemID.GreaterHealingPotion; //boss drops
Items.Weapons((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("ShotMachineGun"));
}
public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
{
npc.lifeMax = (int)(npc.lifeMax * 0.579f * bossLifeScale); //boss life scale in expertmode
npc.damage = (int)(npc.damage * 0.6f); //boss damage increase in expermode
}
}
}
 
Last edited:
Hello everyone! I am trying to create a town npc that spawns only when a modded boss has been defeated. I have looked all over the internet and tried putting mods that had town npcs in tmodreader, but they would always block the codes. Here is my entire code for the town npc :

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

namespace SukiMod.NPCs
{
    public class ExamplePerson : ModNPC
    {
        public override bool Autoload(ref string name, ref string texture, ref string[] altTextures)
        {
            name = "Example Person";
            altTextures = new string[] { "SukiMod/NPCs/ExamplePerson_Alt_1" };
            return mod.Properties.Autoload;
        }

        public override void SetDefaults()
        {
            npc.name = "Example Person";
            npc.townNPC = true;
            npc.friendly = true;
            npc.width = 18;
            npc.height = 40;
            npc.aiStyle = 7;
            npc.damage = 10;
            npc.defense = 15;
            npc.lifeMax = 250;
            npc.soundHit = 1;
            npc.soundKilled = 1;
            npc.knockBackResist = 0.5f;
            Main.npcFrameCount[npc.type] = 25;
            NPCID.Sets.ExtraFramesCount[npc.type] = 9;
            NPCID.Sets.AttackFrameCount[npc.type] = 4;
            NPCID.Sets.DangerDetectRange[npc.type] = 700;
            NPCID.Sets.AttackType[npc.type] = 0;
            NPCID.Sets.AttackTime[npc.type] = 90;
            NPCID.Sets.AttackAverageChance[npc.type] = 30;
            NPCID.Sets.HatOffsetY[npc.type] = 4;
            NPCID.Sets.ExtraTextureCount[npc.type] = 1;
            animationType = NPCID.Guide;
        }

        public override void HitEffect(int hitDirection, double damage)
        {
            int num = npc.life > 0 ? 1 : 5;
            for (int k = 0; k < num; k++)
            {
                Dust.NewDust(npc.position, npc.width, npc.height, mod.DustType("Sparkle"));
            }
        }

        public override bool CanTownNPCSpawn(int numTownNPCs, int money)
        {
            for (int k = 0; k < 255; k++)
            {
                Player player = Main.player[k];
                if (player.active)
                {
                    for (int j = 0; j < player.inventory.Length; j++)
                    {
                        if (player.inventory[j].type == mod.ItemType("WoodenKatana"))
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }

        public override bool CheckConditions(int left, int right, int top, int bottom)
        {
            int score = 0;
            for (int x = left; x <= right; x++)
            {
                for (int y = top; y <= bottom; y++)
                {
                    int type = Main.tile[x, y].type;
                    if (type == mod.TileType("Wood") || type == mod.TileType("Workbench") || type == mod.TileType("WoodenChair") || type == mod.TileType("WoodenDoorOpen") || type == mod.TileType("WoodenDoorClosed"))
                    {
                        score++;
                    }
                    if (Main.tile[x, y].wall == mod.WallType("WoodWall"))
                    {
                        score++;
                    }
                }
            }
            return score >= (right - left) * (bottom - top) / 2;
        }

        public override string TownNPCName()
        {
            switch (WorldGen.genRand.Next(4))
            {
                case 0:
                    return "Someone";
                case 1:
                    return "Somebody";
                case 2:
                    return "Blocky";
                default:
                    return "Colorless";
            }
        }

        public override void FindFrame(int frameHeight)
        {
            /*npc.frame.Width = 40;
            if (((int)Main.time / 10) % 2 == 0)
            {
                npc.frame.X = 40;
            }
            else
            {
                npc.frame.X = 0;
            }*/
        }

        public override string GetChat()
        {
            int partyGirl = NPC.FindFirstNPC(NPCID.PartyGirl);
            if (partyGirl >= 0 && Main.rand.Next(4) == 0)
            {
                return "Can you please tell " + Main.npc[partyGirl].displayName + " to stop decorating my house with colors?";
            }
            switch (Main.rand.Next(3))
            {
                case 0:
                    return "Sometimes I feel like I'm different from everyone else here.";
                case 1:
                    return "What's your favorite color? My favorite colors are white and black.";
                default:
                    return "What? I don't have any arms or legs? Oh, don't be ridiculous!";
            }
        }

        public override void SetChatButtons(ref string button, ref string button2)
        {
            button = Lang.inter[28];
        }

        public override void OnChatButtonClicked(bool firstButton, ref bool shop)
        {
            if (firstButton)
            {
                shop = true;
            }
        }

        public override void SetupShop(Chest shop, ref int nextSlot)
        {
            shop.item[nextSlot].SetDefaults(mod.ItemType("WoodenKatana"));
            nextSlot++;
        }
        public override void TownNPCAttackStrength(ref int damage, ref float knockback)
        {
            damage = 20;
            knockback = 4f;
        }

        public override void TownNPCAttackCooldown(ref int cooldown, ref int randExtraCooldown)
        {
            cooldown = 30;
            randExtraCooldown = 30;
        }

        public override void TownNPCAttackProj(ref int projType, ref int attackDelay)
        {
            projType = mod.ProjectileType("SparklingBall");
            attackDelay = 1;
        }

        public override void TownNPCAttackProjSpeed(ref float multiplier, ref float gravityCorrection, ref float randomOffset)
        {
            multiplier = 12f;
            randomOffset = 2f;
        }
    }
}

Can anyone please help me out with this. It would be very helpful. Thanks!
 
Hello o/ I am currently a new mod maker and I'm creating a mod centered around some pre hard mode summoner things, And i have a question.
So i made a summon that is craft-able in the early game, and it does work but I am curious. I want the minion to behave similar to Deadly Spheres but I'm not sure how to do that and I'm not sure where to look so i came here. If anyone can help id appreciate it ^^
 
Hello o/ I am currently a new mod maker and I'm creating a mod centered around some pre hard mode summoner things, And i have a question.
So i made a summon that is craft-able in the early game, and it does work but I am curious. I want the minion to behave similar to Deadly Spheres but I'm not sure how to do that and I'm not sure where to look so i came here. If anyone can help id appreciate it ^^
If you want it to act like a Deadly Sphere really simply, you can just have the projectile move around the player at random and have it go towards an enemy. For tracking an enemy, here is an example code from my mod from a npc projectile. It should be mostly self explainatory. Just change target to type npc.

Code:
            Player target = Main.player[(int)projectile.ai[0]];
            float shootToX = target.position.X + (float)target.width * 0.5f - projectile.Center.X; 
            float shootToY = target.position.Y - projectile.Center.Y; 
            float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));
            float speed = 15f/distance;

Of course you'll need code for finding an npc, so here's something like this from my projectile.

Code:
            for(int i = 0; i < 1000; i++)
            {
                //Enemy Projectile variable being set
                Projectile enemyProj = Main.projectile[i];
                float shootToX = enemyProj.position.X + (float)enemyProj.width * 0.5f - projectile.Center.X; 
                float shootToY = enemyProj.position.Y - projectile.Center.Y; 
                float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));
                if(distance < 480f && enemyProj.hostile && enemyProj.active)
                {
                    //Setting the projectile's rotation to the projectile
                    Vector2 shootAngle = enemyProj.Center - projectile.Center;
                    float angle = (float)Math.Atan2(shootAngle.Y, shootAngle.X);
                    projectile.rotation = angle;
                   
                    if(projectile.ai[0] > 4f && Main.netMode != 1)
                    {
                        distance = 3f / distance; 
                        shootToX *= distance * 5; 
                        shootToY *= distance * 5; 
                        Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, shootToX, shootToY, mod.ProjectileType("PDTBullet"), 0, 0, Main.myPlayer, 0f, 0f);
                        Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 11);
                        projectile.ai[0] = 0f;
                    }
                }
            }

You can mostly replace the "Projectile enemyProj" to an npc and set the array to be "Main.npc". Everything else should be self explanatory.

Of course you want the projectile to follow the player when it is idle, so here is a simple code for that from my npc which can easily translate to projectile code

Code:
        private void floatAround(Vector2 moveTo, Player p)
        {
            float fOne = (float)Main.rand.Next(-100, 100);
            float fTwo = (float)Main.rand.Next(-100, 100);
            float pX = p.Center.X - npc.Center.X;
            float pY = p.Center.Y - npc.Center.Y;
            float pDistance = (float)System.Math.Sqrt((double)(pX * pX + pY * pY));
            if(portCoolDown > 0)
            {
                portCoolDown--;
            }
            if(pDistance < 50 && portCoolDown == 0)
            {
                MMod.explosionEffect(npc, 4f);
                for(int i = 0; i < 255; i++)
                {
                    Player players = Main.player[i];
                    float dX = players.Center.X - npc.Center.X;
                    float dY = players.Center.Y - npc.Center.Y;
                    float playersDistance = (float)System.Math.Sqrt((double)dX * dX + dY * dY);
                    if(playersDistance < 50)
                    {
                        p.Hurt(30, p.direction);
                    }
                }
                int[] posNeg = {1, -1};
                float sX = posNeg[Main.rand.Next(0, 1)];
                float sY = posNeg[Main.rand.Next(0, 1)];
                float tDistance = 400f;
                npc.position.X = p.Center.X + (tDistance * sX) + fOne;
                npc.position.Y = p.Center.Y + (tDistance * sY) + fTwo;
                didOnce = 0;
                portCoolDown = 180;
            }
            float moveToX = moveTo.X - npc.Center.X + fOne;
            float moveToY = moveTo.Y - npc.Center.Y + fTwo;
            float distance = (float)System.Math.Sqrt((double)(moveToX * moveToX + moveToY * moveToY));
            float speed = 5f;
            if(pDistance > 500)
            {
                speed = 15f;
            }
            distance = speed / distance; 
            moveToX *= distance;
            moveToY *= distance;
            if(pDistance > 500)
            {
                pX += fOne * 2;
                pY += fTwo * 2;
                pX *= distance;
                pY *= distance;
            }
            if(didOnce == 0 || pDistance > 500)
            {
                npc.velocity.X = moveToX;
                npc.velocity.Y = moveToY;
                if(pDistance > 500)
                {
                    npc.velocity.X = pX;
                    npc.velocity.Y = pY;
                }
                didOnce = 1;
            }
            if(mode == 4)
            {
                flammenWheel(p);
            }
        }

This is a private method made that is not a hook, of course you can just ignore that and just use the code within the method, since the parameters used in this method consists of:

Code:
            int maxDefense = 0
            int target = 0;
            //Check player array
            for(int i = 0; i < 255; i++)
            {
                Player pTarget = Main.player[i];
               //Checks if the player's defense is greater than maxDefense and sets the target to that player id in the array and sets the maxDefense as that player's defense
                if(pTarget.statDefense > maxDefense)
                {
                    maxDefense = pTarget.statDefense;
                    target = i;
                }
            }
            Player p = Main.player[target];
     
           //After 90 ticks, get a new moveTo
           if(npc.ai[0] > 90)
            {               
                int randX = Main.rand.Next(-500, 500);
                int randY = Main.rand.Next(-100, 500);
                moveTo = new Vector2(p.Center.X + randX, p.Center.Y + randY);
                npc.ai[0] = 0;
                didOnce = 0;
            }
           
            //If in idle mode
            if(mode == -1)
            {
                //Float around player
                floatAround(moveTo, p);
            }
 
Can I get some help, what does

"Sequence contains no matching element
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
at Terraria.ModLoader.AssemblyManager.InstantiateMods(List`1 modsToLoad)"

mean?
 
If you want it to act like a Deadly Sphere really simply, you can just have the projectile move around the player at random and have it go towards an enemy. For tracking an enemy, here is an example code from my mod from a npc projectile. It should be mostly self explainatory. Just change target to type npc.

Code:
            Player target = Main.player[(int)projectile.ai[0]];
            float shootToX = target.position.X + (float)target.width * 0.5f - projectile.Center.X;
            float shootToY = target.position.Y - projectile.Center.Y;
            float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));
            float speed = 15f/distance;

Of course you'll need code for finding an npc, so here's something like this from my projectile.

Code:
            for(int i = 0; i < 1000; i++)
            {
                //Enemy Projectile variable being set
                Projectile enemyProj = Main.projectile[i];
                float shootToX = enemyProj.position.X + (float)enemyProj.width * 0.5f - projectile.Center.X;
                float shootToY = enemyProj.position.Y - projectile.Center.Y;
                float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));
                if(distance < 480f && enemyProj.hostile && enemyProj.active)
                {
                    //Setting the projectile's rotation to the projectile
                    Vector2 shootAngle = enemyProj.Center - projectile.Center;
                    float angle = (float)Math.Atan2(shootAngle.Y, shootAngle.X);
                    projectile.rotation = angle;
                  
                    if(projectile.ai[0] > 4f && Main.netMode != 1)
                    {
                        distance = 3f / distance;
                        shootToX *= distance * 5;
                        shootToY *= distance * 5;
                        Projectile.NewProjectile(projectile.Center.X, projectile.Center.Y, shootToX, shootToY, mod.ProjectileType("PDTBullet"), 0, 0, Main.myPlayer, 0f, 0f);
                        Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 11);
                        projectile.ai[0] = 0f;
                    }
                }
            }

You can mostly replace the "Projectile enemyProj" to an npc and set the array to be "Main.npc". Everything else should be self explanatory.

Of course you want the projectile to follow the player when it is idle, so here is a simple code for that from my npc which can easily translate to projectile code

Code:
        private void floatAround(Vector2 moveTo, Player p)
        {
            float fOne = (float)Main.rand.Next(-100, 100);
            float fTwo = (float)Main.rand.Next(-100, 100);
            float pX = p.Center.X - npc.Center.X;
            float pY = p.Center.Y - npc.Center.Y;
            float pDistance = (float)System.Math.Sqrt((double)(pX * pX + pY * pY));
            if(portCoolDown > 0)
            {
                portCoolDown--;
            }
            if(pDistance < 50 && portCoolDown == 0)
            {
                MMod.explosionEffect(npc, 4f);
                for(int i = 0; i < 255; i++)
                {
                    Player players = Main.player[i];
                    float dX = players.Center.X - npc.Center.X;
                    float dY = players.Center.Y - npc.Center.Y;
                    float playersDistance = (float)System.Math.Sqrt((double)dX * dX + dY * dY);
                    if(playersDistance < 50)
                    {
                        p.Hurt(30, p.direction);
                    }
                }
                int[] posNeg = {1, -1};
                float sX = posNeg[Main.rand.Next(0, 1)];
                float sY = posNeg[Main.rand.Next(0, 1)];
                float tDistance = 400f;
                npc.position.X = p.Center.X + (tDistance * sX) + fOne;
                npc.position.Y = p.Center.Y + (tDistance * sY) + fTwo;
                didOnce = 0;
                portCoolDown = 180;
            }
            float moveToX = moveTo.X - npc.Center.X + fOne;
            float moveToY = moveTo.Y - npc.Center.Y + fTwo;
            float distance = (float)System.Math.Sqrt((double)(moveToX * moveToX + moveToY * moveToY));
            float speed = 5f;
            if(pDistance > 500)
            {
                speed = 15f;
            }
            distance = speed / distance;
            moveToX *= distance;
            moveToY *= distance;
            if(pDistance > 500)
            {
                pX += fOne * 2;
                pY += fTwo * 2;
                pX *= distance;
                pY *= distance;
            }
            if(didOnce == 0 || pDistance > 500)
            {
                npc.velocity.X = moveToX;
                npc.velocity.Y = moveToY;
                if(pDistance > 500)
                {
                    npc.velocity.X = pX;
                    npc.velocity.Y = pY;
                }
                didOnce = 1;
            }
            if(mode == 4)
            {
                flammenWheel(p);
            }
        }

This is a private method made that is not a hook, of course you can just ignore that and just use the code within the method, since the parameters used in this method consists of:

Code:
            int maxDefense = 0
            int target = 0;
            //Check player array
            for(int i = 0; i < 255; i++)
            {
                Player pTarget = Main.player[i];
               //Checks if the player's defense is greater than maxDefense and sets the target to that player id in the array and sets the maxDefense as that player's defense
                if(pTarget.statDefense > maxDefense)
                {
                    maxDefense = pTarget.statDefense;
                    target = i;
                }
            }
            Player p = Main.player[target];
    
           //After 90 ticks, get a new moveTo
           if(npc.ai[0] > 90)
            {              
                int randX = Main.rand.Next(-500, 500);
                int randY = Main.rand.Next(-100, 500);
                moveTo = new Vector2(p.Center.X + randX, p.Center.Y + randY);
                npc.ai[0] = 0;
                didOnce = 0;
            }
          
            //If in idle mode
            if(mode == -1)
            {
                //Float around player
                floatAround(moveTo, p);
            }


Thank you, I'm still really new to this so all that is slightly confusing but I am learning... I guess I am not sure where to put this coding.
 
Can I get some help, what does

"Sequence contains no matching element
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
at Terraria.ModLoader.AssemblyManager.InstantiateMods(List`1 modsToLoad)"

mean?
Probably that you have no Mod class.
 
Back
Top Bottom