• For issues you find with the Switch and Console releases, please follow this link and give as much detail as possible. This is the speediest way to get info to Pipeworks and get a hotfix in the works.
  • 1.4 will bring many changes to the PC version. We strongly advise making plans to back up your worlds and players prior to updating your game. More details here.
  • Begin your search for Journey's End information here and here. Please report bugs and issues for Journey's End here.
  • For issues you find with the Mobile 1.3 update, please follow this link and give as much detail as possible. This is the speediest way to get info to DR Studios to look at your issue. Also, some troubleshooting hints here.

tModLoader Official tModLoader Help Thread

shoelid

Terrarian
I'd like to have my sword swing fast with a delay between each swing. My assumption was that I could have useTime be longer than useAnimation to achieve this effect, but that doesn't seem to be the case. I've also tinkered around with reuseDelay to no avail. Any suggestions?
I have another question on top of this: How do i completely turn off pitch variance for a custom sound? I've tried .WithPitchVariance(0f), which doesn't seem to work.
 

Piercepotato

Terrarian
You would probably do this in a ModPlayer class. You should carefully read over what ExampleMod tells you in its SimpleModPlayer file, but what you basically do is this:
Create a public variable in the ModPlayer class that your accessory changes. Say you make it a bool titled knockbackAccessory: public bool knockbackAccessory;

Then in the ResetEffects method in your ModPlayer class, set it to false. This is essentially where you place the default value of your knockbackAccessory variable.
To have your accessory update this, you want to put this line in its UpdateAccessory:player.GetModPlayer<your ModPlayer file name here>().your variable here = true;

Now to make it increase knockback.
In the ModPlayer class, you can use the GetWeaponKnockback to increase the knockback value of your attack only if knockbackAccessory is true:
C#:
public override void GetWeaponKnockback(Item item, ref float knockback)
        {
            if (knockbackAccessory) { knockback *= 999; }
        }
I've only started modding recently, but it seems all the fun stuff happens in the ModPlayer class. I'd recommend getting really comfortable with it.
Good luck! :)
it seems like this worked! Thanks!

i just started modding a few days ago, so I’ll take your word and prioritize learning the ModPlayer class :)
 

Piercepotato

Terrarian
Is there a way I could add a dust/particle trail to a melee weapon? Or maybe spawn a small explosion at a certain point in it’s arc?
 

Piercepotato

Terrarian
I was trying to use the ExampleMod NPC as a base for a custom npc but every animation except for just standing still seems to be broken in half... I even tried just importing the Guide’s sprites and the same thing happened :(

EDIT: Nvm, apparently the Guide spritesheet had one frame the example didn’t that was messing the whole thing up lol
 
Last edited:

shoelid

Terrarian
Is there a way I could add a dust/particle trail to a melee weapon? Or maybe spawn a small explosion at a certain point in it’s arc?
use MeleeEffects in your weapon file. This is what I use for some purple dust on my weapon:
C#:
public override void MeleeEffects(Player player, Rectangle hitbox){
            if (Main.rand.NextFloat() < 0.1) {    //10% chance each frame to spawn dust
                Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, 21, 0f, 0f, 0, new Color(255, 255, 255), 0.72f);
If you want an explosion that's cosmetic only, I guess you could use dust. I think doing a simple incrementing integer with a specific hitbox for the dust so that it spawns in a certain place and time would do the trick.

If you want to have the explosion deal damage you should look into creating projectiles or using preexisting AI. You might be able to put that in MeleeEffects as well, but I'm not sure.

The only experience I have with NPCs is through ExampleMod, so I don't know where your issues might be coming from. Maybe try using the sprites they use and double check that the textures are defined correctly.
 

Piercepotato

Terrarian
use MeleeEffects in your weapon file. This is what I use for some purple dust on my weapon:
C#:
public override void MeleeEffects(Player player, Rectangle hitbox){
            if (Main.rand.NextFloat() < 0.1) {    //10% chance each frame to spawn dust
                Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, 21, 0f, 0f, 0, new Color(255, 255, 255), 0.72f);
If you want an explosion that's cosmetic only, I guess you could use dust. I think doing a simple incrementing integer with a specific hitbox for the dust so that it spawns in a certain place and time would do the trick.

If you want to have the explosion deal damage you should look into creating projectiles or using preexisting AI. You might be able to put that in MeleeEffects as well, but I'm not sure.

The only experience I have with NPCs is through ExampleMod, so I don't know where your issues might be coming from. Maybe try using the sprites they use and double check that the textures are defined correctly.
Thanks for the dust tips! I’ll try to get the effects up and running later tonight.
 
Last edited:

TheDarkLitten

Steampunker
I'm making a custom biome, but the background is black and I'm getting "Index was outside the bounds of the array". Help!
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Terraria.Main.DrawBackground()
at Terraria.Main.RenderBackground()
at Terraria.Main.DoDraw(GameTime gameTime)
at Terraria.Main.Draw(GameTime gameTime)
at Microsoft.Xna.Framework.Game.DrawFrame()
at Microsoft.Xna.Framework.Game.Tick()
at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
at Microsoft.Xna.Framework.GameHost.OnIdle()
at Microsoft.Xna.Framework.WindowsGameHost.RunOneFrame()
at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Microsoft.Xna.Framework.WindowsGameHost.Run()
at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
at Terraria.Program.LaunchGame_()
at Terraria.Program.LaunchGame(String[] args, Boolean monoArgs)
at Terraria.WindowsLaunch.Main(String[] args)
using Terraria;
using Terraria.ModLoader;
namespace Scifi.Backgrounds
{
public class UgBgStyle : ModUgBgStyle
{
public override bool ChooseBgStyle() {
return Main.LocalPlayer.GetModPlayer<ScifiPlayer>().ZoneVoid;
}
public override void FillTextureArray(int[] textureSlots) {
textureSlots[0] = mod.GetBackgroundSlot("Backgrounds/VoidBiomeUG0");
textureSlots[1] = mod.GetBackgroundSlot("Backgrounds/VoidBiomeUG1");
textureSlots[2] = mod.GetBackgroundSlot("Backgrounds/VoidBiomeUG2");
textureSlots[3] = mod.GetBackgroundSlot("Backgrounds/VoidBiomeUG3");
}
}
}
I'm not the best when it comes to coding, sorry.
 

AHIBoy

Steampunker
I am writing code to make the slime staff craft able with 25 gel and 30 wood, but for some reason I keep getting errors no matter what I change. Here is the code currently,
C#:
using Terraria.ID;
using Terraria.ModLoader;

namespace Xtreme
{
    public class XTreme : Mod
    {
    public ModRecipe Recipe { get; private set; }

    public override void AddRecipes()
    {
        ModRecipe recipe = new ModRecipe(this);
        recipe.AddIngredient(ItemID.Gel, 20);
        recipe.AddIngredient(ItemID.Wood, 15);
        recipe.AddTile(TileID.WorkBenches);
        recipe.SetResult(ItemID.SlimeStaff, 1);
        recipe.AddRecipe();
    }
  }
}
When I go to build and reload the mod it says that “Sequence contains more than one matching element” I got this from example mod, just tweaking things for the recipe and for my mods Namespace. I have no Idea what’s going on, and I have tried basically everything. If you need a list of the full error I can post it.
 
Last edited:

michaelsoftman

Terrarian
Is there a way to increase damage for only a specific weapon rather than a damage class? For example, wearing a set of copper armor, the set bonus would be +10% damage to only the copper shortsword.
 

NameTaken

Skeletron
I am writing code to make the slime staff craft able with 25 gel and 30 wood, but for some reason I keep getting errors no matter what I change. Here is the code currently,
C#:
using Terraria.ID;
using Terraria.ModLoader;

namespace Xtreme
{
    public class XTreme : Mod
    {
    public ModRecipe Recipe { get; private set; }

    public override void AddRecipes()
    {
        ModRecipe recipe = new ModRecipe(this);
        recipe.AddIngredient(ItemID.Gel, 20);
        recipe.AddIngredient(ItemID.Wood, 15);
        recipe.AddTile(TileID.WorkBenches);
        recipe.SetResult(ItemID.SlimeStaff, 1);
        recipe.AddRecipe();
    }
  }
}
When I go to build and reload the mod it says that “Sequence contains more than one matching element” I got this from example mod, just tweaking things for the recipe and for my mods Namespace. I have no Idea what’s going on, and I have tried basically everything. If you need a list of the full error I can post it.
That public ModRecipe Recipe { get; private set; } part is something ive never seen before, probably for something extremely complex.
so just
C#:
using Terraria.ID;
using Terraria.ModLoader;

namespace Xtreme
{
    public class XTreme : Mod
    {
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(this);
            recipe.AddIngredient(ItemID.Gel, 20);
            recipe.AddIngredient(ItemID.Wood, 15);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(ItemID.SlimeStaff, 1);
            recipe.AddRecipe();
        }
    }
}
should work, btw, i would recommend making the slime staff much, MUCH more expensive, as it is insanely good for that recipe, but im not here to tell you how to make your mod.
 

AHIBoy

Steampunker
That public ModRecipe Recipe { get; private set; } part is something ive never seen before, probably for something extremely complex.
so just
C#:
using Terraria.ID;
using Terraria.ModLoader;

namespace Xtreme
{
    public class XTreme : Mod
    {
        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(this);
            recipe.AddIngredient(ItemID.Gel, 20);
            recipe.AddIngredient(ItemID.Wood, 15);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(ItemID.SlimeStaff, 1);
            recipe.AddRecipe();
        }
    }
}
should work, btw, i would recommend making the slime staff much, MUCH more expensive, as it is insanely good for that recipe, but im not here to tell you how to make your mod.
It keeps giving me the same error,

“System.InvalidOperationException: Sequence contains more than one matching element”
 

omegashark

Terrarian
So i’m making a gigashark mod and everytime I build+reload it says *invalid expression term ‘/‘ and the error is next to { and I don’t know how to remove it pls help
 

adsfghg

Terrarian
I'm trying to make a prefix that gives the weapon lifesteal
I want a weapon that has this prefix to have lifesteal.
I tried things like writing OnHitNPC in the file but it gives error.
Can anyone tell me what change to make to the code so it works as intended please.
Code:
using Terraria;
using Terraria.ModLoader;


namespace d.Prefixes
{
    public class Lifesteal : ModPrefix
    {
        public override float RollChance(Item item)
            => 50f;

        public override bool CanRoll(Item item)
            => true;

        public override PrefixCategory Category
            => PrefixCategory.AnyWeapon;

        public override void SetStats(ref float damageMult, ref float knockbackMult, ref float useTimeMult, ref float scaleMult, ref float shootSpeedMult, ref float manaMult, ref int critBonus)
        {
            damageMult = 0.6f;
        }
    }
}
 

NameTaken

Skeletron
Im making a new class where you can draw cards, which are consumable weapons from a deck of cards, im having issues with it, though, i want to make it so that if you have a total of ten cards in your inventory, you cannot draw any cards. But i cant figure out how to count the number of cards in the inventory, especially since they stack.

clearly its either gonna be buggy as heck (yes I censored it) or were gonna be able to count the amount of cards in the inventory.

basically what i have is an int (cardCount) that increases by one every time you draw a card from a deck, and decreases by one every time you "play" a card, the problem is, people can trash the cards without lowering the cardCount, then you can only have 9 cards, then 8, until eventually you just cant have cards which, surprisingly, isn't very fun.
 
Last edited:
In a mod I'm making, I have an item that is basically an upgrade to the snowman cannon. It (is supposed to) fire 4 rockets at once that like the snowman cannon home in on enemies and don't deal damage to the player who fired them but it would have a different sprite to the snowman cannon's. However I am having some problems with it:

First - When making the rocket projectile, I tried to clone projectile defaults and ai from the snowman rockets but just change the sprite and name (since it just need to be a resprite anyway) however when I did that it resulted in it having an invisible explosion that still hurts the player and for some reason the rocket bounces off walls now??? So after that failure I tried to make one from scratch but I couldn't find any documentation on making a rocket projectile so after looking through the source and copying some defaults and stuff for the snowman rockets from the base game, I still couldn't work out how to make a rocket work and also I'm not sure how to give it the special type of homing they have if making it from scratch.

Second - For some reason whilst item.useAmmo is AmmoID.Rocket if I make item.shoot anything except ProjectileID.RocketI (including modded projectiles) it will either shoot nothing at all or fire the entirely wrong projectile. And even after checking both the electrosphere launcher and snowman cannon I couldn't find how to fix that and make a rocket launcher convert a rocket to a non-standard rocket. So I couldn't even test the above problem unless I set the rocket launcher to not have an ammo. I have fixed this problem now thanks to penumbra gaming.

Any help with either of these problems would be greatly appreciated. Thanks in advance :)
 
Last edited:
Top Bottom