using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace WondersBlight.Items.Weapons
{
public class Bloomer : ModItem
{
public override void SetDefaults()
{
item.name = "Bloomer";
item.damage = 26;
item.melee = true;
item.width = 80;
item.height = 80;
item.toolTip = "Biomatter makes everything better.";
item.useTime = 40;
item.useAnimation = 45;
item.useStyle = 1;
item.knockBack = 3;
item.value = 10000;
item.rare = 4;
item.UseSound = SoundID.Item1;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.Vine, 10);
recipe.AddIngredient(ItemID.ManaCrystal, 1);
recipe.AddIngredient(ItemID.Stinger, 10);
recipe.AddIngredient(ItemID.JungleSpores, 10);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this);
recipe.AddIngredient("Gloomer");
recipe.AddRecipe();
}
public override void MeleeEffects(Player player, Rectangle hitbox)
{
if (Main.rand.Next(3) == 0)
{
int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, mod.DustType("Sparkle"));
//Emit dusts when swing the sword
}
}
public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit)
{
target.AddBuff(BuffID.Poisned, 60); //Add Onfire buff to the NPC for 1 second
}
}
}
Greeting. I am currently working on a modded weapon that I wish to add particles to. I used the ExampleMod base to see how exactly I do this, but i continuously get the reoccurring error: error CS0246: The type or namespace name 'Rectangle' could not be found (are you missing a using directive or an assembly reference?) Of Course, here's my code. Thanks for any reply!
Code:using System.Collections.Generic; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace WondersBlight.Items.Weapons { public class Bloomer : ModItem { public override void SetDefaults() { item.name = "Bloomer"; item.damage = 26; item.melee = true; item.width = 80; item.height = 80; item.toolTip = "Biomatter makes everything better."; item.useTime = 40; item.useAnimation = 45; item.useStyle = 1; item.knockBack = 3; item.value = 10000; item.rare = 4; item.UseSound = SoundID.Item1; } public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); recipe.AddIngredient(ItemID.Vine, 10); recipe.AddIngredient(ItemID.ManaCrystal, 1); recipe.AddIngredient(ItemID.Stinger, 10); recipe.AddIngredient(ItemID.JungleSpores, 10); recipe.AddTile(TileID.Anvils); recipe.SetResult(this); recipe.AddIngredient("Gloomer"); recipe.AddRecipe(); } public override void MeleeEffects(Player player, Rectangle hitbox) { if (Main.rand.Next(3) == 0) { int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, mod.DustType("Sparkle")); //Emit dusts when swing the sword } } public override void OnHitNPC(Player player, NPC target, int damage, float knockback, bool crit) { target.AddBuff(BuffID.Poisned, 60); //Add Onfire buff to the NPC for 1 second } } }
using Microsoft.Xna.Framework;
I'm not seeing anything, you sure you saved and rebuilt? and that the image is a png file?It says this problem here but there is nothing wrong with the file names
yesI'm not seeing anything, you sure you saved and rebuilt? and that the image is a png file?
Here's a part of a discussion about homing projectiles that hopefully is useful.How do I make falling projectiles (like star wrath) and homing projectiles?
Thank you
You'll probably need to write your own AI then, but I can show you some code snippets to get you started. When I wanted to make a homing projectile of my own, I started by writing a function that iterates through all NPCs to select which one to target.
Then I'd simply need to write "NPC nearestNPC = FindNearest(projectile.Center);" in my AI to find which NPC is nearest to the projectile's center. But recently I looked through the games code, and found the following code snippet.//Find the nearest NPC
public NPC FindNearest(Vector2 pos)
{
NPC nearest = null;
float oldDist = 1001;
float newDist = 1000;
for (int i = 0; i < Terraria.Main.npc.Length - 1; i++) //Do once for each NPC in the world
{
if (Terraria.Main.npc.friendly == true)//Don't target town NPCs
continue;
if (Terraria.Main.npc.active == false)//Don't target dead NPCs
continue;
if (Terraria.Main.npc.damage == 0)//Don't target non-aggressive NPCs
continue;
if (nearest == null) //if no NPCs have made it past the previous few checks
nearest = Terraria.Main.npc; //become the nearest NPC
else
{
oldDist = Vector2.Distance(pos, nearest.position);//Check the distance to the nearest NPC that's earlier in the loop
newDist = Vector2.Distance(pos, Terraria.Main.npc.position);//Check the distance to the current NPC in the loop
if (newDist < oldDist)//If closer than the previous NPC in the loop
nearest = Terraria.Main.npc;//Become the nearest NPC
}
}
return nearest; //return the npc that is nearest to the vector 'pos'
}
This uses NPC.CanBeChasedBy() to exclude any NPC's that you don't want to target and Collision.CanHit() to check if it has line of sight with each NPC, which my function didn't.int num3;
for (int num33 = 0; num33 < 200; num33 = num3 + 1)
{
if (Main.npc[num33].CanBeChasedBy(this, false))
{
float num34 = Main.npc[num33].position.X + (float)(Main.npc[num33].width / 2);
float num35 = Main.npc[num33].position.Y + (float)(Main.npc[num33].height / 2);
float num36 = Math.Abs(this.position.X + (float)(this.width / 2) - num34) + Math.Abs(this.position.Y + (float)(this.height / 2) - num35);
if (num36 < 800f && Collision.CanHit(new Vector2(this.position.X + (float)(this.width / 2), this.position.Y + (float)(this.height / 2)), 1, 1, Main.npc[num33].position, Main.npc[num33].width, Main.npc[num33].height))
{
num31 = num34;
num32 = num35;
flag = true;
}
}
num3 = num33;
}
Once I know which NPC I'm targeting, I like to spawn dust at it's location simply so that I have a visual indication of which NPC is being targeted.
Also, here's some code that makes a projectile home in on the mouse's position. It's not quite self contained, but there's enough there to work with.
None of this code is going to work straight off, it will all need work to suit your needs. But I hope you find it helpful.//mPos = Main.mouseWorld;//get the mouses position in the world
targPos = findTarget(); //Find the thing I want to home in on -- use your target's position instead
toMouse = (float)Math.Atan2(targPos.Y - projectile.position.Y, targPos.X - projectile.position.X); //calculate a bearing to that thing
if (Main.player[projectile.owner].gravDir == -1f) //if my player is upside down
targPos.Y = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY;//reverse the vertical position of my mouse
//accelerate towards my target
projectile.velocity.X += (float)Math.Cos(toMouse) * acel * randVel; //acel is a float that controls how fast the projectile accelerates. randVel is a random modifier to the acceleration.
projectile.velocity.Y += (float)Math.Sin(toMouse) * acel * randVel;
if (Math.Sqrt(projectile.velocity.X * projectile.velocity.X + projectile.velocity.Y * projectile.velocity.Y) > maxSpeed) //if going too fast
{
//Main.NewText("Max!");
projectile.velocity *= 1 - (acel / maxSpeed); //slow down a little bit
}
Edit: huh, looks like spoiler tags aren't the things to put code into.
Thanks a lotHere's a part of a discussion about homing projectiles that hopefully is useful.
Well, no. The bottom spoiler contains code that belongs in a AI hook and requires a function to find what to home in on. The top spoiler contains a function that searches through the NPC array and finds the nearest one to the projectile. This requires some programming understanding to get working.Thanks a lot
So do I simply put that code inside the projectiles.cs?
Well it means it cant find the texture for the pet buff, is the pet buff png named the same as the buff .cs file?can somebody help me?
I want to do a pet, but it fails and this apparears:
Buffs/PetBuff
en Terraria.ModLoader.Mod.GetTexture(String name)
en Terraria.ModLoader.ModLoader.GetTexture(String name)
en Terraria.ModLoader.Mod.SetupContent()
en Terraria.ModLoader.ModLoader.do_Load(Object threadContext)
If the folder is called buff, the namespace should be Buff.PetBuff not Buffs.PetBuff, so check the namespace in the PetBuff.cs-the cs file is :
PetBuff.cs
-and the png is :
PetBuff.png
-Both files are in a folder called Buff
Can you post the code of that file in code tags for easier viewing.Done but now this apparears:
The tile WBName does not exist in the mod YourModName.
If you are trying to use a vanilla tile, try using ModRecipe.AddTile(tileID).
en Terraria.ModLoader.ModRecipe.AddTile(Mod mod, String tileName)
en YourModName.Items.PetCall.AddRecipes() en c:\Users\hp\Documents\My Games\Terraria\ModLoader\Mod Sources\YourModName\Items\PetCall.cs:línea 22
en Terraria.ModLoader.RecipeHooks.AddRecipes()
Sorry if im Bothering to much, but this is my first mod