tModLoader Official tModLoader Help Thread

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?
 
You don't need anything special to do this.
In your UpdateArmorSet:
Code:
player.setBonus = Language.GetTextValue("ArmorSetBonus.Palladium");
player.onHitRegen = true;
it works, except for the "player.setBonus = Language.GetTextValue("ArmorSetBonus.Palladium");"
part but not that it matters because i can just type "Greatly increases life regeneration after striking an enemy"
 
how do i make an accessory that makes you immune to a buff? im trying to make something interesting and i want it to make you immune to distorted.
 
Last edited:
is there some way to modify player knockback through an accessory? I found something called .GetWeaponKnockback but I can’t figure out how to set it up properly or even if it would do what i want anyway.
 
is there some way to modify player knockback through an accessory? I found something called .GetWeaponKnockback but I can’t figure out how to set it up properly or even if it would do what i want anyway.

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! :guidesmile:
 
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.
 
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! :guidesmile:

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 :guidesmile:
 
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?
 
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 :guidesad:

EDIT: Nvm, apparently the Guide spritesheet had one frame the example didn’t that was messing the whole thing up lol
 
Last edited:
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.
 
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:
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.
 
Back
Top Bottom