chelllovec
Terrarian
(translate by Google Translate)
I decided to create a projectile that creates projectiles, but I ran into the error indicated in the name. Here is the code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;
using System;
using static Terraria.DataStructures.IEntitySource;
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RandomParashaMod.Content.Projectile;
namespace RandomParashaMod.Content.Projectile
{
// This is a basic item template.
// Please see tModLoader's ExampleMod for every other example:
// tModLoader/ExampleMod at stable · tModLoader/tModLoader
public class MultipleArrowProjectile : ModProjectile
{
// The Display Name and Tooltip of this item can be edited in the 'Localization/en-US_Mods.RandomParashaMod.hjson' file.
public override void SetStaticDefaults()
{
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 5; // The length of old position to be recorded
ProjectileID.Sets.TrailingMode[Projectile.type] = 0; // The recording mode
}
public override void SetDefaults()
{
Projectile.width = 10; // The width of projectile hitbox
Projectile.height = 28; // The height of projectile hitbox
Projectile.aiStyle = ProjAIStyleID.Arrow;
Projectile.arrow = true;
Projectile.friendly = true; // Can the projectile deal damage to enemies?
Projectile.hostile = false; // Can the projectile deal damage to the player?
Projectile.DamageType = DamageClass.Ranged; // Is the projectile shoot by a ranged weapon?
Projectile.penetrate = 1; // How many monsters the projectile can penetrate. (OnTileCollide below also decrements penetrate for bounces as well)
Projectile.timeLeft = 120; // The live time for the projectile (60 = 1 second, so 600 is 10 seconds)
Projectile.alpha = 0;
Projectile.ignoreWater = false; // Does the projectile's speed be influenced by water?
Projectile.tileCollide = true; // Can the projectile collide with tiles?
}
public override void AI()
{
if (Projectile.timeLeft <= 80)
{
if (Projectile.owner == Main.myPlayer)
{
for (int i = 0; i < 2; i++)
{
float angle = 15 - 30 * i;
float radians = ((float)Math.Atan2(Projectile.velocity.Y, Projectile.velocity.X)) + MathHelper.ToRadians(angle);
float newSpeedX = (float)Math.Cos(radians) * Projectile.velocity.X;
float newSpeedY = (float)Math.Sin(radians) * Projectile.velocity.Y;
Vector2 Speed = new Vector2(newSpeedX, newSpeedY);
Projectile.NewProjectile
(Projectile.GetSource_FromThis(),
Projectile.Center,
Speed,
Projectile.type,
Projectile.originalDamage,
Projectile.knockBack,
Projectile.owner);
}
}
Projectile.Kill();
}
}
}
}
I decided to create a projectile that creates projectiles, but I ran into the error indicated in the name. Here is the code:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.DataStructures;
using System;
using static Terraria.DataStructures.IEntitySource;
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RandomParashaMod.Content.Projectile;
namespace RandomParashaMod.Content.Projectile
{
// This is a basic item template.
// Please see tModLoader's ExampleMod for every other example:
// tModLoader/ExampleMod at stable · tModLoader/tModLoader
public class MultipleArrowProjectile : ModProjectile
{
// The Display Name and Tooltip of this item can be edited in the 'Localization/en-US_Mods.RandomParashaMod.hjson' file.
public override void SetStaticDefaults()
{
ProjectileID.Sets.TrailCacheLength[Projectile.type] = 5; // The length of old position to be recorded
ProjectileID.Sets.TrailingMode[Projectile.type] = 0; // The recording mode
}
public override void SetDefaults()
{
Projectile.width = 10; // The width of projectile hitbox
Projectile.height = 28; // The height of projectile hitbox
Projectile.aiStyle = ProjAIStyleID.Arrow;
Projectile.arrow = true;
Projectile.friendly = true; // Can the projectile deal damage to enemies?
Projectile.hostile = false; // Can the projectile deal damage to the player?
Projectile.DamageType = DamageClass.Ranged; // Is the projectile shoot by a ranged weapon?
Projectile.penetrate = 1; // How many monsters the projectile can penetrate. (OnTileCollide below also decrements penetrate for bounces as well)
Projectile.timeLeft = 120; // The live time for the projectile (60 = 1 second, so 600 is 10 seconds)
Projectile.alpha = 0;
Projectile.ignoreWater = false; // Does the projectile's speed be influenced by water?
Projectile.tileCollide = true; // Can the projectile collide with tiles?
}
public override void AI()
{
if (Projectile.timeLeft <= 80)
{
if (Projectile.owner == Main.myPlayer)
{
for (int i = 0; i < 2; i++)
{
float angle = 15 - 30 * i;
float radians = ((float)Math.Atan2(Projectile.velocity.Y, Projectile.velocity.X)) + MathHelper.ToRadians(angle);
float newSpeedX = (float)Math.Cos(radians) * Projectile.velocity.X;
float newSpeedY = (float)Math.Sin(radians) * Projectile.velocity.Y;
Vector2 Speed = new Vector2(newSpeedX, newSpeedY);
Projectile.NewProjectile
(Projectile.GetSource_FromThis(),
Projectile.Center,
Speed,
Projectile.type,
Projectile.originalDamage,
Projectile.knockBack,
Projectile.owner);
}
}
Projectile.Kill();
}
}
}
}