Standalone [1.3] tModLoader - A Modding API

Code:
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MadCrafter.Items
{
    public class Dreams : ModItem
    {

        public override void SetDefaults()
        {
            item.name = "Your D.R.E.A.M.S Book";
            item.width = 32;
            item.height = 32;
            item.toolTip = "A book that holds your wishes.";
            item.toolTip2 = "Adds a little of everything.";
            item.value = 50;
            item.rare = 2;
            item.accessory = true;
        }

        public override void UpdateEquip(Player player)
        {
            player.meleeDamage = 0.2f;
            player.thrownDamage = 0.2f;
            player.rangedDamage = 0.2f;
            player.magicDamage = 0.2f;
            player.minionDamage = 0.2f;
            player.meleeSpeed = 0.33f;
            player.thrownCost33 = true;
            player.ammoCost75 = true;
            player.moveSpeed += 0.33f;
            player.maxMinions++;
            player.statDefense += 100;
            player.manaCost -= 0.33f;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.CobaltShield, 1);
            recipe.AddIngredient(ItemID.MusketBall, 1);
            recipe.AddIngredient(ItemID.ManaCrystal, 1);
            recipe.AddIngredient(ItemID.HerculesBeetle, 1);
            recipe.AddIngredient(ItemID.AvengerEmblem, 1);
            recipe.AddIngredient(ItemID.FeralClaws, 1);
            recipe.AddIngredient(ItemID.HermesBoots, 1);
            recipe.AddIngredient(ItemID.Book, 1);
            recipe.AddTile(TileID.Autohammer);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
Dreams.png
Dreams
Same.
 
Missing mod: BEM/Projectiles/StarShard
at Terraria.ModLoader.ModLoader.GetTexture(String name)
at Terraria.ModLoader.Mod.SetupContent()
at Terraria.ModLoader.ModLoader.do_Load(Object threadContext)

This is a problem many people have come up against here. Today while trying to fix mine I found many answers to the problem, which all, essentially, went along the lines of "check that the name correspond exactly".

So check that, it worked for quite a few people, but, should it fail, I found a backup route.

Place this into your code between

public class StarShard : ModProjectile
{

and

public override void SetDefaults()
{

COPY AND PASTE THIS:

public override bool Autoload(ref string name, ref string texture)
{
texture = mod.Name + "/Projectiles/StarShard";
return mod.Properties.Autoload;
}

ALSO CHANGE /Projectiles/StarShard to the name and location of your image (which should be .png). For example if it was a "BlueYoYo" in the items folder it would be "/Items/BlueYoYo" with the speech marks.

Hope this works for everyone else with the problem :)
 
c:\Users\John\Documents\my games\Terraria\ModLoader\Mod Sources\Mad Crafter\Items\Dreams.cs(23,30) : error CS0115: 'MadCrafter.Items.Dreams.Autoload(ref string, ref string)': no suitable method found to override

Did you ever get this afterwards?
[doublepost=1466181507,1466181443][/doublepost]Wait, may know error, sec.
[doublepost=1466181649][/doublepost]Never mind, no idea. Placed where you asked but... same error but 11 instead of 23.
[doublepost=1466181714][/doublepost]
Code:
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MadCrafter.Items
{
    public class Dreams : ModItem
    {

        public override bool Autoload(ref string name, ref string texture)
        {
            texture = mod.Name + "/Items/Dreams";
            return mod.Properties.Autoload;
        }

        public override void SetDefaults()
        {
            item.name = "Your D.R.E.A.M.S Book";
            item.width = 32;
            item.height = 32;
            item.toolTip = "A book that holds your wishes.";
            item.toolTip2 = "Adds a little of everything.";
            item.value = 50;
            item.rare = 2;
            item.accessory = true;
        }

        public override void UpdateEquip(Player player)
        {
            player.meleeDamage = 0.2f;
            player.thrownDamage = 0.2f;
            player.rangedDamage = 0.2f;
            player.magicDamage = 0.2f;
            player.minionDamage = 0.2f;
            player.meleeSpeed = 0.33f;
            player.thrownCost33 = true;
            player.ammoCost75 = true;
            player.moveSpeed += 0.33f;
            player.maxMinions++;
            player.statDefense += 100;
            player.manaCost -= 0.33f;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.CobaltShield, 1);
            recipe.AddIngredient(ItemID.MusketBall, 1);
            recipe.AddIngredient(ItemID.ManaCrystal, 1);
            recipe.AddIngredient(ItemID.HerculesBeetle, 1);
            recipe.AddIngredient(ItemID.AvengerEmblem, 1);
            recipe.AddIngredient(ItemID.FeralClaws, 1);
            recipe.AddIngredient(ItemID.HermesBoots, 1);
            recipe.AddIngredient(ItemID.Book, 1);
            recipe.AddTile(TileID.Autohammer);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}
 
c:\Users\John\Documents\my games\Terraria\ModLoader\Mod Sources\Mad Crafter\Items\Dreams.cs(23,30) : error CS0115: 'MadCrafter.Items.Dreams.Autoload(ref string, ref string)': no suitable method found to override

Did you ever get this afterwards?
[doublepost=1466181507,1466181443][/doublepost]Wait, may know error, sec.
[doublepost=1466181649][/doublepost]Never mind, no idea. Placed where you asked but... same error but 11 instead of 23.
[doublepost=1466181714][/doublepost]
Code:
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MadCrafter.Items
{
    public class Dreams : ModItem
    {

        public override bool Autoload(ref string name, ref string texture)
        {
            texture = mod.Name + "/Items/Dreams";
            return mod.Properties.Autoload;
        }

        public override void SetDefaults()
        {
            item.name = "Your D.R.E.A.M.S Book";
            item.width = 32;
            item.height = 32;
            item.toolTip = "A book that holds your wishes.";
            item.toolTip2 = "Adds a little of everything.";
            item.value = 50;
            item.rare = 2;
            item.accessory = true;
        }

        public override void UpdateEquip(Player player)
        {
            player.meleeDamage = 0.2f;
            player.thrownDamage = 0.2f;
            player.rangedDamage = 0.2f;
            player.magicDamage = 0.2f;
            player.minionDamage = 0.2f;
            player.meleeSpeed = 0.33f;
            player.thrownCost33 = true;
            player.ammoCost75 = true;
            player.moveSpeed += 0.33f;
            player.maxMinions++;
            player.statDefense += 100;
            player.manaCost -= 0.33f;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.CobaltShield, 1);
            recipe.AddIngredient(ItemID.MusketBall, 1);
            recipe.AddIngredient(ItemID.ManaCrystal, 1);
            recipe.AddIngredient(ItemID.HerculesBeetle, 1);
            recipe.AddIngredient(ItemID.AvengerEmblem, 1);
            recipe.AddIngredient(ItemID.FeralClaws, 1);
            recipe.AddIngredient(ItemID.HermesBoots, 1);
            recipe.AddIngredient(ItemID.Book, 1);
            recipe.AddTile(TileID.Autohammer);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}

Get rid of the whole Autoload override and just put the texture for the item in the same folder as the script. Much easier.
 
Get rid of the whole Autoload override and just put the texture for the item in the same folder as the script and has the same name. Much easier.

But that is what wasn't working before.
[doublepost=1466182081,1466182019][/doublepost]
c:\Users\John\Documents\my games\Terraria\ModLoader\Mod Sources\Mad Crafter\Items\Dreams.cs(23,30) : error CS0115: 'MadCrafter.Items.Dreams.Autoload(ref string, ref string)': no suitable method found to override

Did you ever get this afterwards?
[doublepost=1466181507,1466181443][/doublepost]Wait, may know error, sec.
[doublepost=1466181649][/doublepost]Never mind, no idea. Placed where you asked but... same error but 11 instead of 23.
[doublepost=1466181714][/doublepost]
Code:
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace MadCrafter.Items
{
    public class Dreams : ModItem
    {

        public override bool Autoload(ref string name, ref string texture)
        {
            texture = mod.Name + "/Items/Dreams";
            return mod.Properties.Autoload;
        }

        public override void SetDefaults()
        {
            item.name = "Your D.R.E.A.M.S Book";
            item.width = 32;
            item.height = 32;
            item.toolTip = "A book that holds your wishes.";
            item.toolTip2 = "Adds a little of everything.";
            item.value = 50;
            item.rare = 2;
            item.accessory = true;
        }

        public override void UpdateEquip(Player player)
        {
            player.meleeDamage = 0.2f;
            player.thrownDamage = 0.2f;
            player.rangedDamage = 0.2f;
            player.magicDamage = 0.2f;
            player.minionDamage = 0.2f;
            player.meleeSpeed = 0.33f;
            player.thrownCost33 = true;
            player.ammoCost75 = true;
            player.moveSpeed += 0.33f;
            player.maxMinions++;
            player.statDefense += 100;
            player.manaCost -= 0.33f;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.CobaltShield, 1);
            recipe.AddIngredient(ItemID.MusketBall, 1);
            recipe.AddIngredient(ItemID.ManaCrystal, 1);
            recipe.AddIngredient(ItemID.HerculesBeetle, 1);
            recipe.AddIngredient(ItemID.AvengerEmblem, 1);
            recipe.AddIngredient(ItemID.FeralClaws, 1);
            recipe.AddIngredient(ItemID.HermesBoots, 1);
            recipe.AddIngredient(ItemID.Book, 1);
            recipe.AddTile(TileID.Autohammer);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
    }
}


Is autoload enabled in your main mod file?
 
I have a question:
How do I make a block that plays a sound that can be pitched and be activated by cable?
And how can I make a custom music box?
I could not figure it out
 
But that is what wasn't working before.

It doesn't have any function apart from making something simple complicated.

If you really insist on using Autoload, then add IList<EquipType> equips as a third parameter (and Sytem.Collections.Generic as a using directive), but there is literally no benefit of doing that above just doing it the normal way, unless you for some reason want to separate image files from their scripts.
 
I have been messing around with this trying to make one item, and I can safely say after scrolling through every page of your tutorial, countless you tube tutorials and threads on these forums, I can safely say that this is more perplexing then trying to comprehend what is outside the known universe. How does anyone manage to create mods? I cant even make a basic sword.
 
Can someone please tell me whats wrong with this?
Code:
  public override void AI()
        {
            npc.ai[0]++;
            Player P = Main.player[npc.target];
            if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
            {
                npc.TargetClosest(true);
            }
            npc.netUpdate = true;

            npc.ai[1] >= 230)
            {
                float Speed = 20f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                int damage = 10;
                int type = mod.ProjectileType("DragonSlimePro");
                Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
                float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
                int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)(Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
                npc.ai[1] = 0;
            }
        }
 
I have been messing around with this trying to make one item, and I can safely say after scrolling through every page of your tutorial, countless you tube tutorials and threads on these forums, I can safely say that this is more perplexing then trying to comprehend what is outside the known universe. How does anyone manage to create mods? I cant even make a basic sword.

Mainly because the most people that start modding have not programmed before. Meaning that they are using applied programming without even knowing basic programming. It's like taking up scuba diving if you don't know how to swim.
Can someone please tell me whats wrong with this?
Code:
  public override void AI()
        {
            npc.ai[0]++;
            Player P = Main.player[npc.target];
            if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
            {
                npc.TargetClosest(true);
            }
            npc.netUpdate = true;

            npc.ai[1] >= 230)
            {
                float Speed = 20f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                int damage = 10;
                int type = mod.ProjectileType("DragonSlimePro");
                Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
                float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
                int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)(Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
                npc.ai[1] = 0;
            }
        }

Looks like a part of your if statement went missing (at npc.ai[1] >= 230) ).
 
Mainly because the most people that start modding have not programmed before. Meaning that they are using applied programming without even knowing basic programming. It's like taking up scuba diving if you don't know how to swim.

Can you please help me what is wrong with this then? Click the URL and go to my last comment. I got the entire code, and the displayed error message if it helps.
 
Mainly because the most people that start modding have not programmed before. Meaning that they are using applied programming without even knowing basic programming. It's like taking up scuba diving if you don't know how to swim.


Looks like a part of your if statement went missing (at npc.ai[1] >= 230) ).
I just fixed that and there was also something wrong in here:
Code:
 {
                float Speed = 20f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                int damage = 10;
                int type = mod.ProjectileType("DragonSlimePro");
                Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
                float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
                int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)(Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
                npc.ai[1] = 0;
            }
And I don't what it is.
 
I just fixed that and there was also something wrong in here:
Code:
 {
                float Speed = 20f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                int damage = 10;
                int type = mod.ProjectileType("DragonSlimePro");
                Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
                float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
                int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)(Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
                npc.ai[1] = 0;
            }
And I don't what it is.
go into your /terraria/ModLoader/Logs/Compile Errors.txt and it'll be easier to help you

also its because of this, pay attention when there is an error, it usually directs you to the line
Projectile.NewProjectile(vector8.X, vector8.Y, (float)((Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);

you was missing just that red one right there
 
Last edited:
I just fixed that and there was also something wrong in here:
Code:
 {
                float Speed = 20f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                int damage = 10;
                int type = mod.ProjectileType("DragonSlimePro");
                Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
                float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
                int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)(Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);
                npc.ai[1] = 0;
            }
And I don't what it is.

Take a look at this line:
Code:
int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)(Math.Cos(rotation) * Speed) * -1), (float)((Math.Sin(rotation) * Speed) * -1), type, damage, 0f, 0);

The parentheses don't add up, you end the argument list after -1.
Code:
int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)(Math.Cos(rotation) * Speed) * -1);

Next time though, please provide the error you're getting, so I don't have to sift through the entire code. Also, do yourself a favour and don't give variables names like vector8, give them something more descriptive. Will save you a lot of stress later on.
 
I get this error when I try to build my mod:
Code:
c:\Users\Bryson\Documents\My Games\Terraria\ModLoader\Mod Sources\GunPulse\Items\DragonEgg.cs(32,13) : warning CS0162: Unreachable code detected

c:\Users\Bryson\Documents\My Games\Terraria\ModLoader\Mod Sources\GunPulse\NPCs\Boss\DragonSlime.cs(71,40) : error CS0234: The type or namespace name 'NewProjectile' does not exist in the namespace 'GunPulse.Projectile' (are you missing an assembly reference?)
And here is the code for the Dragon Slime
Code:
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Graphics.Effects;
using Terraria.Graphics.Shaders;
using Terraria.ID;
using Terraria.ModLoader;

namespace GunPulse.NPCs.Boss
{
    public class DragonSlime : ModNPC
    {
        public override void SetDefaults()
        {
            npc.name = "Dragon Slime";
            npc.displayName = "Dragon Slime";
            npc.aiStyle = 3;
            npc.lifeMax = 5000;
            npc.damage = 60;
            npc.defense = 200;
            npc.knockBackResist = 0;
            npc.width = 162;
            npc.height = 126;
            animationType = NPCID.Zombie;
            Main.npcFrameCount[npc.type] = 3;
            npc.value = Item.buyPrice(0, 40, 75, 42);
            aiType = NPCID.Bunny;
            npc.npcSlots = 1f;
            npc.boss = true;
            npc.lavaImmune = true;
            npc.noGravity = false;
            npc.noTileCollide = false;
            npc.soundHit = 8;
            npc.soundKilled = 14;
            npc.netAlways = true;
        }
        public override void AutoloadHead(ref string headTexture, ref string bossHeadTexture)
        {
            bossHeadTexture = "GunPulse/NPCs/Boss/DragonSlime_Head_Boss";
        }
        public override void BossLoot(ref string name, ref int potionType)
        {
            potionType = ItemID.GreaterHealingPotion;
            Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType("DragonBar"), 23);
        }
        public override void ScaleExpertStats(int numPlayers, float bossLifeScale)
        {
            npc.lifeMax += (int)(npc.lifeMax * 0.579f * bossLifeScale);
            npc.damage += (int)(npc.damage * 0.6f);
        }
        public override void AI()
        {
            npc.ai[0]++;
            Player P = Main.player[npc.target];
            if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead || !Main.player[npc.target].active)
            {
                npc.TargetClosest(true);
            }
            npc.netUpdate = true;

            npc.ai[1]++;
            if (npc.ai[1] >= 230)
            {
                float Speed = 20f;
                Vector2 vector8 = new Vector2(npc.position.X + (npc.width / 2), npc.position.Y + (npc.height / 2));
                int damage = 10;
                int type = mod.ProjectileType("DragonSlimePro");
                Main.PlaySound(23, (int)npc.position.X, (int)npc.position.Y, 17);
                float rotation = (float)Math.Atan2(vector8.Y - (P.position.Y + (P.height * 0.5f)), vector8.X - (P.position.X + (P.width * 0.5f)));
                int num54 = Projectile.NewProjectile(vector8.X, vector8.Y, (float)(Math.Cos(rotation) * Speed) * -1);
                npc.ai[1] = 0;
            }
        }
    }
}
Whats wrong here?
 
Back
Top Bottom