ubernovaburst
Terrarian
Uhm i need help with a few things pls.
First thing:
I made a Custom bow wich i want to turn wooden arrows to custom arrows.
Second thing:
I want these Custom Arrows to home enemies.
Third thing:
The Custom bow i made shoots 3 arrows but i want the to shoot .. like .. denser together to eachother .
Heres the Code for my bow:
using Terraria;
using System;
using Terraria.ID;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Terraria.ModLoader;
namespace Pilavius.Items
{
public class MonsterBow : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Monster Bow");
Tooltip.SetDefault("Transforms Wooden arrows in Monster Eyes!");
}
public override void SetDefaults()
{
item.damage = 250;
item.noMelee = true;
item.ranged = true;
item.width = 69;
item.height = 40;
item.useTime = 10;
item.useAnimation = 10;
item.useStyle = 5;
item.shoot = mod.ProjectileType("MonsterEye");
item.knockBack = 5;
item.value = 1000;
item.rare = 9;
item.UseSound = SoundID.Item97;
item.autoReuse = true;
item.shootSpeed = 65f;
}
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
float numberProjectiles = 3; // This defines how many projectiles to shot
float rotation = MathHelper.ToRadians(45);
position += Vector2.Normalize(new Vector2(speedX, speedY)) * 15f; //this defines the distance of the projectiles form the player when the projectile spawns
for (int i = 0; i < numberProjectiles; i++)
{
Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (numberProjectiles - 1))) * .2f; // This defines the projectile roatation and speed. .4f == projectile speed
Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI);
}
return false;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.TitaniumBar, 25);
recipe.AddIngredient(ItemID.DemoniteBar, 50);
recipe.AddIngredient(ItemID.ShadowScale, 20);
recipe.AddTile(TileID.MythrilAnvil);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
Heres the Code for my Arrow:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace Pilavius.Projectiles
{
public class MonsterEye : ModProjectile
{
public override void SetDefaults()
{
projectile.width = 25;
projectile.height = 25;
projectile.aiStyle = 0; //How the projectile works
projectile.tileCollide = true;
projectile.friendly = true;
projectile.penetrate = 3; //this is the projectile penetration
projectile.hostile = false;
projectile.light = 1.00f; // projectile light
projectile.ranged = true; //this make the projectile do magic damage
projectile.tileCollide = true; //this make that the projectile does not go thru walls
projectile.ignoreWater = true;
projectile.light = 0.30f;
projectile.timeLeft = 400;
aiType = 1;
}
public override void AI()
{
for (int i = 0; i < 200; i++)
{
NPC target = Main.npc;
//If the npc is hostile
if (NPC.)
{
//Get the shoot trajectory from the projectile and target
float shootToX = target.position.X + (float)target.width * 0.5f - projectile.Center.X;
float shootToY = target.position.Y - projectile.Center.Y;
float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));
//If the distance between the live targeted npc and the projectile is less than 480 pixels
if (distance < 480f && !target.friendly && target.active)
{
//Divide the factor, 3f, which is the desired velocity
distance = 3f / distance;
//Multiply the distance by a multiplier if you wish the projectile to have go faster
shootToX *= distance * 5;
shootToY *= distance * 5;
//Set the velocities to the shoot values
projectile.velocity.X = shootToX;
projectile.velocity.Y = shootToY;
}
}
}
Lighting.AddLight(projectile.Center, 2.5f, 0.4f, 4.0f);
//this is projectile dust
int DustID27 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y + 1f), projectile.width + 1, projectile.height + 1, mod.DustType("SDust"), projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 55, default(Color), 2.9f);
Main.dust[DustID27].noGravity = true;
//this make that the projectile faces the right way
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
projectile.localAI[0] += 1f;
projectile.alpha = (int)projectile.localAI[0] * 2;
}
}
}
EDIT: Uhm I got the shots "denser" to each other so thats solved. I also got them to home enemies. Now i just wanted to ask if it is possible to adjust the homing, so that it doesnt just instantly flies towards the enemy whenever its sighted but that it makes a curve just like with the specter staff maybe just a bit faster and also if there is some way to make the projectiles attack the parts of the boss wich have lifebars and not just fly inside the middle of the boss AND if its possible to make the projectile only see enemies when there is no wall or tile in between them. And the last problem is the thing with custom bow and arrows still. Thx in advance.
First thing:
I made a Custom bow wich i want to turn wooden arrows to custom arrows.
Second thing:
I want these Custom Arrows to home enemies.
Third thing:
The Custom bow i made shoots 3 arrows but i want the to shoot .. like .. denser together to eachother .
Heres the Code for my bow:
using Terraria;
using System;
using Terraria.ID;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Terraria.ModLoader;
namespace Pilavius.Items
{
public class MonsterBow : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Monster Bow");
Tooltip.SetDefault("Transforms Wooden arrows in Monster Eyes!");
}
public override void SetDefaults()
{
item.damage = 250;
item.noMelee = true;
item.ranged = true;
item.width = 69;
item.height = 40;
item.useTime = 10;
item.useAnimation = 10;
item.useStyle = 5;
item.shoot = mod.ProjectileType("MonsterEye");
item.knockBack = 5;
item.value = 1000;
item.rare = 9;
item.UseSound = SoundID.Item97;
item.autoReuse = true;
item.shootSpeed = 65f;
}
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
float numberProjectiles = 3; // This defines how many projectiles to shot
float rotation = MathHelper.ToRadians(45);
position += Vector2.Normalize(new Vector2(speedX, speedY)) * 15f; //this defines the distance of the projectiles form the player when the projectile spawns
for (int i = 0; i < numberProjectiles; i++)
{
Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (numberProjectiles - 1))) * .2f; // This defines the projectile roatation and speed. .4f == projectile speed
Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI);
}
return false;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.TitaniumBar, 25);
recipe.AddIngredient(ItemID.DemoniteBar, 50);
recipe.AddIngredient(ItemID.ShadowScale, 20);
recipe.AddTile(TileID.MythrilAnvil);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
Heres the Code for my Arrow:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace Pilavius.Projectiles
{
public class MonsterEye : ModProjectile
{
public override void SetDefaults()
{
projectile.width = 25;
projectile.height = 25;
projectile.aiStyle = 0; //How the projectile works
projectile.tileCollide = true;
projectile.friendly = true;
projectile.penetrate = 3; //this is the projectile penetration
projectile.hostile = false;
projectile.light = 1.00f; // projectile light
projectile.ranged = true; //this make the projectile do magic damage
projectile.tileCollide = true; //this make that the projectile does not go thru walls
projectile.ignoreWater = true;
projectile.light = 0.30f;
projectile.timeLeft = 400;
aiType = 1;
}
public override void AI()
{
for (int i = 0; i < 200; i++)
{
NPC target = Main.npc;
//If the npc is hostile
if (NPC.)
{
//Get the shoot trajectory from the projectile and target
float shootToX = target.position.X + (float)target.width * 0.5f - projectile.Center.X;
float shootToY = target.position.Y - projectile.Center.Y;
float distance = (float)System.Math.Sqrt((double)(shootToX * shootToX + shootToY * shootToY));
//If the distance between the live targeted npc and the projectile is less than 480 pixels
if (distance < 480f && !target.friendly && target.active)
{
//Divide the factor, 3f, which is the desired velocity
distance = 3f / distance;
//Multiply the distance by a multiplier if you wish the projectile to have go faster
shootToX *= distance * 5;
shootToY *= distance * 5;
//Set the velocities to the shoot values
projectile.velocity.X = shootToX;
projectile.velocity.Y = shootToY;
}
}
}
Lighting.AddLight(projectile.Center, 2.5f, 0.4f, 4.0f);
//this is projectile dust
int DustID27 = Dust.NewDust(new Vector2(projectile.position.X, projectile.position.Y + 1f), projectile.width + 1, projectile.height + 1, mod.DustType("SDust"), projectile.velocity.X * 0.2f, projectile.velocity.Y * 0.2f, 55, default(Color), 2.9f);
Main.dust[DustID27].noGravity = true;
//this make that the projectile faces the right way
projectile.rotation = (float)Math.Atan2((double)projectile.velocity.Y, (double)projectile.velocity.X) + 1.57f;
projectile.localAI[0] += 1f;
projectile.alpha = (int)projectile.localAI[0] * 2;
}
}
}
EDIT: Uhm I got the shots "denser" to each other so thats solved. I also got them to home enemies. Now i just wanted to ask if it is possible to adjust the homing, so that it doesnt just instantly flies towards the enemy whenever its sighted but that it makes a curve just like with the specter staff maybe just a bit faster and also if there is some way to make the projectiles attack the parts of the boss wich have lifebars and not just fly inside the middle of the boss AND if its possible to make the projectile only see enemies when there is no wall or tile in between them. And the last problem is the thing with custom bow and arrows still. Thx in advance.
Last edited: