Standalone [1.3] tModLoader - A Modding API

So, I'm now running into a bug when opening the mod browser.
"The game has crashed accessing web resources!"
"Sequence contains more than one matching element
at System.Linq.Enumerable.SingleOrDefault[TSource](1Enumerable`1 Source, Func`2 predicate)
at Terraria.ModLoader.UI.UIModBrowser.PopulateFromJSON(TModFile[] installedMods, String json)"

I can't screenshot for some reason so this is a word-for-word, capitalized version of the error I get. It's occurred reoccurently over the past 3-4 days, but when I reopen the mod browser after it I can switch to updates and download them, even if reloading the browser brings up the error again.
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace JoshuasMod.Items.Weapons        //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{
    public class CosmicCataclysm : ModItem
    {
        public override void SetDefaults()
        {
            item.CloneDefaults(ItemID.StarWrath);   
            item.damage = 1000;   //The damage stat for the Weapon.                 
            item.melee = false;   //This defines if it does melee damage and if its effected by melee increasing Armor/Accessories.
            item.useTime = 10;     //How fast the Weapon is used.
            item.useAnimation = 10;    //How long the Weapon is used for.
            item.useStyle = 1;         //The way your Weapon will be used, 5 is the Holding Out Used for: Guns, Spellbooks, Drills, Chainsaws, Flails, Spears for example
            item.noMelee = true;     //Setting to True allows the weapon sprite to stop doing damage, so only the projectile does the damge
            item.knockBack = 10;  //The knockback stat of your Weapon. The higher the number, the higher the Knockback.
            item.value = Item.buyPrice(1, 20, 50, 0); // How much the item is worth, in copper coins, when you sell it to a merchant. It costs 1/5th of this to buy it back from them. An easy way to remember the value is platinum, gold, silver, copper or PPGGSSCC (So this item price is 1 Platinum, 20 Gold and 50 Silver.)
            item.rare = 11;   //The color the title of your Weapon when hovering over it ingame
            item.UseSound = SoundID.Item21; //item.UseSound = SoundID.Item1;   //The sound played when using your Weapon
            item.autoReuse = true; //Weather your Weapon will be used again after use while holding down, if false you will need to click again after use to use it again.
            item.shoot = 0;
            item.useTurn = true;
        }

        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(BuffID.Daybreak, 5 * 60);
            target.AddBuff(BuffID.Frostburn, 5 * 60);
            target.AddBuff(BuffID.DryadsWardDebuff, 5 * 60);

            int healingAmount = damage/50;
            player.statLife +=healingAmount;
            player.HealEffect(healingAmount, true);
        }

        public override bool AltFunctionUse(Player player)
        {
            return true;
        }

        public override bool CanUseItem(Player player)
        {
            if (player.altFunctionUse == 2)
            {
            item.useStyle = 1;    //The way your Weapon will be used, 1 is the regular sword swing.
            item.useTime = 12;   //How fast the Weapon is used.
            item.useAnimation = 12;     //How long the Weapon is used for.
            item.UseSound = SoundID.Item1;
            item.damage = 1000;
            item.shoot = mod.ProjectileType("CataclysmicBlaze");
            item.shootSpeed = 18f;
            item.useTurn = true;
            }
            else
            {
            item.useStyle = 1;    //The way your Weapon will be used, 1 is the regular sword swing.
            item.UseSound = SoundID.Item1; //The sound played when using your Weapon.
            item.damage = 1000;
            item.useTime = 10;   //How fast the Weapon is used.
            item.useAnimation = 10;     //How long the Weapon is used for.
            item.autoReuse = true;
            item.melee = false;
            item.rare = 11;
            item.shoot = 0;
            item.useTurn = true;
            }
            return base.CanUseItem(player);
        }
  
        //This is the "Star Wrath" style for the projectiles.
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            int numberProjectiles = 1 + Main.rand.Next(1);  //Defines how many projectiles it will shoot. "numberProjectiles = 1" is 1 projectile, "numberProjectiles = 2" is 2 projectiles, etc.
            for (int index = 0; index < numberProjectiles; ++index)
            {
                Vector2 vector2_1 = new Vector2((float)((double)player.position.X + (double)player.width * 0.5 + (double)(Main.rand.Next(100) * -player.direction) + ((double)Main.mouseX + (double)Main.screenPosition.X - (double)player.position.X)), (float)((double)player.position.Y + (double)player.height * 0.5 - 600.0));   //This defines the projectile width, direction and position.
                vector2_1.X = (float)(((double)vector2_1.X + (double)player.Center.X) / 2.0) + (float)Main.rand.Next(-100, 100);
                vector2_1.Y -= (float)(100 * index);
                float num12 = (float)Main.mouseX + Main.screenPosition.X - vector2_1.X;
                float num13 = (float)Main.mouseY + Main.screenPosition.Y - vector2_1.Y;
                if ((double)num13 < 0.0) num13 *= -1f;
                if ((double)num13 < 20.0) num13 = 20f;
                float num14 = (float)Math.Sqrt((double)num12 * (double)num12 + (double)num13 * (double)num13);
                float num15 = item.shootSpeed / num14;
                float num16 = num12 * num15;
                float num17 = num13 * num15;
                float SpeedX = num16 + (float)Main.rand.Next(-12, 10) * 0.160f;  //This defines the projectile X position speed and randomness.
                float SpeedY = num17 + (float)Main.rand.Next(-12, 10) * 0.160f;  //This defines the projectile Y position speed and randomness.
                Projectile.NewProjectile(vector2_1.X, vector2_1.Y, SpeedX, SpeedY, type, damage, knockBack, Main.myPlayer, 0.0f, (float)Main.rand.Next(5));
            }
            return false;
        }

    }
}

Okay, so I have a sword that can shoot projectiles from the sky towards my cursor (Like the Star Wrath), but can only shoot 1 of the projectiles right now. How do I make it shoot 3 different projectiles in the same 'Star Wrath' style, at the same time? Do I need to add a "projectile.NewProjectile" line?[/CODE][/SPOILER]
 
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace JoshuasMod.Items.Weapons        //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{
    public class CosmicCataclysm : ModItem
    {
        public override void SetDefaults()
        {
            item.CloneDefaults(ItemID.StarWrath);  
            item.damage = 1000;   //The damage stat for the Weapon.                
            item.melee = false;   //This defines if it does melee damage and if its effected by melee increasing Armor/Accessories.
            item.useTime = 10;     //How fast the Weapon is used.
            item.useAnimation = 10;    //How long the Weapon is used for.
            item.useStyle = 1;         //The way your Weapon will be used, 5 is the Holding Out Used for: Guns, Spellbooks, Drills, Chainsaws, Flails, Spears for example
            item.noMelee = true;     //Setting to True allows the weapon sprite to stop doing damage, so only the projectile does the damge
            item.knockBack = 10;  //The knockback stat of your Weapon. The higher the number, the higher the Knockback.
            item.value = Item.buyPrice(1, 20, 50, 0); // How much the item is worth, in copper coins, when you sell it to a merchant. It costs 1/5th of this to buy it back from them. An easy way to remember the value is platinum, gold, silver, copper or PPGGSSCC (So this item price is 1 Platinum, 20 Gold and 50 Silver.)
            item.rare = 11;   //The color the title of your Weapon when hovering over it ingame
            item.UseSound = SoundID.Item21; //item.UseSound = SoundID.Item1;   //The sound played when using your Weapon
            item.autoReuse = true; //Weather your Weapon will be used again after use while holding down, if false you will need to click again after use to use it again.
            item.shoot = 0;
            item.useTurn = true;
        }

        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(BuffID.Daybreak, 5 * 60);
            target.AddBuff(BuffID.Frostburn, 5 * 60);
            target.AddBuff(BuffID.DryadsWardDebuff, 5 * 60);

            int healingAmount = damage/50;
            player.statLife +=healingAmount;
            player.HealEffect(healingAmount, true);
        }

        public override bool AltFunctionUse(Player player)
        {
            return true;
        }

        public override bool CanUseItem(Player player)
        {
            if (player.altFunctionUse == 2)
            {
            item.useStyle = 1;    //The way your Weapon will be used, 1 is the regular sword swing.
            item.useTime = 12;   //How fast the Weapon is used.
            item.useAnimation = 12;     //How long the Weapon is used for.
            item.UseSound = SoundID.Item1;
            item.damage = 1000;
            item.shoot = mod.ProjectileType("CataclysmicBlaze");
            item.shootSpeed = 18f;
            item.useTurn = true;
            }
            else
            {
            item.useStyle = 1;    //The way your Weapon will be used, 1 is the regular sword swing.
            item.UseSound = SoundID.Item1; //The sound played when using your Weapon.
            item.damage = 1000;
            item.useTime = 10;   //How fast the Weapon is used.
            item.useAnimation = 10;     //How long the Weapon is used for.
            item.autoReuse = true;
            item.melee = false;
            item.rare = 11;
            item.shoot = 0;
            item.useTurn = true;
            }
            return base.CanUseItem(player);
        }
 
        //This is the "Star Wrath" style for the projectiles.
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            int numberProjectiles = 1 + Main.rand.Next(1);  //Defines how many projectiles it will shoot. "numberProjectiles = 1" is 1 projectile, "numberProjectiles = 2" is 2 projectiles, etc.
            for (int index = 0; index < numberProjectiles; ++index)
            {
                Vector2 vector2_1 = new Vector2((float)((double)player.position.X + (double)player.width * 0.5 + (double)(Main.rand.Next(100) * -player.direction) + ((double)Main.mouseX + (double)Main.screenPosition.X - (double)player.position.X)), (float)((double)player.position.Y + (double)player.height * 0.5 - 600.0));   //This defines the projectile width, direction and position.
                vector2_1.X = (float)(((double)vector2_1.X + (double)player.Center.X) / 2.0) + (float)Main.rand.Next(-100, 100);
                vector2_1.Y -= (float)(100 * index);
                float num12 = (float)Main.mouseX + Main.screenPosition.X - vector2_1.X;
                float num13 = (float)Main.mouseY + Main.screenPosition.Y - vector2_1.Y;
                if ((double)num13 < 0.0) num13 *= -1f;
                if ((double)num13 < 20.0) num13 = 20f;
                float num14 = (float)Math.Sqrt((double)num12 * (double)num12 + (double)num13 * (double)num13);
                float num15 = item.shootSpeed / num14;
                float num16 = num12 * num15;
                float num17 = num13 * num15;
                float SpeedX = num16 + (float)Main.rand.Next(-12, 10) * 0.160f;  //This defines the projectile X position speed and randomness.
                float SpeedY = num17 + (float)Main.rand.Next(-12, 10) * 0.160f;  //This defines the projectile Y position speed and randomness.
                Projectile.NewProjectile(vector2_1.X, vector2_1.Y, SpeedX, SpeedY, type, damage, knockBack, Main.myPlayer, 0.0f, (float)Main.rand.Next(5));
            }
            return false;
        }

    }
}

Okay, so I have a sword that can shoot projectiles from the sky towards my cursor (Like the Star Wrath), but can only shoot 1 of the projectiles right now. How do I make it shoot 3 different projectiles in the same 'Star Wrath' style, at the same time? Do I need to add a "projectile.NewProjectile" line?[/CODE][/SPOILER]
Looking through your code, I can see the line:
int numberProjectiles = 1 + Main.rand.Next(1); //Defines how many projectiles it will shoot. "numberProjectiles = 1" is 1 projectile, "numberProjectiles = 2" is 2 projectiles, etc.
And the comment at the end of that line explains what you need to do.
 
I have a problem when creating and NPC, it looks like this:
zko3xySISaqbcAQ-_LD-9A.png
What's wrong?
 
Looking through your code, I can see the line:
int numberProjectiles = 1 + Main.rand.Next(1); //Defines how many projectiles it will shoot. "numberProjectiles = 1" is 1 projectile, "numberProjectiles = 2" is 2 projectiles, etc.
And the comment at the end of that line explains what you need to do.
I meant like 2 different projectiles, at the same time. Example: Shooting the Terra Beam and Influx Waver projectile.
 
Hey guys, we recently setup our own Patreon!
We really appreciate you for being here, and using tModLoader.
The best way to support us is by becoming a patron on our Patreon page: https://www.patreon.com/tModLoader
https://www.patreon.com/tModLoader
You can choose an amount to pay (monthly) to support us.

We will use funds from our Patreon to pay for the following subjects, but these are not limited to:
  • Mod Browser hosting server
  • Website hosting server (possibly)
  • Other

Becoming a Patron comes with many rewards! Check our Patreon page for more information.
 
I have a problem when creating and NPC, it looks like this:
zko3xySISaqbcAQ-_LD-9A.png
What's wrong?
That happens when you set the frameCount of that NPC to an incorrect amount. The npcFrameCount must be the same as the number of frames in the NPC's sprite sheet.

I meant like 2 different projectiles, at the same time. Example: Shooting the Terra Beam and Influx Waver projectile.
Oh, well the simplest way would be to duplicate the line that begins with "Projectile.NewProjectile(..." and then change the type to the ID of the other projectile that you want to shoot.

However, this will create the new projectile at the same location with the same speed, damage etc. as the first one. You can modify the values of the projectile when it's created. As an example, the following would create the second projectile at half the speed, but twice the damage as the first.
Projectile.NewProjectile(vector2_1.X, vector2_1.Y, SpeedX * 0.5f, SpeedY * 0.5f, ProjectileID.InfluxWaver, damage * 2, knockBack, Main.myPlayer, 0.0f, (float)Main.rand.Next(5));
 
That happens when you set the frameCount of that NPC to an incorrect amount. The npcFrameCount must be the same as the number of frames in the NPC's sprite sheet.

Oh, well the simplest way would be to duplicate the line that begins with "Projectile.NewProjectile(..." and then change the type to the ID of the other projectile that you want to shoot.

However, this will create the new projectile at the same location with the same speed, damage etc. as the first one. You can modify the values of the projectile when it's created. As an example, the following would create the second projectile at half the speed, but twice the damage as the first.
Projectile.NewProjectile(vector2_1.X, vector2_1.Y, SpeedX * 0.5f, SpeedY * 0.5f, ProjectileID.InfluxWaver, damage * 2, knockBack, Main.myPlayer, 0.0f, (float)Main.rand.Next(5));

You, sir, helped a ton :D
But one more (very nooby) question:
How do I change the Influx Waver Projectile to a custom/modded projectile?

Here's the code again:
Code:
                Vector2 vector2_1 = new Vector2((float)((double)player.position.X + (double)player.width * 0.5 + (double)(Main.rand.Next(100) * -player.direction) + ((double)Main.mouseX + (double)Main.screenPosition.X - (double)player.position.X)), (float)((double)player.position.Y + (double)player.height * 0.5 - 600.0));   //This defines the projectile width, direction and position.
                vector2_1.X = (float)(((double)vector2_1.X + (double)player.Center.X) / 2.0) + (float)Main.rand.Next(-100, 100);
                vector2_1.Y -= (float)(100 * index);
                float num12 = (float)Main.mouseX + Main.screenPosition.X - vector2_1.X;
                float num13 = (float)Main.mouseY + Main.screenPosition.Y - vector2_1.Y;
                if ((double)num13 < 0.0) num13 *= -1f;
                if ((double)num13 < 20.0) num13 = 20f;
                float num14 = (float)Math.Sqrt((double)num12 * (double)num12 + (double)num13 * (double)num13);
                float num15 = item.shootSpeed / num14;
                float num16 = num12 * num15;
                float num17 = num13 * num15;
                float SpeedX = num16 + (float)Main.rand.Next(-12, 10) * 0.160f;  //This defines the projectile X position speed and randomness.
                float SpeedY = num17 + (float)Main.rand.Next(-12, 10) * 0.160f;  //This defines the projectile Y position speed and randomness.
                Projectile.NewProjectile(vector2_1.X, vector2_1.Y, SpeedX, SpeedY, type, damage, knockBack, Main.myPlayer, 0.0f, (float)Main.rand.Next(5));
                Projectile.NewProjectile(vector2_1.X, vector2_1.Y, SpeedX * 0.5f, SpeedY * 0.5f, ProjectileID.InfluxWaver, damage * 2, knockBack, Main.myPlayer, 0.0f, (float)Main.rand.Next(5));[/SPOILER]
 
Last edited:
Any one have problems if the browse? When I click in download, the tmod say "heavy load". Its normal?
Yes this is normal. It means the server is out of bandwidth and can't serve you any more downloads. You will need to download mods from their respective threads, if they don't offer a download that doesn't rely on the mod browser you should get mad at them... :p
 
That happens when you set the frameCount of that NPC to an incorrect amount. The npcFrameCount must be the same as the number of frames in the NPC's sprite sheet.

Oh, well the simplest way would be to duplicate the line that begins with "Projectile.NewProjectile(..." and then change the type to the ID of the other projectile that you want to shoot.

However, this will create the new projectile at the same location with the same speed, damage etc. as the first one. You can modify the values of the projectile when it's created. As an example, the following would create the second projectile at half the speed, but twice the damage as the first.
Projectile.NewProjectile(vector2_1.X, vector2_1.Y, SpeedX * 0.5f, SpeedY * 0.5f, ProjectileID.InfluxWaver, damage * 2, knockBack, Main.myPlayer, 0.0f, (float)Main.rand.Next(5));
Thanks! :D
 
Ok, latest update installed, everything's ok...but, I can't download the updates for Calamity, Tremor, and Spirit mods. keeps saying the "mod browser is under heavy load." anyone know why this is happening?
 
hi, for some reason it says "The name 'TileID' does not exist in the current context" I am confused, any help?
using Terraria;
using Terraria.ModLoader;
namespace ApocalypseMOD.Items
{
[AutoloadEquip(EquipType.Head)]
public class HelmetName : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("I wanna be a mage when i grow up!");
}
public override void SetDefaults()
{
item.width = 18;
item.height = 18;
item.value = 10000;
item.rare = 2;
item.defense = 6;
}
public override bool IsArmorSet(Item head, Item body, Item legs)
{
return body.type == mod.ItemType("BreastplateName") && legs.type == mod.ItemType("ExampleLeggings");
}
public override void UpdateArmorSet(Player player)
{
player.setBonus = "eye.png";
player.meleeDamage *= 0.8f;
player.thrownDamage *= 0.8f;
player.rangedDamage *= 0.8f;
player.magicDamage *= 0.8f;
player.minionDamage *= 0.8f;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(mod, "StarBar", 10);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
[doublepost=1498099812,1498099640][/doublepost]the exact same tile id code works fine on my custom sword...
 
hi, for some reason it says "The name 'TileID' does not exist in the current context" I am confused, any help?
using Terraria;
using Terraria.ModLoader;
namespace ApocalypseMOD.Items
{
[AutoloadEquip(EquipType.Head)]
public class HelmetName : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("I wanna be a mage when i grow up!");
}
public override void SetDefaults()
{
item.width = 18;
item.height = 18;
item.value = 10000;
item.rare = 2;
item.defense = 6;
}
public override bool IsArmorSet(Item head, Item body, Item legs)
{
return body.type == mod.ItemType("BreastplateName") && legs.type == mod.ItemType("ExampleLeggings");
}
public override void UpdateArmorSet(Player player)
{
player.setBonus = "eye.png";
player.meleeDamage *= 0.8f;
player.thrownDamage *= 0.8f;
player.rangedDamage *= 0.8f;
player.magicDamage *= 0.8f;
player.minionDamage *= 0.8f;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(mod, "StarBar", 10);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
[doublepost=1498099812,1498099640][/doublepost]the exact same tile id code works fine on my custom sword...
TileID is in the Terraria.ID namespace, so add the appropriate using statement.
 
hey jopojelly, thx for the help. I got another problem tho
Missing mod: ApocalyplseMOD/Items/BreastplateName_Body
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.Mod.AddEquipTexture(EquipTexture equipTexture, ModItem item, EquipType type, String name, String texture, String armTexture, String femaleTexture)
at Terraria.ModLoader.Mod.AddEquipTexture(ModItem item, EquipType type, String name, String texture, String armTexture, String femaleTexture)
at Terraria.ModLoader.Mod.AutoloadItem(Type type)
at Terraria.ModLoader.Mod.Autoload()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

here is code

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace ApocalyplseMOD.Items
{
[AutoloadEquip(EquipType.Body)]
public class BreastplateName : ModItem
{
public override void SetStaticDefaults()
{
base.SetStaticDefaults();
DisplayName.SetDefault("Solar breastplate");
Tooltip.SetDefault("I wanna be a mage when i grow up!"
+ "\nImmunity to 'On Fire!'"
+ "\n+20 max mana and +1 max minions");
}
public override void SetDefaults()
{
item.width = 18;
item.height = 18;
item.value = 10000;
item.rare = 2;
item.defense = 8;
}
public override void UpdateEquip(Player player)
{
player.buffImmune[BuffID.OnFire] = true;
player.statManaMax2 += 20;
player.maxMinions++;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(mod, "StarBar", 20);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
 
I keep getting this message when I load up terraria and it goes through my mods.
Field not found: 'Terraria.Item.toolTip2'.
at TrueEater.GlobalTrueItem.SetDefaults(Item item)
at Terraria.ModLoader.ItemLoader.SetDefaults(Item item, Boolean createModItem)
at Terraria.ModLoader.Mod.SetupContent()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

And every time I click "Ok" to let it disable the mod. It just does it again. I did it for 10 mins strait once.
 
Back
Top Bottom