tModLoader Official tModLoader Help Thread

I'm not certain, but I think you would need to update item.useStyle directly. The SetDefault hook is only called once, so changing swing has no impact during gameplay.
So how would I go about that? I'd assume I would want to change that using the UseItem bool, but I can't figure out how I'd go about doing this
 
IDK if be real, but here is the first way:
C#:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace testMod.Items
{
    public class whyNot : ModItem
    {
        public int swing = 0;
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("chonkSword");
            Tooltip.SetDefault("This is not basic modded sword.");
        }

        public override void SetDefaults()
        {
            item.damage = 2140;
            item.melee = true;
            item.width = 40;
            item.height = 40;
            item.useTime = 30;
            item.useAnimation = 20;
            item.useStyle = swing;
            item.knockBack = 90;
            item.value = 10000;
            item.rare = ItemRarityID.Cyan;
            item.UseSound = SoundID.Item1;
            item.autoReuse = true;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.DirtBlock, 10);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
        public override bool UseItem(Player player)
        {
            swing += 1;
            if (swing > 3) swing = 0;
            return true; //using weapon after setting
        }
    }
}
And the second way:
C#:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace testMod.Items
{
    public class whyNot : ModItem
    {
        public int swing = 0;
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("chonkSword");
            Tooltip.SetDefault("This is not basic modded sword.");
        }

        public override void SetDefaults()
        {
            item.damage = 2140;
            item.melee = true;
            item.width = 40;
            item.height = 40;
            item.useTime = 30;
            item.useAnimation = 20;
            item.useStyle = 0; //that's standard swing (on start)
            item.knockBack = 90;
            item.value = 10000;
            item.rare = ItemRarityID.Cyan;
            item.UseSound = SoundID.Item1;
            item.autoReuse = true;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.DirtBlock, 10);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
        public override bool UseItem(Player player)
        {
            swing += 1;
            if (swing > 3) swing = 0;
            item.useStyle = swing; //changing swing right from there
            return true; //using weapon
        }
    }
}
Quote this post if you will have compile (send screen of error, but try to fix it yourself if possible) / in-game error (describe it and send video if possible).
 
IDK if be real, but here is the first way:
C#:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace testMod.Items
{
    public class whyNot : ModItem
    {
        public int swing = 0;
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("chonkSword");
            Tooltip.SetDefault("This is not basic modded sword.");
        }

        public override void SetDefaults()
        {
            item.damage = 2140;
            item.melee = true;
            item.width = 40;
            item.height = 40;
            item.useTime = 30;
            item.useAnimation = 20;
            item.useStyle = swing;
            item.knockBack = 90;
            item.value = 10000;
            item.rare = ItemRarityID.Cyan;
            item.UseSound = SoundID.Item1;
            item.autoReuse = true;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.DirtBlock, 10);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
        public override bool UseItem(Player player)
        {
            swing += 1;
            if (swing > 3) swing = 0;
            return true; //using weapon after setting
        }
    }
}
And the second way:
C#:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace testMod.Items
{
    public class whyNot : ModItem
    {
        public int swing = 0;
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("chonkSword");
            Tooltip.SetDefault("This is not basic modded sword.");
        }

        public override void SetDefaults()
        {
            item.damage = 2140;
            item.melee = true;
            item.width = 40;
            item.height = 40;
            item.useTime = 30;
            item.useAnimation = 20;
            item.useStyle = 0; //that's standard swing (on start)
            item.knockBack = 90;
            item.value = 10000;
            item.rare = ItemRarityID.Cyan;
            item.UseSound = SoundID.Item1;
            item.autoReuse = true;
        }

        public override void AddRecipes()
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.DirtBlock, 10);
            recipe.AddTile(TileID.WorkBenches);
            recipe.SetResult(this);
            recipe.AddRecipe();
        }
        public override bool UseItem(Player player)
        {
            swing += 1;
            if (swing > 3) swing = 0;
            item.useStyle = swing; //changing swing right from there
            return true; //using weapon
        }
    }
}
Quote this post if you will have compile (send screen of error, but try to fix it yourself if possible) / in-game error (describe it and send video if possible).

I ended up getting it to work partially how I wanted, and two things.

1. Using 0 as the standard swing style didn't work, 1 was the original swing instead
2. The sprite and using of the item is glitchy, as I don't think any item was meant to be used in more than 1 style
 
I ended up getting it to work partially how I wanted, and two things.

1. Using 0 as the standard swing style didn't work, 1 was the original swing instead
2. The sprite and using of the item is glitchy, as I don't think any item was meant to be used in more than 1 style
sure. but the first 3 styles are normal for swords I think...
 
sure. but the first 3 styles are normal for swords I think...
They are, but when you swing in style 3 after style 1 for example, the sword will flash behind your character before teleporting where it should for the style change. It inflicts damage behind the character as well, causing an overall buggy feel.
 
They are, but when you swing in style 3 after style 1 for example, the sword will flash behind your character before teleporting where it should for the style change. It inflicts damage behind the character as well, causing an overall buggy feel.
I know by the way. So, your sword was probably just fun thing so it is more like test thing
 
They are, but when you swing in style 3 after style 1 for example, the sword will flash behind your character before teleporting where it should for the style change. It inflicts damage behind the character as well, causing an overall buggy feel.
I had a look through some old code for one of my mods, and I got it working by changing item.useStyle in the HoldItem hook. The HoldItem hook is called every frame, so you won't want to increase your swing int with it. Instead use UseItem to increase swing like you already do, and use HoldItem to set item.useStyle to swing.
 
How do you check if the player was hit and how to apply it to an item/ accesory?
I know its probably something really simple and just something I havent discovered yet but I'd really appreciate it if someone knew how to do that...
Nvm I figured it out myself...
 
Last edited:
@michaelsoftman do you mean werewolf or wolf
The wolf uses npc hit sound 1 for organic, the werewolf uses npc hit sound 6 which is the 'beast' hit sound.
Have fun :)
Edit:There is also an easy way to check for all of these hit sounds.
Someone created a thread for that.
This is the thread: tModLoader - Dust and Sound Catalogue 2
I really recommend checking it out.
 
Last edited:
Is there any way at all to get steam achievements/time with tmodloader? like a manual install or etc. I heard the installation manual method changed though, you have to put it in a separate folder instead of replacing the terraria folder files, so is there any workaround at all? I don't like 1.4 much bc of the changes like the NPC house prices/happiness, reaver shark nerf etc, I'd love to play terraria 1.3.5.3 or tmodloader 1.3.5.3 and get steam achievements.
 
Im not sure if its possible but I doubt it.
Many of the achievments did not exist i 1.3.5.3 and Im not even sure if Tmodloader is compatible with achievments.
There is probably a way to download Terraria 1.3.5.3 but that is probably on an other side of the Internet.
Maybe I missed something but as far as I know it isnt possible.
But you could search for a mod that adds achievements or similiar.
 
the Steam cloud sometimes messes things up and causes Tmodloader to crash.
Are there problems with any other games too?
Edit:I'll have to read your stuff later since I'll be offline for now.
I hope someone else can fix it while I'm gone
Good luck ;)
 
Back
Top Bottom