tModLoader Question, how can you make shotguns shoot two different projectiles, and can it work for other items. (1.3 tModloader)

Gilded Wyvern

Terrarian
Hi, I'm a new member and newbie mod developer and I need some help for some code. Whenever I use this code it just shoots 2 of the specified projectiles without spreading them out at all. Any reason why it may be so?
I'll post the code here V (This is for a magic gun)

using Microsoft.Xna.Framework;
using MOR.Items.Weapons.Magic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace MOR.Items.Weapons.Magic
{
public class OrbitalBlaster : ModItem
{
public override void SetStaticDefaults()
{
Tooltip.SetDefault("'Ka-Plewm'");

}
public override void SetDefaults()
{
item.damage = 50;
item.magic = true;
item.mana = 10;
item.width = 52;
item.height = 20;
item.useTime = 12;
item.useAnimation = 12;
item.useStyle = ItemUseStyleID.HoldingOut;
item.noMelee = true; //so the item's animation doesn't do damage
item.knockBack = 6f;
item.value = Item.sellPrice(gold: 9);
item.rare = ItemRarityID.Pink;
item.UseSound = SoundID.Item12;
item.autoReuse = true;
item.shoot = ProjectileID.PurpleLaser;
item.shootSpeed = 16f;
}

public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
int numberProjectiles = 3 + Main.rand.Next(4); // 4 or 5 shots
for (int i = 0; i < numberProjectiles; i++)
{
Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedByRandom(MathHelper.ToRadians(30)); // 30 degree spread. // If you want to randomize the speed to stagger the projectiles
float scale = 1f - (Main.rand.NextFloat() * .6f);
perturbedSpeed = perturbedSpeed * scale;
Projectile.NewProjectile(position.X, position.Y, perturbedSpeed.X, perturbedSpeed.Y, type, damage, knockBack, player.whoAmI);
}
return false;
{
Vector2 muzzleOffset = Vector2.Normalize(new Vector2(speedX, speedY)) * -1000f;
if (Collision.CanHit(position, 0, 0, position + muzzleOffset, 0, 0))
{
position += muzzleOffset;
}
return true;
}
} // return false because we don't want tmodloader to shoot projectile
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.Shotgun);
recipe.AddIngredient(ItemID.LaserRifle);
recipe.AddIngredient(ModContent.ItemType<Lazerstick>());
recipe.AddTile(TileID.MythrilAnvil);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
Please help? Thank you very much
- Gilded Wyvern
 
First, please put your code into a code block. It makes it much easier to read. To do this on the the forums, click the three dots then choose code (looks like </>).

I think you have the
Code:
{
Vector2 muzzleOffset = Vector2.Normalize(new Vector2(speedX, speedY)) * -1000f;
if (Collision.CanHit(position, 0, 0, position + muzzleOffset, 0, 0))
{
position += muzzleOffset;
}
return true;
}
in the wrong spot. Take a look at tModLoader/ExampleGun.cs at master · tModLoader/tModLoader again.
 
First, please put your code into a code block. It makes it much easier to read. To do this on the the forums, click the three dots then choose code (looks like </>).

I think you have the
Code:
{
Vector2 muzzleOffset = Vector2.Normalize(new Vector2(speedX, speedY)) * -1000f;
if (Collision.CanHit(position, 0, 0, position + muzzleOffset, 0, 0))
{
position += muzzleOffset;
}
return true;
}
in the wrong spot. Take a look at tModLoader/ExampleGun.cs at master · tModLoader/tModLoader again.
Awesome! Thank you so much, by the way how did you get those special images under your message?
 
Great

I tried your suggestion, and checked the Example Gun and it doesn't seem to specify where to put it. Thank you for trying to help but it didn't work. Have a nice day.

ExampleGun has code blocks for both shooting multiple projectiles of the same type, and shooting 2 different projectiles at the same time. While the code is commented out, you can uncomment it and it'll work just fine where it is.
 
Back
Top Bottom