kayll2660
Terrarian
i try so many codes but nun work
here is my code for the debuff
and here is thed code for the projecile
here is my code for the debuff
Code:
using Terraria.ModLoader;
using Terraria;
using Terraria.DataStructures;
using Terraria.ID;
using funnyswordman.Dusts;
namespace funnyswordman.Debuff
{
public class HATEFlamesDebuff : ModBuff
{
public override void SetDefaults()
{
DisplayName.SetDefault("HATE Flames");
Description.SetDefault("Your soul is dying...");
Main.debuff[Type] = true;
Main.pvpBuff[Type] = true;
Main.buffNoSave[Type] = true;
longerExpertDebuff = true;
}
public override void Update(Player player, ref int buffIndex)
{
player.GetModPlayer<HATEFlamesDebuffPlayer>().HATEFlames = true;
int d = Dust.NewDust(player.position, player.width, player.height, ModContent.DustType<HATEDust>(), 0, 0, 0, default, 2);
Main.dust[d].noGravity = true;
}
public override void Update(NPC npc, ref int buffIndex)
{
npc.GetGlobalNPC<HATEFlamesDebuffNPC>().HATEFlames = true;
int d = Dust.NewDust(npc.position, npc.width, npc.height, ModContent.DustType<HATEDust>(), 0, 0, 0, default, 2);
Main.dust[d].noGravity = true;
}
}
public class HATEFlamesDebuffPlayer : ModPlayer
{
public bool HATEFlames;
public override void ResetEffects()
{
HATEFlames = false;
}
public override void UpdateBadLifeRegen()
{
if (HATEFlames)
{
if (player.lifeRegen > 0)
{
player.lifeRegen = 0;
}
player.lifeRegenTime = 0;
player.lifeRegen -= 50;
}
}
public override bool PreKill(double damage, int hitDirection, bool pvp, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource)
{
if (HATEFlames)
{
damageSource = PlayerDeathReason.ByCustomReason(player.name + " disintegrated.");
}
return true;
}
}
public class HATEFlamesDebuffNPC : GlobalNPC
{
public override bool InstancePerEntity => true;
public bool HATEFlames;
public override void ResetEffects(NPC npc)
{
HATEFlames = false;
}
public override void UpdateLifeRegen(NPC npc, ref int damage)
{
if (HATEFlames)
{
if (npc.lifeRegen > 0)
{
npc.lifeRegen = 0;
}
npc.lifeRegen -= 50;
if (damage < 1)
{
damage = 1;
}
}
}
}
}
and here is thed code for the projecile
Code:
sing System; //what sources the code uses, these sources allow for calling of terraria functions, existing system functions and microsoft vector functions (probably more)
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using funnyswordman.Debuff;
namespace funnyswordman.Projectiles //where it's stored. Replace Mod with the name of your mod. This file is stored in the folder \Mod Sources\(mod name, folder can't have spaces)\Projectiles.
{
public class TrueSlash : ModProjectile //the class of the projectile
{
public override void SetDefaults()
{
projectile.width = 25; //sprite is 2 pixels wide
projectile.height = 25; //sprite is 20 pixels tall
projectile.aiStyle = 0; //projectile moves in a straight line
projectile.friendly = true; //player projectile
projectile.ranged = true; //ranged projectile
projectile.timeLeft = 600; //lasts for 600 frames/ticks. Terraria runs at 60FPS, so it lasts 10 seconds.
aiType = ProjectileID.Bullet; //This clones the exact AI of the vanilla projectile Bullet.
drawOffsetX = -30;
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
target.AddBuff(mod.BuffType("HATEFlames"), 240);
}
public override void AI()
{
projectile.rotation = projectile.spriteDirection = projectile.direction;
projectile.rotation = projectile.velocity.ToRotation() + MathHelper.ToRadians(90f);
Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 191, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f); //spawns dust behind it, this is a spectral light blue dust
float num132 = (float)Math.Sqrt((double)(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y));
float num133 = projectile.localAI[0];
if (num133 == 0f)
{
projectile.localAI[0] = num132;
num133 = num132;
}
float num134 = projectile.position.X;
float num135 = projectile.position.Y;
float num136 = 300f;
bool flag3 = false;
int num137 = 0;
if (projectile.ai[1] == 0f)
{
for (int num138 = 0; num138 < 200; num138++)
{
if (Main.npc[num138].CanBeChasedBy(this, false) && (projectile.ai[1] == 0f || projectile.ai[1] == (float)(num138 + 1)))
{
float num139 = Main.npc[num138].position.X + (float)(Main.npc[num138].width / 2);
float num140 = Main.npc[num138].position.Y + (float)(Main.npc[num138].height / 2);
float num141 = Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num139) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num140);
if (num141 < num136 && Collision.CanHit(new Vector2(projectile.position.X + (float)(projectile.width / 2), projectile.position.Y + (float)(projectile.height / 2)), 1, 1, Main.npc[num138].position, Main.npc[num138].width, Main.npc[num138].height))
{
num136 = num141;
num134 = num139;
num135 = num140;
flag3 = true;
num137 = num138;
}
}
}
if (flag3)
{
projectile.ai[1] = (float)(num137 + 1);
}
flag3 = false;
}
if (projectile.ai[1] > 0f)
{
int num142 = (int)(projectile.ai[1] - 1f);
if (Main.npc[num142].active && Main.npc[num142].CanBeChasedBy(this, true) && !Main.npc[num142].dontTakeDamage)
{
float num143 = Main.npc[num142].position.X + (float)(Main.npc[num142].width / 2);
float num144 = Main.npc[num142].position.Y + (float)(Main.npc[num142].height / 2);
if (Math.Abs(projectile.position.X + (float)(projectile.width / 2) - num143) + Math.Abs(projectile.position.Y + (float)(projectile.height / 2) - num144) < 1000f)
{
flag3 = true;
num134 = Main.npc[num142].position.X + (float)(Main.npc[num142].width / 2);
num135 = Main.npc[num142].position.Y + (float)(Main.npc[num142].height / 2);
}
}
else
{
projectile.ai[1] = 0f;
}
}
if (!projectile.friendly)
{
flag3 = false;
}
if (flag3)
{
float num145 = num133;
Vector2 vector10 = new Vector2(projectile.position.X + (float)projectile.width * 0.5f, projectile.position.Y + (float)projectile.height * 0.5f);
float num146 = num134 - vector10.X;
float num147 = num135 - vector10.Y;
float num148 = (float)Math.Sqrt((double)(num146 * num146 + num147 * num147));
num148 = num145 / num148;
num146 *= num148;
num147 *= num148;
int num149 = 8;
projectile.velocity.X = (projectile.velocity.X * (float)(num149 - 1) + num146) / (float)num149;
projectile.velocity.Y = (projectile.velocity.Y * (float)(num149 - 1) + num147) / (float)num149;
}
}
public override void Kill(int timeLeft)
{
Collision.HitTiles(projectile.position, projectile.velocity, projectile.width, projectile.height);
Main.PlaySound(SoundID.Item10, projectile.position);
}
}
}