I need some help with my modded items here

Status
Not open for further replies.

rebuz_ya

Terrarian
This is my first mod and I started working on it a month ago.

1: The weapon should have autoswing on right click

C#:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.GameContent.Creative;
using Microsoft.Xna.Framework;
using RebuzMod.Content.Items.Weapons.Projectiles;

namespace RebuzMod.Content.Items.Weapons.Melee
{
    public class DualAssassin : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Dual Assassin");

            Tooltip.SetDefault("[c/F2C902:Left click to swing crimson side which shoots ichor blades that explode and decrease enemies defense ]\n[c/60F802:Right click to swing corrupted side which shoots cursed swords that pierce up to 3 times and inflict enemies with cursed flames ]");

            CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1;
        }
        public override void SetDefaults()
        {
            Item.DamageType = DamageClass.Melee;
            Item.damage = 90;

            Item.width = 64;
            Item.height = 64;

            Item.useTime = 25;
            Item.useAnimation = 25;
            Item.useStyle = 1;
            Item.knockBack = 5;
            Item.value = 100000;
            Item.rare = 7;
            Item.shoot = ModContent.ProjectileType<IchorBlade>();
            Item.shootSpeed = 15;
            Item.UseSound = SoundID.Item1;
            Item.autoReuse = true;
        }

        public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
        {
            target.AddBuff(BuffID.Ichor, 600);

            if (player.altFunctionUse == 2)
            {
                target.AddBuff(BuffID.CursedInferno, 600);
            } else
            {
                target.AddBuff(BuffID.Ichor, 600);
            }
        }

        public override bool AltFunctionUse(Player player)
        {
            return true;
        }

        public override bool CanUseItem(Player player)
        {
            if (player.altFunctionUse == 2)
            {
                Item.shoot = ModContent.ProjectileType<CursedSword>();
            } else
            {
                Item.shoot = ModContent.ProjectileType<IchorBlade>();
            }
            return true;
        }

        public override void AddRecipes()
        {
            Recipe recipe = CreateRecipe();
            recipe.AddIngredient(ItemID.NightsEdge);
            recipe.AddIngredient(ItemID.CursedFlame, 8);
            recipe.AddIngredient(ItemID.Bladetongue);
            recipe.AddIngredient(ItemID.Ichor, 8);
            recipe.AddIngredient(ItemID.Seedler);
            recipe.AddTile(TileID.MythrilAnvil);
            recipe.Register();
        }

        public override Vector2? HoldoutOffset()
        {
            return new Vector2(-2, -2);
        }

        public override Color? GetAlpha(Color lightColor)
        {
            return Color.White;
        }
    }
}

2. This shield should have the same dash as the solar shield (from the solar armor set bonus) also the icebarrier doesn't really work

C#:
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;
using Terraria.GameContent.Creative;
using Microsoft.Xna.Framework;
using RebuzMod.Content.Tiles.Furniture;

namespace RebuzMod.Content.Items.Accessories
{
    [AutoloadEquip(EquipType.Shield)]
    public class TerraShield : ModItem
    {
        public override void SetStaticDefaults()
        {
            DisplayName.SetDefault("Terra Shield");
            Tooltip.SetDefault("Increases your endurance by 25%\nAllows the player to dash\nDouble tap any direction");

            CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1;
        }

        public override void SetDefaults()
        {
            Item.width = 24;
            Item.height = 28;
            Item.value = 750000;
            Item.rare = 10;
            Item.accessory = true;

            Item.defense = 30;
        }

        public override void UpdateAccessory(Player player, bool hideVisual)
        {
            player.GetModPlayer<TerraDashPlayer>().DashAccessoryEquipped = true;
        }

        public override void AddRecipes()
        {
            Recipe recipe = CreateRecipe();
            recipe.AddIngredient(ItemID.EoCShield);
            recipe.AddIngredient(ItemID.AnkhShield);
            recipe.AddIngredient(ItemID.FrozenShield);
            recipe.AddIngredient(ItemID.HeroShield);
            recipe.AddIngredient(ItemID.FragmentSolar, 10);
            recipe.AddIngredient(ItemID.LunarBar, 5);
            recipe.AddTile(ModContent.TileType<LuminiteAnvil>());
            recipe.Register();
        }

        public override Color? GetAlpha(Color lightColor)
        {
            return Color.White;
        }
    }

    public class TerraDashPlayer : ModPlayer
    {
        public const int DashDown = 0;
        public const int DashUp = 1;
        public const int DashRight = 2;
        public const int DashLeft = 3;

        public const int DashCooldown = 50;
        public const int DashDuration = 40;

        public const float DashVelocity = 12;

        public int DashDir = -1;

        public bool DashAccessoryEquipped;
        public int DashDelay = 0;
        public int DashTimer = 0;

        public override void ResetEffects()
        {
            DashAccessoryEquipped = false;

            if (Player.controlDown && Player.releaseDown && Player.doubleTapCardinalTimer[DashDown] < 15)
            {
                DashDir = DashDown;
            }
            else if (Player.controlUp && Player.releaseUp && Player.doubleTapCardinalTimer[DashUp] < 15)
            {
                DashDir = DashUp;
            }
            else if (Player.controlRight && Player.releaseRight && Player.doubleTapCardinalTimer[DashRight] < 15)
            {
                DashDir = DashRight;
            }
            else if (Player.controlLeft && Player.releaseLeft && Player.doubleTapCardinalTimer[DashLeft] < 15)
            {
                DashDir = DashLeft;
            }
            else
            {
                DashDir = -1;
            }
        }

        public override void PreUpdateMovement()
        {
            if (CanUseDash() && DashDir != -1 && DashDelay == 0)
            {
                Vector2 newVelocity = Player.velocity;

                switch (DashDir)
                {
                    case DashUp when Player.velocity.Y > -DashVelocity:
                    case DashDown when Player.velocity.Y < DashVelocity:
                        {
                            float dashDirection = DashDir == DashDown ? 1.5f : -1.5f;
                            newVelocity.Y = dashDirection * DashVelocity;
                            break;
                        }
                    case DashLeft when Player.velocity.X > -DashVelocity:
                    case DashRight when Player.velocity.X < DashVelocity:
                        {
                            float dashDirection = DashDir == DashRight ? 1.5f : -1.5f;
                            newVelocity.X = dashDirection * DashVelocity;
                            break;
                        }
                    default:
                        return;
                }

                DashDelay = DashCooldown;
                DashTimer = DashDuration;
                Player.velocity = newVelocity / 1.2f;
            }

            if (DashDelay > 0)
                DashDelay--;

            if (DashTimer > 0)
            {
                Player.eocDash = DashTimer;
                Player.armorEffectDrawShadowEOCShield = true;

                DashTimer--;
            }
        }

        private bool CanUseDash()
        {
            return DashAccessoryEquipped
                && Player.dashType == 0
                && !Player.setSolar
                && !Player.mount.Active;
        }
    }
}

thanks for any help, here's the link to my mod.
 
Last edited:
Please use code blocks instead of posting a wall of code lol.

For #1, you have it spawning a wasp projectile rather than a star.
For #4, you left out the knockback parameter completely, and you're using Projectile.owner for knockback instead. Since there's no owner in this case, the projectile won't deal damage.
For #5, you don't specify knockback immunity anywhere.
 
Please use code blocks instead of posting a wall of code lol.

For #1, you have it spawning a wasp projectile rather than a star.
For #4, you left out the knockback parameter completely, and you're using Projectile.owner for knockback instead. Since there's no owner in this case, the projectile won't deal damage.
For #5, you don't specify knockback immunity anywhere.
Thanks for repliying!
In the first case, it actuallly does spawn a wasp projectile, but what i meant was that it actually should spawn both, it's just that i don't know how to make the star properly fall down from the ceiling (just like the star from the holy arrow).
In №4. it actually helped, thanks!
 
Status
Not open for further replies.
Back
Top Bottom