Standalone [1.3] tModLoader - A Modding API

True, sometimes even nanoseconds, but XNA (the library used for Terraria) allows for a 'standard' framerate (a bit like vsync). This will cap your FPS at 60 and will try to make updates work towards that number (when you're experiencing frame drops). So you can safely state that there are 60 ticks every second using XNA/Terraria.
No more, no less.
umm how?? I get what you mean but I cant seem to work it out
 
the delay of 0.1 second?
like in lua its just
wait(0.1)
Yeah, unfortunately this ain't that simple. If you want to use a build in 'wait' command, you'll either have to work with 'workers' or 'threading' (those are the two fastest/easiest), but I wouldn't recommend any of them, since it's just for this one function (it's really over-the-top to use something like what I mentioned to implement what you want). You could also use a while loop, but... meh. Like I said, best thing you can do is make a timer yourself.
Create a variable, increment that variable every update (so 60x every second). You can then check that value against 60 or 120 or 180, etc depending on the time you want to wait. Waiting for 0.1 second would mean you need to check the variable against 6.
 
Yeah, unfortunately this ain't that simple. If you want to use a build in 'wait' command, you'll either have to work with 'workers' or 'threading' (those are the two fastest/easiest), but I wouldn't recommend any of them, since it's just for this one function (it's really over-the-top to use something like what I mentioned to implement what you want). You could also use a while loop, but... meh. Like I said, best thing you can do is make a timer yourself.
Create a variable, increment that variable every update (so 60x every second). You can then check that value against 60 or 120 or 180, etc depending on the time you want to wait. Waiting for 0.1 second would mean you need to check the variable against 6.
I might have solved it using System.Diagnostic.Stopwatch sw = new Stopwatch();
code:
Code:
        public override void UseStyle(Player player)
        {
                int counter = 1; //charge-up counter
                int Power = 6; //projectile speed
                int counterLimit = 11; //say every "charge" is per 0.1 sec which makes the limit to 1 second (full charge)
                //int PenBase = 3; //defense reduction
                if (counter > 1 && item.channel == true)
                {
                    stylenumber = 4;
                    } else if (counter >1 && item.channel == true){
                    stylenumber = 5;
                    item.shootSpeed = Power;
                    item.shoot = mod.ProjectileType("SASKnife");
                    } else if (item.channel == true){
                        if (counter < counterLimit)
                        {
                            System.Diagnostics.Stopwatch sw = new Stopwatch();
                            sw.Start();
                            if (sw.ElapsedMilliseconds == 100)
                            {
                                sw.Stop();
                                Power++;
                                counter++;
                            }
                            sw.Reset();
                        }
                    } else {
                    stylenumber = 1;
                }
        }
haven't added the projectile for SASKnife (one is for melee the other is to throw)
 
I might have solved it using System.Diagnostic.Stopwatch sw = new Stopwatch();
code:
Code:
        public override void UseStyle(Player player)
        {
                int counter = 1; //charge-up counter
                int Power = 6; //projectile speed
                int counterLimit = 11; //say every "charge" is per 0.1 sec which makes the limit to 1 second (full charge)
                //int PenBase = 3; //defense reduction
                if (counter > 1 && item.channel == true)
                {
                    stylenumber = 4;
                    } else if (counter >1 && item.channel == true){
                    stylenumber = 5;
                    item.shootSpeed = Power;
                    item.shoot = mod.ProjectileType("SASKnife");
                    } else if (item.channel == true){
                        if (counter < counterLimit)
                        {
                            System.Diagnostics.Stopwatch sw = new Stopwatch();
                            sw.Start();
                            if (sw.ElapsedMilliseconds == 100)
                            {
                                sw.Stop();
                                Power++;
                                counter++;
                            }
                            sw.Reset();
                        }
                    } else {
                    stylenumber = 1;
                }
        }
haven't added the projectile for SASKnife (one is for melee the other is to throw)
Well, if you think that's the way to go about it (and it works) then go right ahead ;)
 
HOW TO MAKE MOD PLEASE TUTORIAL !
Please do not post with Capital letters only...
Other than that, there aren't that many tutorials out there yet, but there is a link in the OP that should help you get started.
You can also download the Example mod to look at how things are done exactly.
It's also recommendable to search for some C# tutorials (if you don't know how to code with it already that is).
 
I think some tapi classes and method can be added in this tool
Well, it's a good thing I've been adding tapi classes and methods ever since I started working on this, right? :p

I might have solved it using System.Diagnostic.Stopwatch sw = new Stopwatch();
code:
Code:
        public override void UseStyle(Player player)
        {
                int counter = 1; //charge-up counter
                int Power = 6; //projectile speed
                int counterLimit = 11; //say every "charge" is per 0.1 sec which makes the limit to 1 second (full charge)
                //int PenBase = 3; //defense reduction
                if (counter > 1 && item.channel == true)
                {
                    stylenumber = 4;
                    } else if (counter >1 && item.channel == true){
                    stylenumber = 5;
                    item.shootSpeed = Power;
                    item.shoot = mod.ProjectileType("SASKnife");
                    } else if (item.channel == true){
                        if (counter < counterLimit)
                        {
                            System.Diagnostics.Stopwatch sw = new Stopwatch();
                            sw.Start();
                            if (sw.ElapsedMilliseconds == 100)
                            {
                                sw.Stop();
                                Power++;
                                counter++;
                            }
                            sw.Reset();
                        }
                    } else {
                    stylenumber = 1;
                }
        }
haven't added the projectile for SASKnife (one is for melee the other is to throw)
Instead of using a stopwatch, you can just create a projectile that behaves the same way as drills, etc. (the example mod has a drill), and use a value in the projectile's ai array to keep count of stuff. (The Sarcophagus has an example of keeping track of time with the ai array.)
 
How do you animate tiles? Say, a 3x2 tile. How would I animate it?
You need to set 'animationFrameHeight' in the SetDefaults method of your ModTile to the height of one frame (note that you need to INCLUDE the padding).
Then you can do something like the following:
Code:
 public override void AnimateTile(ref int frame, ref int frameCounter)
{
    frameCounter++;
    if (frameCounter >= 10) // Here you can change the speed at which your tile animates.
    {
        frame = (frame + 1) % 8; // The '8' needs to be changed to the max frame amount.
        frameCounter = 0;
    }
}
Hope this helps!
 
I have been trying to make a simple mod that adds crafting recipes for vanilla items using vanilla items but when i try to compile i get this error.
Code:
c:\Users\~\Documents\My Games\Terraria\ModLoader\Mod Sources\Craftingrecipes\recipehelper.cs(11,24) : error CS0115: 'Craftingrecipes.RecipeHelper.AddRecipes(Terraria.ModLoader.Mod)': no suitable method found to override

Here is my code:
build.txt
Code:
author = eatintoast
version = v.10
displayName = craftingrecipes

craftingrecipes.cs
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Craftingrecipes {
    public class Craftingrecipes : Mod
    {
        public override void SetModInfo(out string name, ref ModProperties properties)
        {
            name = "Craftingrecipes";
            properties.Autoload = true;
        }
        public override void AddRecipes()
        {
            RecipeHelper.AddRecipes(this);
        }
    }
}

recipehelper.cs
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Craftingrecipes
{
    public class RecipeHelper
    {
        public override void AddRecipes(Mod mod)
        {
            ModRecipe recipe= new ModRecipe(mod);
            recipe.AddIngredient(ItemId.StoneBlock, 10);
            recipe.AddIngredient(ItemId.Silk, 10);
            recipe.AddIngredient(ItemId.Wood, 10);
            recipe.SetResult(ItemId.Aglet);
            recip.Addrecipe();

        }
    }
}
 
I have been trying to make a simple mod that adds crafting recipes for vanilla items using vanilla items but when i try to compile i get this error.
Code:
c:\Users\~\Documents\My Games\Terraria\ModLoader\Mod Sources\Craftingrecipes\recipehelper.cs(11,24) : error CS0115: 'Craftingrecipes.RecipeHelper.AddRecipes(Terraria.ModLoader.Mod)': no suitable method found to override

Here is my code:
build.txt
Code:
author = eatintoast
version = v.10
displayName = craftingrecipes

craftingrecipes.cs
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Craftingrecipes {
    public class Craftingrecipes : Mod
    {
        public override void SetModInfo(out string name, ref ModProperties properties)
        {
            name = "Craftingrecipes";
            properties.Autoload = true;
        }
        public override void AddRecipes()
        {
            RecipeHelper.AddRecipes(this);
        }
    }
}

recipehelper.cs
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Craftingrecipes
{
    public class RecipeHelper
    {
        public override void AddRecipes(Mod mod)
        {
            ModRecipe recipe= new ModRecipe(mod);
            recipe.AddIngredient(ItemId.StoneBlock, 10);
            recipe.AddIngredient(ItemId.Silk, 10);
            recipe.AddIngredient(ItemId.Wood, 10);
            recipe.SetResult(ItemId.Aglet);
            recip.Addrecipe();

        }
    }
}
Look at the Mod mod parameter.
 
I have been trying to make a simple mod that adds crafting recipes for vanilla items using vanilla items but when i try to compile i get this error.
Code:
c:\Users\~\Documents\My Games\Terraria\ModLoader\Mod Sources\Craftingrecipes\recipehelper.cs(11,24) : error CS0115: 'Craftingrecipes.RecipeHelper.AddRecipes(Terraria.ModLoader.Mod)': no suitable method found to override

Here is my code:
build.txt
Code:
author = eatintoast
version = v.10
displayName = craftingrecipes

craftingrecipes.cs
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Craftingrecipes {
    public class Craftingrecipes : Mod
    {
        public override void SetModInfo(out string name, ref ModProperties properties)
        {
            name = "Craftingrecipes";
            properties.Autoload = true;
        }
        public override void AddRecipes()
        {
            RecipeHelper.AddRecipes(this);
        }
    }
}

recipehelper.cs
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace Craftingrecipes
{
    public class RecipeHelper
    {
        public override void AddRecipes(Mod mod)
        {
            ModRecipe recipe= new ModRecipe(mod);
            recipe.AddIngredient(ItemId.StoneBlock, 10);
            recipe.AddIngredient(ItemId.Silk, 10);
            recipe.AddIngredient(ItemId.Wood, 10);
            recipe.SetResult(ItemId.Aglet);
            recip.Addrecipe();

        }
    }
}
Yeah, that ain't going to work. You've got your RecipeHelper class, which doesn't inherit from anything, and you're trying to call an override function...
Just make that function
Code:
public void AddRecipes(Mod mod)
{
    ModRecipe recipe= new ModRecipe(mod);
    recipe.AddIngredient(ItemId.StoneBlock, 10);
    recipe.AddIngredient(ItemId.Silk, 10);
    recipe.AddIngredient(ItemId.Wood, 10);
    recipe.SetResult(ItemId.Aglet);
    recip.Addrecipe();
}
 
Well, it's a good thing I've been adding tapi classes and methods ever since I started working on this, right? :p


Instead of using a stopwatch, you can just create a projectile that behaves the same way as drills, etc. (the example mod has a drill), and use a value in the projectile's ai array to keep count of stuff. (The Sarcophagus has an example of keeping track of time with the ai array.)
I'll check it out! thanks for the info
 
Tile animation not working! Code:
Code:
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ObjectData;

namespace TerraMod.Tiles
{
    public class RudoniateForgeBlock : ModTile
    {
        public override void SetDefaults()
        {
            Main.tileSolidTop[Type] = true;
            Main.tileFrameImportant[Type] = true;
            Main.tileNoAttach[Type] = true;
            Main.tileTable[Type] = true;
            Main.tileLavaDeath[Type] = true;
            TileObjectData.newTile.CopyFrom(TileObjectData.Style3x2);
            TileObjectData.newTile.CoordinateHeights = new int[]{ 34 };
            TileObjectData.addTile(Type);
            this.animationFrameHeight = 34;
            this.minPick = 190;
            dustType = 37;
            drop = mod.ItemType("RudoniateForge");
            AddMapEntry(new Color(24, 97, 134));
        }
       
        public override void AnimateTile(ref int frame, ref int frameCounter)
        {
            frameCounter++;
            if (frameCounter >= 50)
            {
                frame = (frame + 1) % 4;
                frameCounter = 0;
            }
        }
    }
}
Sprite:
RudoniateForgeBlock.png
 
Back
Top Bottom