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! :)
 
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! :)

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 :)
 
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 :(

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:
Back
Top Bottom