I wrote that? I don't even remember. Tell me, how do vanilla exploding weapons work? If you could tell me which weapon you'd like to mimic, I can see how to replicate it. Sorry I don't have time right now, but I should be able to look into this later.So, I'm still having trouble with the explosion problems. Almost gone insane. I need help......Code:public class HellfireKnifeProjectile : ModProjectile { public override void SetDefaults() { projectile.name = "Hellfire Knife"; projectile.alpha = 0; projectile.scale = 1f; projectile.width = 14; projectile.height = 30; projectile.aiStyle = 2; projectile.friendly = true; projectile.penetrate = 1; projectile.timeLeft = 600; projectile.melee = true; projectile.light = 0.2f; projectile.ignoreWater = true; aiType = 48; } public override bool PreAI() { Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1f); if (projectile.timeLeft <= 3) { projectile.tileCollide = false; projectile.ai[1] = 0f; projectile.alpha = 255; projectile.position.X = projectile.position.X + (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2); projectile.width = 80; projectile.height = 80; projectile.position.X = projectile.position.X - (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); projectile.knockBack = 4f; projectile.Damage(); return false; } return true; } private int counter = 1; public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit) { int damageCache = damage; if (counter == 1) { damage = 0; counter--; } else { damage = damageCache; } } public override bool OnTileCollide(Vector2 oldVelocity) { projectile.velocity *= 0f; projectile.alpha = 255; projectile.timeLeft = 3; return false; } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { projectile.velocity *= 0f; projectile.alpha = 255; projectile.timeLeft = 3; } public override void Kill(int timeLeft) { if (!projectile.active) { return; } Main.projectileIdentity[projectile.owner, projectile.identity] = -1; projectile.timeLeft = 0; Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 14); projectile.position.X = projectile.position.X + (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2); projectile.width = 22; projectile.height = 22; projectile.position.X = projectile.position.X - (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); #region visual effect for (int i = 0; i < 7; i++) { Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 1.5f); } for (int i = 0; i < 3; i++) { int d = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 2.5f); Main.dust[d].noGravity = true; Main.dust[d].velocity *= 3f; d = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1.5f); Main.dust[d].velocity *= 2f; } int g = Gore.NewGore(new Vector2(projectile.position.X - 10f, projectile.position.Y - 10f), default(Vector2), Main.rand.Next(61, 64), 1f); Main.gore[g].velocity *= 0.3f; Main.gore[g].velocity.X += (float)Main.rand.Next(-10, 11) * 0.05f; Main.gore[g].velocity.Y += (float)Main.rand.Next(-10, 11) * 0.05f; #endregion projectile.active = false; } }
@jopojelly , when I was wondering around, I found the explosive example you gave long long ago when I first started to make explosive, namely my explosive, which is a duplication of the vanilla explosive bullet. So I duplicate it into my explosive throwing knife and made a little bit revision for my aim. Now two problems occurred:
Thx in advance, since this is really tricky (My problem is always wired).
- In order to prevent it from dealing dual damage to the first target, I figured it out using some if statements. You can see I change the damage to 0 before the first hit and made it normal afterwards. But, it seems the monster will take 1 or 2 damage regardless of the projectile's 0 damage. Will I have any luck to avoid this?
- This is actually the issue driving me crazy. This explosive throwing knife has a super wired bug compared to the "my explosive". When this knife hit on the ground, it worked like a charm, dealt damage to the mobs nearby in a perfectly normal way. But when it directly hit on a mob, it sucks. It will only dealt 1 damage to the mob, and could also cast an explosive effect. However, it wouldn't deal any actual and area damage. It looks sorta like the damage was swallowed... My explosive does not have such a wired problem. Since I duplicated your explosive, I totally got no idea what the hell is going on here. So the best thing I can do is asking for your help.
And here I post "My Explosive" in case that you might wanna see.
Code:public class MyExplosiveProjectile : ModProjectile { public override void SetDefaults() { projectile.name = "My Explosive Projectile"; projectile.CloneDefaults(ProjectileID.ExplosiveBullet); aiType = ProjectileID.Bullet; } public override bool PreAI() { if (projectile.owner == Main.myPlayer && projectile.timeLeft <= 3) { projectile.tileCollide = false; projectile.ai[1] = 0f; projectile.alpha = 255; projectile.position.X = projectile.position.X + (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2); projectile.width = 80; // This is the actual damaging size of this projectile. projectile.height = 80; projectile.position.X = projectile.position.X - (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); projectile.knockBack = 8f; projectile.Damage(); return false; } return true; } public override bool OnTileCollide(Vector2 oldVelocity) { projectile.velocity *= 0f; projectile.alpha = 255; projectile.timeLeft = 3; return false; } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { projectile.velocity *= 0f; projectile.alpha = 255; projectile.timeLeft = 3; } public override void Kill(int timeLeft) { if (!projectile.active) { return; } Main.projectileIdentity[projectile.owner, projectile.identity] = -1; int num = projectile.timeLeft; projectile.timeLeft = 0; Main.PlaySound(2, (int)projectile.position.X, (int)projectile.position.Y, 14); projectile.position.X = projectile.position.X + (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y + (float)(projectile.height / 2); projectile.width = 22; projectile.height = 22; projectile.position.X = projectile.position.X - (float)(projectile.width / 2); projectile.position.Y = projectile.position.Y - (float)(projectile.height / 2); for (int num459 = 0; num459 < 7; num459++) { Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 31, 0f, 0f, 100, default(Color), 1.5f); } for (int num460 = 0; num460 < 3; num460++) { int num461 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 2.5f); Main.dust[num461].noGravity = true; Main.dust[num461].velocity *= 3f; num461 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y), projectile.width, projectile.height, 6, 0f, 0f, 100, default(Color), 1.5f); Main.dust[num461].velocity *= 2f; } int num462 = Gore.NewGore(new Vector2(projectile.position.X - 10f, projectile.position.Y - 10f), default(Vector2), Main.rand.Next(61, 64), 1f); Main.gore[num462].velocity *= 0.3f; Main.gore[num462].velocity.X += (float)Main.rand.Next(-10, 11) * 0.05f; Main.gore[num462].velocity.Y += (float)Main.rand.Next(-10, 11) * 0.05f; projectile.active = false; } }