HummeL777
Steampunker
Last night, while creating a gun, I had a request to make a bow. But in ExampleMod I did not have a layout of a bow or arrows. Could you tell me how to remake the code?
Code of rifle:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace GlobalOffensive.Items.Weapons.Range
{
public class Rifle : ModItem
{
public override void SetDefaults()
{
item.name = "Hunter rifle";
item.damage = 25;
item.ranged = true;
item.width = 45;
item.height = 9;
item.toolTip = "This is a modded gun.";
item.useTime = 30;
item.useAnimation = 30;
item.useStyle = 5;
item.noMelee = true; //so the item's animation doesn't do damage
item.knockBack = 4;
item.value = 10000;
item.rare = 2;
item.UseSound = SoundID.Item11;
item.autoReuse = true;
item.shoot = mod.ProjectileType("CopperBullet");
item.shootSpeed = 6f;
item.useAmmo = mod.ItemType("CopperBullet");
item.scale = 1.5f;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DynastyWood, 5);
recipe.AddIngredient(ItemID.IronBar, 10);
recipe.AddIngredient(ItemID.Leather, 3);
recipe.AddIngredient(ItemID.GrayPressurePlate, 1);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this);
recipe.AddRecipe();
}
public override Vector2? HoldoutOffset()
{
return new Vector2(-8, 0);
}
}
}
Code of Bullets(Item):
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace GlobalOffensive.Items.Weapons.Range.Ammo
{
public class CopperBullet : ModItem
{
public override void SetDefaults()
{
item.name = "Hunter Bullet";
item.damage = 6;
item.ranged = true;
item.width = 1;
item.height = 1;
item.maxStack = 999;
item.toolTip = "This is a modded bullet ammo.";
item.consumable = true; //You need to set the item consumable so that the ammo would automatically consumed
item.knockBack = 1.5f;
item.value = 10;
item.rare = 2;
item.shoot = mod.ProjectileType("CopperBullet"); //The projectile shoot when your weapon using this ammo
item.shootSpeed = 12f; //The speed of the projectile
item.ammo = item.type; //The ammo class this ammo belongs to.
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this, 50);
recipe.AddRecipe();
}
}
}
Code of Bullets(Projectile):
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace GlobalOffensive.Projectile
{
public class CopperBullet : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "CopperBullet";
projectile.width = 8;
projectile.height = 8;
projectile.aiStyle = 1;
projectile.friendly = true;
projectile.hostile = false;
projectile.ranged = true;
projectile.penetrate = 1;
projectile.timeLeft = 600;
projectile.alpha = 255;
projectile.light = 0f;
projectile.ignoreWater = true;
projectile.tileCollide = true;
projectile.extraUpdates = 1;
ProjectileID.Sets.TrailCacheLength[projectile.type] = 5;
ProjectileID.Sets.TrailingMode[projectile.type] = 0;
aiType = ProjectileID.Bullet;
}
public override bool OnTileCollide(Vector2 oldVelocity)
{
//If collide with tile, reduce the penetrate.
//So the projectile can reflect at most 5 times
projectile.penetrate--;
if (projectile.penetrate <= 0)
{
projectile.Kill();
}
else
{
if (projectile.velocity.X != oldVelocity.X)
{
projectile.velocity.X = -oldVelocity.X;
}
if (projectile.velocity.Y != oldVelocity.Y)
{
projectile.velocity.Y = -oldVelocity.Y;
}
Main.PlaySound(SoundID.Item10, projectile.position);
}
return false;
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Vector2 drawOrigin = new Vector2(Main.projectileTexture[projectile.type].Width * 0.5f, projectile.height * 0.5f);
for (int k = 0; k < projectile.oldPos.Length; k++)
{
Vector2 drawPos = projectile.oldPos[k] - Main.screenPosition + drawOrigin + new Vector2(0f, projectile.gfxOffY);
Color color = projectile.GetAlpha(lightColor) * ((float)(projectile.oldPos.Length - k) / (float)projectile.oldPos.Length);
spriteBatch.Draw(Main.projectileTexture[projectile.type], drawPos, null, color, projectile.rotation, drawOrigin, projectile.scale, SpriteEffects.None, 0f);
}
return true;
}
}
Code of rifle:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace GlobalOffensive.Items.Weapons.Range
{
public class Rifle : ModItem
{
public override void SetDefaults()
{
item.name = "Hunter rifle";
item.damage = 25;
item.ranged = true;
item.width = 45;
item.height = 9;
item.toolTip = "This is a modded gun.";
item.useTime = 30;
item.useAnimation = 30;
item.useStyle = 5;
item.noMelee = true; //so the item's animation doesn't do damage
item.knockBack = 4;
item.value = 10000;
item.rare = 2;
item.UseSound = SoundID.Item11;
item.autoReuse = true;
item.shoot = mod.ProjectileType("CopperBullet");
item.shootSpeed = 6f;
item.useAmmo = mod.ItemType("CopperBullet");
item.scale = 1.5f;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DynastyWood, 5);
recipe.AddIngredient(ItemID.IronBar, 10);
recipe.AddIngredient(ItemID.Leather, 3);
recipe.AddIngredient(ItemID.GrayPressurePlate, 1);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this);
recipe.AddRecipe();
}
public override Vector2? HoldoutOffset()
{
return new Vector2(-8, 0);
}
}
}
Code of Bullets(Item):
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace GlobalOffensive.Items.Weapons.Range.Ammo
{
public class CopperBullet : ModItem
{
public override void SetDefaults()
{
item.name = "Hunter Bullet";
item.damage = 6;
item.ranged = true;
item.width = 1;
item.height = 1;
item.maxStack = 999;
item.toolTip = "This is a modded bullet ammo.";
item.consumable = true; //You need to set the item consumable so that the ammo would automatically consumed
item.knockBack = 1.5f;
item.value = 10;
item.rare = 2;
item.shoot = mod.ProjectileType("CopperBullet"); //The projectile shoot when your weapon using this ammo
item.shootSpeed = 12f; //The speed of the projectile
item.ammo = item.type; //The ammo class this ammo belongs to.
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock, 1);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this, 50);
recipe.AddRecipe();
}
}
}
Code of Bullets(Projectile):
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace GlobalOffensive.Projectile
{
public class CopperBullet : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "CopperBullet";
projectile.width = 8;
projectile.height = 8;
projectile.aiStyle = 1;
projectile.friendly = true;
projectile.hostile = false;
projectile.ranged = true;
projectile.penetrate = 1;
projectile.timeLeft = 600;
projectile.alpha = 255;
projectile.light = 0f;
projectile.ignoreWater = true;
projectile.tileCollide = true;
projectile.extraUpdates = 1;
ProjectileID.Sets.TrailCacheLength[projectile.type] = 5;
ProjectileID.Sets.TrailingMode[projectile.type] = 0;
aiType = ProjectileID.Bullet;
}
public override bool OnTileCollide(Vector2 oldVelocity)
{
//If collide with tile, reduce the penetrate.
//So the projectile can reflect at most 5 times
projectile.penetrate--;
if (projectile.penetrate <= 0)
{
projectile.Kill();
}
else
{
if (projectile.velocity.X != oldVelocity.X)
{
projectile.velocity.X = -oldVelocity.X;
}
if (projectile.velocity.Y != oldVelocity.Y)
{
projectile.velocity.Y = -oldVelocity.Y;
}
Main.PlaySound(SoundID.Item10, projectile.position);
}
return false;
}
public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor)
{
Vector2 drawOrigin = new Vector2(Main.projectileTexture[projectile.type].Width * 0.5f, projectile.height * 0.5f);
for (int k = 0; k < projectile.oldPos.Length; k++)
{
Vector2 drawPos = projectile.oldPos[k] - Main.screenPosition + drawOrigin + new Vector2(0f, projectile.gfxOffY);
Color color = projectile.GetAlpha(lightColor) * ((float)(projectile.oldPos.Length - k) / (float)projectile.oldPos.Length);
spriteBatch.Draw(Main.projectileTexture[projectile.type], drawPos, null, color, projectile.rotation, drawOrigin, projectile.scale, SpriteEffects.None, 0f);
}
return true;
}
}