https://github.com/blushiemagic/tModLoader/blob/master/ExampleMod/ExamplePlayer.cs#L139Also, how can i make things spawn in my inventory, like the copper shortsword?
There is a solution for this, it's near the bottom on Page 9. Hope it helps.I'm trying to have my laser shoot from the sky straight down on the mouses location but I can't figure it out and I can't find it on the doc.
Like this, but without the check for the basic bullet since that's what you want: https://github.com/blushiemagic/tModLoader/blob/master/ExampleMod/Items/Weapons/ExampleGun.cs#L54I need help modding a bow and a custom arrow
So I'm trying to code a bow to use all types of arrows but only shoot my custom arrow.
And I'm also not sure where to start when coding the custom arrow.
Any ideas on how to?
Here's the code for the bow:
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace TheLegendOfZelda.Items
.Weapons.Ranged.LightBow
{
public class LightBow : ModItem
}
public override void SetStaticDefaults()
{
DisplayName.SetDefault("The Bow of Light");
Tooltip.SetDefault("The legendary Bow of Light");
}
public override void SetDefaults()
{
item.damage = 100;
item.ranged = true;
item.width = 40;
item.height = 40;
item.useTime = 20;
item.useAnimation = 6;
item.useStyle = 5;
item.noMelee = true;
item.autoReuse = true;
item.knockBack = 6;
item.value = 10000;
item.rare = 2;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
item.shoot = mod.ProjectileType("LightArrow");
item.shootSpeed = 15;
item.useAmmo = AmmoID.Arrow;
}
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(mod,"MasterOre", 20);
recipe.AddIngredient(ItemID.HallowedRepeater);
recipe.AddIngredient(ItemID.Diamond, 25);
recipe.AddIngredient(ItemID.GoldBar, 10);
recipe.AddIngredient(ItemID.PlatinumBar, 10);
recipe.AddTile(TileID.MythrilAnvil);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
BTW I'm new at coding c# (or whatever this coding language is). I've only been doing it for about a week now
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 = 4 + Main.rand.Next(1);
for (int index = 0; index < numberProjectiles; ++index)
{
//This shoot function is almost identical to Star Wrath's, except with 4 projectiles instead of 3.
Vector2 vector2_1 = new Vector2((float)((double)player.position.X + (double)player.width * 0.5 + (double)(Main.rand.Next(100) * -player.direction) + ((double)Main.mouseX + (double)Main.screenPosition.X - (double)player.position.X)), (float)((double)player.position.Y + (double)player.height * 0.5 - 600.0)); //This defines the projectile width, direction and position.
vector2_1.X = (float)(((double)vector2_1.X + (double)player.Center.X) / 2.0) + (float)Main.rand.Next(-100, 100);
vector2_1.Y -= (float)(100 * index);
float num12 = (float)Main.mouseX + Main.screenPosition.X - vector2_1.X;
float num13 = (float)Main.mouseY + Main.screenPosition.Y - vector2_1.Y;
if ((double)num13 < 0.0) num13 *= -1f;
if ((double)num13 < 20.0) num13 = 20f;
float num14 = (float)Math.Sqrt((double)num12 * (double)num12 + (double)num13 * (double)num13);
float num15 = item.shootSpeed / num14;
float num16 = num12 * num15;
float num17 = num13 * num15;
float SpeedX = num16 + (float)Main.rand.Next(-12, 10) * 0.160f; //This defines the projectile X position speed and randomness.
float SpeedY = num17 + (float)Main.rand.Next(-12, 10) * 0.160f; //This defines the projectile Y position speed and randomness.
Projectile.NewProjectile(vector2_1.X, vector2_1.Y, SpeedX * 0.90f, SpeedY * 0.90f, ProjectileID.StarWrath, damage * 1, knockBack, Main.myPlayer, 0.0f, (float)Main.rand.Next(5)); //The "StarWrath" projectile's velocity is the same as the original projectile's speed.
}
return false;
}
using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID; //We are borrowing properties from
using Terraria.ModLoader;
namespace TiborsMod.Items
{
public class akey47 : ModItem
{
public override void SetDefaults()
{
item.name = "A-key 47"; //Its display name
item.damage = 20; //The damage
item.ranged = true; //Whether or not it is a ranged weapon
item.width = 60; //Item width
item.height = 60; //Item height
item.maxStack = 1; //How many of this item you can stack
item.toolTip = "Unlocked and loaded."; //The item’s tooltip
item.useTime = 10; //How long it takes for the item to be used | 1
item.useAnimation = 39; //How long the animation of the item takes | 2
item.knockBack = 7f; //How much knockback the item produces
item.useSound = 12; //The soundeffect played when used
item.noMelee = true; //Whether the weapon should do melee damage or not
item.useStyle = 5; //How the weapon is held, 5 is the gun hold style
item.value = 1; //How much the item is worth
item.rare = 1; //The rarity of the item
item.shoot = mod.ProjectileType("keyproj"); //What the item shoots, retains an int value | 3
item.shootSpeed = 8f; //How fast the projectile fires
item.useAmmo = AmmoID.; //The item ammo ID that it will use
item.autoReuse = true; //Whether it automatically uses the item again after its done being used/animated
}
public override void AddRecipes() //Adding recipes
{
ModRecipe recipe = new ModRecipe(mod); //Creating a new recipe to be added to
recipe.AddIngredient(ItemID.DirtBlock); //Setting the ingredient to the item as a Dirt Block
recipe.SetResult(this); //Set the result of the recipe to this item (this refers to the class itself)
recipe.AddRecipe(); //Add this recipe
}
public class akey47 : GlobalItem
{
public override void SetDefaults(Item item)
{
if (item.type == ItemID.GoldenKey)
{
item.ammo = ItemID.GoldenKey;
item.shoot = mod.ProjectileType("keyproj");
}
// and so on, for SilkRope and WebRope
}
}
}
}
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria;
using Terraria.ModLoader;
namespace TiborsMod.Projectiles //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly
{
public class keyproj : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "keyproj"; //Name of the projectile, only shows this if you get killed by it
projectile.width = 36; //Set the hitbox width
projectile.height = 36; //Set the hitbox height
projectile.timeLeft = 300; //The amount of time the projectile is alive for
projectile.penetrate = 1; //Tells the game how many enemies it can hit before being destroyed
projectile.friendly = true; //Tells the game whether it is friendly to players/friendly npcs or not
projectile.hostile = false; //Tells the game whether it is hostile to players or not
projectile.tileCollide = true; //Tells the game whether or not it can collide with a tile
projectile.ignoreWater = true; //Tells the game whether or not projectile will be affected by water
projectile.ranged = true; //Tells the game whether it is a ranged projectile or not
projectile.aiStyle = 0; //How the projectile works, this is no AI, it just goes a straight path
}
}
}
It is something like:How do I make it so that a custom projectile spawns upon another custom projectile's death? And is there a way to change the overall velocity of the projectile?
Thanks for the reply, but I figured it out before you typed this.It is something like:
public override void Kill()
{
(New projectile code)
}
[doublepost=1521401513,1521401397][/doublepost]I want to know how to make a weapon spawn a projectile that is a set distance away from the player, as well as 90 degrees from the degrees relation of the player and mouse pointer
Lol, i figured that out myself too.Thanks for the reply, but I figured it out before you typed this.
Also, I don't the answer to your question, since I'm not very experienced, sorry. ^^;
Btw, how does one create a Shadowflame Hex Doll-like projectile?