I think can work to you aswell
Well, I had an error here . It said it must return a “Microsoft.Xna.Framework.Vector2?”. Here is my code
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace whatever.Items.weapons
{
public class ShotGunII : ModItem
{
public override void SetDefaults()
{
item.name = "ShotGun-II";
item.damage = 50;
item.ranged = true;
item.width = 40;
item.height = 20;
item.toolTip = "This is a refined shotgun.";
item.useTime = 28;
item.useAnimation = 28;
item.useStyle = 5;
item.noMelee = true; //so the item's animation doesn't do damage
item.knockBack = 7;
item.value = 10000;
item.rare = 2;
item.useSound = 14;
item.autoReuse = false;
item.shoot = 10; //idk why but all the guns in the vanilla source have this
item.shootSpeed = 14f;
item.useAmmo = ProjectileID.Bullet;
item.holdStyle = 1;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.Shotgun ,1);
recipe.AddIngredient(ItemID.IllegalGunParts ,1);
recipe.AddTile(TileID.WorkBenches);
recipe.SetResult(this);
recipe.AddRecipe();
}
public static Vector2[] randomSpread(float speedX, float speedY, int angle, int num)
{
var posArray = new Vector2[num];
float spread = (float)(angle * 0.0174532925);
float baseSpeed = (float)System.Math.Sqrt(speedX * speedX + speedY * speedY);
double baseAngle = System.Math.Atan2(speedX, speedY);
double randomAngle;
for (int i = 0; i < num; ++i)
{
randomAngle = baseAngle + (Main.rand.NextFloat() - 0.5f) * spread;
posArray
= new Vector2(baseSpeed * (float)System.Math.Sin(randomAngle), baseSpeed * (float)System.Math.Cos(randomAngle));
}
return (Vector2[])posArray;
}
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
Vector2[] speeds = randomSpread(speedX,speedY,8,6);
for (int i = 0; i < 5; ++i)
{
Projectile.NewProjectile(position.X, position.Y, speeds.X, speeds.Y, type, damage, knockBack, player.whoAmI);
}
return false;
}
public override void UseStyle(Player player)
{
player.itemLocation.X -= 5f * player.direction;
player.itemLocation.Y += 4f * player.gravDir;
}
public override Vector2 HoldoutOffset()
{
Vector2 offset = new Vector2(8,0);
// 8, 0 is something I just made up on the spot, just experiment with these numbers until you find something that works.
return offset;
}
}
}