Someone that needs help
Torch God
Meme face
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 thisI'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.
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
}
}
}
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
}
}
}
IDK if be real, but here is the first way:
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 = 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 } } }
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).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 } } }
sure. but the first 3 styles are normal for swords I think...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
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.sure. but the first 3 styles are normal for swords I think...
I know by the way. So, your sword was probably just fun thing so it is more like test thingThey 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.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.