• PC 1.4.3: An eye for an eye, the Terraria x Don't Starve Together Crossover Update! Get all the details here. Found some bugs? Report them with as much detail as possible here.
  • Xbox & PS 1.4: NEW PATCH released Dec 7 - read the details here. Get all the info on the Journey's End update by clicking here. Known Issues and FAQ can be read here. For any other bugs, report them (with as much detail as possible) here.
  • Switch 1.4: Journey's End will launch on Switch January 4, 2022! More details here.
  • Mobile News: Stay up to date with the latest mobile news here. Report mobile bugs here

tModLoader Official tModLoader Help Thread

Peepachu

Terrarian
How would I go about increasing the swing style by 1 with every swing, then resetting it after the style = 3? This is the code I have so far, with no luck, any help would be greatly appreciated

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace testMod.Items
{
public class whyNot : ModItem
{
public int swing;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("chonkSword"); // By default, capitalization in classnames will add spaces to the display name. You can customize the display name here by uncommenting this line.
Tooltip.SetDefault("This is a 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 = swing + 1;
if (swing > 3)
{
swing = 0;
}
return true;
}
}
}
 

Solo-Ion

Dungeon Spirit
How would I go about increasing the swing style by 1 with every swing, then resetting it after the style = 3? This is the code I have so far, with no luck, any help would be greatly appreciated

using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace testMod.Items
{
public class whyNot : ModItem
{
public int swing;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("chonkSword"); // By default, capitalization in classnames will add spaces to the display name. You can customize the display name here by uncommenting this line.
Tooltip.SetDefault("This is a 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 = swing + 1;
if (swing > 3)
{
swing = 0;
}
return true;
}
}
}
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.
 

Peepachu

Terrarian
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
 

DV Game

Terrarian
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).
 

Peepachu

Terrarian
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
 

DV Game

Terrarian
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...
 

Peepachu

Terrarian
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.
 

DV Game

Terrarian
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
 

Solo-Ion

Dungeon Spirit
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.
 

Argentum

Terrarian
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:

Argentum

Terrarian
@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:

Magistrex2020

Terrarian
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.
 

Argentum

Terrarian
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.
 
Top Bottom