Standalone [1.3] tModLoader - A Modding API

Can you show us your animation code?
Projectile code?
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Tremor.Projectiles {

public class Pixinator : ModProjectile
{
    public override void SetDefaults()
    {
        projectile.name = "Pixinator";
        projectile.width = 24;
        projectile.aiStyle = 1;
        projectile.height = 32;
        Main.projFrames[projectile.type] = 2;
        projectile.friendly = true;
        projectile.penetrate = -1;
        projectile.timeLeft = 18000;
        projectile.tileCollide = true;
        projectile.ignoreWater = true;
    }
}}
 
That's the attributes section, you're only telling it how many frames are available for use

For a basic animation, put in the AI() method for the projectile class:

Code:
projectile.frameCounter++;

if (projectile.frameCounter > 16)
{
    projectile.frame++;
    projectile.frameCounter = 0;
}
if (projectile.frame > 1)
{
   projectile.frame = 0;
}

frameCounter upticks the counter for however many ticks you need before it can advance a frame. Here it takes 16 ticks before it can advance a frame, then resets the frame counter. When it advances a frame, it "animates".

The next bit is the index for the frames. You start with 0 here, then it advances to 1, then after the frame advances again, it goes back to 0, thus animating it. This part here is useful for when you have a animated projectile with several different animations that would be used for different scenarios, like the flying and walking animation of pets.
 
That's the attributes section, you're only telling it how many frames are available for use

For a basic animation, put in the AI() method for the projectile class:

Code:
projectile.frameCounter++;

if (projectile.frameCounter > 16)
{
    projectile.frame++;
    projectile.frameCounter = 0;
}
if (projectile.frame > 1)
{
   projectile.frame = 0;
}

frameCounter upticks the counter for however many ticks you need before it can advance a frame. Here it takes 16 ticks before it can advance a frame, then resets the frame counter. When it advances a frame, it "animates".

The next bit is the index for the frames. You start with 0 here, then it advances to 1, then after the frame advances again, it goes back to 0, thus animating it. This part here is useful for when you have a animated projectile with several different animations that would be used for different scenarios, like the flying and walking animation of pets.
Thanks now it's animated! Now I only need to find the Waspgun Wasp AI and also find out why the projectile isn't rotating when I'm changing direction of shooting...
 
ummm how do I make a armor piece? I keep on using the layout of the example mod but it wont work
this is what I got
Code:
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace AeonsOfTerraria.Items.Armor {
public class AeonBrestplate : ModItem
{
    public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
    {
        equips.Add(EquipType.Body);
        return true;
    }

    public override void SetDefaults()
    {
        item.name = "Aeon Breastplate";
        item.width = 18;
        item.height = 18;
        AddTooltip("the ultimate brestplate.");
        item.value = 999999;
        item.rare = 10;
        item.defense = 999999999;
    }
   
    public override void UpdateEquip(Player player)
    {
        player.buffImmune[BuffID.OnFire] = true;
        player.statManaMax2 += 1000000;
        }   
       
    public override void AddRecipes()
    {
        ModRecipe recipe = new ModRecipe(mod);
        recipe.AddIngredient(null, "TrueCoreAes", 30);
        recipe.AddIngredient(null, "TrueCoreCaelum", 30);
        recipe.AddIngredient(null, "TrueCoreFerus", 30);
        recipe.AddIngredient(null, "TrueCoreFortis", 30);
        recipe.AddIngredient(null, "TrueCoreInfernum", 30);
        recipe.AddIngredient(null, "TrueCoreLunar", 30);
        recipe.AddIngredient(null, "TrueCoreMalum", 30);
        recipe.AddIngredient(null, "TrueCoreRare", 30);
        recipe.AddIngredient(null, "TrueCoreSanctus", 30);
        recipe.AddTile(null, "AncientTransmuter");
        recipe.SetResult(this);
        recipe.AddRecipe();
    }
}}
 
ummm how do I make a armor piece? I keep on using the layout of the example mod but it wont work
this is what I got
Code:
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace AeonsOfTerraria.Items.Armor {
public class AeonBrestplate : ModItem
{
    public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
    {
        equips.Add(EquipType.Body);
        return true;
    }

    public override void SetDefaults()
    {
        item.name = "Aeon Breastplate";
        item.width = 18;
        item.height = 18;
        AddTooltip("the ultimate brestplate.");
        item.value = 999999;
        item.rare = 10;
        item.defense = 999999999;
    }

    public override void UpdateEquip(Player player)
    {
        player.buffImmune[BuffID.OnFire] = true;
        player.statManaMax2 += 1000000;
        }
   
    public override void AddRecipes()
    {
        ModRecipe recipe = new ModRecipe(mod);
        recipe.AddIngredient(null, "TrueCoreAes", 30);
        recipe.AddIngredient(null, "TrueCoreCaelum", 30);
        recipe.AddIngredient(null, "TrueCoreFerus", 30);
        recipe.AddIngredient(null, "TrueCoreFortis", 30);
        recipe.AddIngredient(null, "TrueCoreInfernum", 30);
        recipe.AddIngredient(null, "TrueCoreLunar", 30);
        recipe.AddIngredient(null, "TrueCoreMalum", 30);
        recipe.AddIngredient(null, "TrueCoreRare", 30);
        recipe.AddIngredient(null, "TrueCoreSanctus", 30);
        recipe.AddTile(null, "AncientTransmuter");
        recipe.SetResult(this);
        recipe.AddRecipe();
    }
}}
What doesn't work exactly? Do you get an error? Doesn't ithe recipe appear or doesn't the armor show up when you equip it?

EDIT:
Could it be the spelling mistake of your class? If your .cs file is named 'AeonBreastplate.cs', you should change the class name to the same (you got 'AeonBrestplate').
 
Last edited:
ummm how do I make a armor piece? I keep on using the layout of the example mod but it wont work
this is what I got
Code:
using System;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace AeonsOfTerraria.Items.Armor {
public class AeonBrestplate : ModItem
{
    public override bool Autoload(ref string name, ref string texture, IList<EquipType> equips)
    {
        equips.Add(EquipType.Body);
        return true;
    }

    public override void SetDefaults()
    {
        item.name = "Aeon Breastplate";
        item.width = 18;
        item.height = 18;
        AddTooltip("the ultimate brestplate.");
        item.value = 999999;
        item.rare = 10;
        item.defense = 999999999;
    }
  
    public override void UpdateEquip(Player player)
    {
        player.buffImmune[BuffID.OnFire] = true;
        player.statManaMax2 += 1000000;
        }  
      
    public override void AddRecipes()
    {
        ModRecipe recipe = new ModRecipe(mod);
        recipe.AddIngredient(null, "TrueCoreAes", 30);
        recipe.AddIngredient(null, "TrueCoreCaelum", 30);
        recipe.AddIngredient(null, "TrueCoreFerus", 30);
        recipe.AddIngredient(null, "TrueCoreFortis", 30);
        recipe.AddIngredient(null, "TrueCoreInfernum", 30);
        recipe.AddIngredient(null, "TrueCoreLunar", 30);
        recipe.AddIngredient(null, "TrueCoreMalum", 30);
        recipe.AddIngredient(null, "TrueCoreRare", 30);
        recipe.AddIngredient(null, "TrueCoreSanctus", 30);
        recipe.AddTile(null, "AncientTransmuter");
        recipe.SetResult(this);
        recipe.AddRecipe();
    }
}}
Do you have both of the .png files for it? One is shown in game and you have to animate that and then there is the one that is shown in your inventory.
 
You need a total of 4 sprited for the body armor: One for the item, one for the Male animation, one for the female and one of the arms, but that's all included in the example mod.
 
How do I get a projectile to fall from the sky?
Do you want this effect on a custom projectile, or with a custom weapon?
If it's the weapon part you want, you can override the Shoot function on the ModItem and give the position.Y (of the projectile you want to shoot) some negative values like 'position.Y -= 100;' and fiddle around a bit with the speedX and speedY values depending on which side the player is facing (if you want to take that into account). After that just return true in the shoot function and (with a bit of fiddling around with the values) you might just end up with the effect you want.
If you want this effect on a custom projectile, it's going to be a bit harder (still quite possible, though) you actually want to do the same as with the custom weapon (change the position etc.) in the AI function (which you'll have to override). Inside this AI, you have to do a check if the projectile hasn't updated yet so something like this will do (note, this can be better)
Code:
private bool hasUpdated = false;
public override void AI()
{
        if(!hasUpdated)
        {
                hasUpdated = true;
                projectile.position.Y -= 100;
                // Change the velocity parameter of the projectile here.     
        }
}
As you can see, I've added a comment. Instead of changing speedX and speedY parameters like you'd do with the custom weapon, you have to change the projectile.velocity.X and projectile.velocity.Y parameters to get the effect you want. Again, fiddle around with this a bit untill you end up with the effect you want (since the effect you want to achieve might differ from the effect I'm thinking of, so I'm not giving you resolute values).
Hope this helps you on your way.

P.S. Sorry for the large amount of text ><
 
My axe I made can't cut wood for some reason. The auto block select goes toward the nearest tree but wont cut it. It does not make the cutting sound.
public override void SetDefaults()
{
item.name = "Lightning Waraxe";
item.damage = 15;
item.melee = true;
item.width = 50;
item.height = 50;
item.useTime = 10;
item.useAnimation = 10;
item.useStyle = 1;
item.knockBack = 5;
item.value = 10000;
item.rare = 2;
item.useSound = 1;
item.autoReuse = true;
item.shoot = mod.ProjectileType("Bolt");
item.shootSpeed = 15f;
item.axe = 30;
}
}}
 
My axe I made can't cut wood for some reason. The auto block select goes toward the nearest tree but wont cut it. It does not make the cutting sound.
public override void SetDefaults()
{
item.name = "Lightning Waraxe";
item.damage = 15;
item.melee = true;
item.width = 50;
item.height = 50;
item.useTime = 10;
item.useAnimation = 10;
item.useStyle = 1;
item.knockBack = 5;
item.value = 10000;
item.rare = 2;
item.useSound = 1;
item.autoReuse = true;
item.shoot = mod.ProjectileType("Bolt");
item.shootSpeed = 15f;
item.axe = 30;
}
}}
Items that shoot projectiles can't be used as tools.
 
how would i make something like the portal gun like when you right click it shoots something else?

Try putting
Code:
if (Main.mouseRight && Main.mouseRightRelease)
{
    // Create  new projectile here
}

in the HoldItem method for your ModItem class. Note that this is a simpler conditional, and that it will shoot your custom projectile even when you're opening doors, chests or talking to NPCs while holding the item in your hand, which is a behavior I've noticed in the portal gun anyway.
 
Hi!
I got two questions.
1. I really like the singleplayer chat, it is really handy to be able to spawn npcs easily. But how do I make them spawn a little bit to the right of the player or spawn in groups of for example 10? When i look through the code for it in the example mod I see that it is possible but i just do not get it to work.

2. I want a text to appear when I defeat Plantera for the first time in a world. I am using this code in NPCLoot in GlobalNPC.
Code:
if(npc.type == 262)
            {
                bool flag3 = NPC.downedPlantBoss;
                NPC.downedPlantBoss = true;
                if (!flag3)
                {
                    Main.NewText("Some text", 50, 255, 130);
                }
                else
                {
                    Main.NewText(Some other text", 50, 255, 130);
                }
            }
The else statement is only there for testing purposes. Every time I take down Plantera, it does not matter if it is the first time in a world or the tenth, it always shows "Some other text". Am i doing something wrong?
 
Hi!
I got two questions.
1. I really like the singleplayer chat, it is really handy to be able to spawn npcs easily. But how do I make them spawn a little bit to the right of the player or spawn in groups of for example 10? When i look through the code for it in the example mod I see that it is possible but i just do not get it to work.

2. I want a text to appear when I defeat Plantera for the first time in a world. I am using this code in NPCLoot in GlobalNPC.
Code:
if(npc.type == 262)
            {
                bool flag3 = NPC.downedPlantBoss;
                NPC.downedPlantBoss = true;
                if (!flag3)
                {
                    Main.NewText("Some text", 50, 255, 130);
                }
                else
                {
                    Main.NewText(Some other text", 50, 255, 130);
                }
            }
The else statement is only there for testing purposes. Every time I take down Plantera, it does not matter if it is the first time in a world or the tenth, it always shows "Some other text". Am i doing something wrong?

1. Assuming you're using the example mod, if you want to make them spawn a little bit to the right, then you need to do something like "/npc npcType ~16 ~0", where the numbers after the ~ signs are the coordinate offsets in pixels from the player. (If you don't use the ~ symbol it will use the absolute coordinates instead of the relative coordinates.) To spawn them in groups, you'll need to add the number you want to spawn after the coordinates, like this: "/npc npcType ~0 ~0 10"

2. The problem is that the vanilla NPCLoot is already setting downedPlantBoss to true before the GlobalNPC's NPCLoot is called. What you'll have to do is to place that code in PreNPCLoot instead, and don't set NPC.downedPlantBoss yourself (letting vanilla set that).
 
Blue Magic, I'm attempting to add more mods/items to the example, how can i get passed this,
Terraria.ID.ItemID Does not contain a definition for "ModdedItem"
Please Help, How do i add Defintions for the Items to work ? I'm attempting to port from Tapi also, for custom mods.
 
Blue Magic, I'm attempting to add more mods/items to the example, how can i get passed this,
Terraria.ID.ItemID Does not contain a definition for "ModdedItem"
Please Help, How do i add Defintions for the Items to work ? I'm attempting to port from Tapi also, for custom mods.
What exactly are you trying to do? Show us some code to let us help you.
 
Code:
//This is added to the Example Mod Script,

recipe = new ModRecipe(this);
        recipe.AddIngredient(null, "ExampleItem");
        recipe.SetResult(ItemID.Mega Blade);
        recipe.AddRecipe();

//This will be in the items file, in the souces, and has a picture along with it named Mega Blade

using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using Terraria.ModLoader;

namespace ExampleMod.Items {
public class Face: ModItem
{
    public override void SetDefaults()
    {
        item.name = "Mega Cyan Blade";
        item.width = 20;
        item.damage = 70;
        item.melee = true;
        item.useAnimation = 15;
        item.useSound = 1;
        item.autoReuse = true;
        item.height = 20;
        item.maxStack = 1;
        item.tooltip = "Cutting The Vines.";
        item.value = 500;
        item.rare = 1;
        item.hammer = 100;
        item.axe = 100;
     }
    public override void AddRecipes()
    {
       ModRecipe recipe = new ModRecipe(mod);
        recipe.AddIngredient(null, "ExampleItem");
        recipe.SetResult(this);
        recipe.AddRecipe();
    }
}}

//After ill have an error when i try to build and reload saying Terraria.ID.ItemID Does not contain a defintion for "Mega Blade"
 
Back
Top Bottom