MaloLeNono
Terrarian
Hello, I'm trying to create a drill for a mod that me and my friends would use. Here's the main drill script and the drill projectile script:
As stated in the title, no matter what use time or use animation I use for this, it will always be the fasted that it can be. This is based off of the tModLoader 1.4.4 example mod. I just started making mods for terraria and for pickaxes I can change the use time and it'll change fine. In game, if I set the use time to say 999, it does say that the drill has "Snail speed", but it's still incredibly fast. Also, whenever The projectile touches a tile but my mouse isn't hovering over the tile, it glitches out and plays the drill sound like a billion times a second. Any help?
C#:
using ModDeTchass.Content.Items.Materials;
using ModDeTchass.Content.Projectiles;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace ModDeTchass.Content.Items.Drills
{
class DrillDeTchass : ModItem
{
public override void SetStaticDefaults()
{
ItemID.Sets.IsDrill[Type] = true;
}
public override void SetDefaults()
{
Item.width = 50;
Item.height = 18;
Item.damage = 60;
Item.DamageType = DamageClass.MeleeNoSpeed;
Item.knockBack = 0.5f;
Item.useTime = 20;
Item.useAnimation = 20;
Item.useStyle = ItemUseStyleID.Shoot;
Item.value = Item.buyPrice(gold: 1);
Item.UseSound = SoundID.Item23;
Item.shoot = ModContent.ProjectileType<DrillDeTchassProjectile>();
Item.shootSpeed = 32f;
Item.noMelee = true;
Item.noUseGraphic = true;
Item.channel = true;
Item.tileBoost = 5;
Item.pick = 1;
}
public override void AddRecipes()
{
CreateRecipe()
.AddIngredient<BouffeDeTchass>(20)
.AddTile(TileID.Anvils)
.Register();
}
}
}
C#:
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria.Audio;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace ModDeTchass.Content.Projectiles
{
class DrillDeTchassProjectile : ModProjectile
{
public override void SetStaticDefaults()
{
ProjectileID.Sets.HeldProjDoesNotUsePlayerGfxOffY[Type] = true;
}
public override void SetDefaults()
{
Projectile.width = 22;
Projectile.height = 22;
Projectile.friendly = true;
Projectile.tileCollide = true;
Projectile.penetrate = -1;
Projectile.DamageType = DamageClass.Melee;
Projectile.ownerHitCheck = true;
Projectile.aiStyle = -1;
Projectile.hide = true;
}
public override void AI()
{
Player player = Main.player[Projectile.owner];
Projectile.timeLeft = 60;
if (Projectile.soundDelay <= 0)
{
SoundEngine.PlaySound(SoundID.Item22, Projectile.Center);
Projectile.soundDelay = 20;
}
Vector2 playerCenter = player.RotatedRelativePoint(player.MountedCenter);
if (Main.myPlayer == Projectile.owner)
{
if (player.channel)
{
float holdoutDistance = player.HeldItem.shootSpeed * Projectile.scale;
Vector2 holdoutOffset = holdoutDistance * Vector2.Normalize(Main.MouseWorld - playerCenter);
if (holdoutOffset.X != Projectile.velocity.X || holdoutOffset.Y != Projectile.velocity.Y)
{
Projectile.netUpdate = true;
}
Projectile.velocity = holdoutOffset;
}
else
{
Projectile.Kill();
}
}
if (Projectile.velocity.X > 0f)
{
player.ChangeDir(1);
}
else if (Projectile.velocity.X < 0f)
{
player.ChangeDir(-1);
}
Projectile.spriteDirection = Projectile.direction;
player.ChangeDir(Projectile.direction);
player.heldProj = Projectile.whoAmI;
player.SetDummyItemTime(2);
Projectile.Center = playerCenter;
Projectile.rotation = Projectile.velocity.ToRotation() + MathHelper.PiOver2;
player.itemRotation = (Projectile.velocity * Projectile.direction).ToRotation();
Projectile.velocity.X *= 1f + Main.rand.Next(-3, 4) * 0.01f;
if (Main.rand.NextBool(10))
{
Dust dust = Dust.NewDustDirect(Projectile.position + Projectile.velocity * Main.rand.Next(6, 10) * 0.15f, Projectile.width, Projectile.height, DustID.Dirt, 0f, 0f, 80, Color.White, 1f);
dust.position.X -= 4f;
dust.noGravity = true;
dust.velocity.X *= 0.5f;
dust.velocity.Y = -Main.rand.Next(3, 8) * 0.1f;
}
}
}
}
As stated in the title, no matter what use time or use animation I use for this, it will always be the fasted that it can be. This is based off of the tModLoader 1.4.4 example mod. I just started making mods for terraria and for pickaxes I can change the use time and it'll change fine. In game, if I set the use time to say 999, it does say that the drill has "Snail speed", but it's still incredibly fast. Also, whenever The projectile touches a tile but my mouse isn't hovering over the tile, it glitches out and plays the drill sound like a billion times a second. Any help?