using System;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
namespace Cyclogenesis.Items {
public class Scythe : ModItem
{
public override void SetDefaults()
{
item.name = "Cyclogenesis Scythe";
item.damage = 100;
item.magic = true;
item.width = 60;
item.height = 56;
item.toolTip = "Shoots scythes, may deal inaccurate damage.";
item.toolTip2 = "Increases damage the more armor you have.";
item.useTime = 45;
item.useAnimation = 45;
item.useStyle = 1;
item.knockBack = 2;
item.value = 0;
item.rare = 10;
item.useSound = 1;
item.autoReuse = true;
item.mana = 14;
item.useSound = 8;
item.shoot = 45;
item.shootSpeed = 1f;
}
public override void MeleeEffects(Player player, Rectangle hitbox)
{
int dust = Dust.NewDust(new Vector2((float)hitbox.X, (float)hitbox.Y), hitbox.Width, hitbox.Height, 27, player.velocity.X * 0.2f + (float)(player.direction * 3), player.velocity.Y * 0.2f, 100, default(Color), 1.75f);
Main.dust[dust].noGravity = true;
Main.dust[dust].velocity *= 1.66f;
var FrontLightPos = new Vector2((float)player.position.X + 55, (float)player.position.Y);
var BackLightPos = new Vector2((float)player.position.X - 55, (float)player.position.Y);
Lighting.AddLight(FrontLightPos, 0.75f, 0f, 0f);
Lighting.AddLight(BackLightPos, 0f, 0f, 0.75f);
}
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 damageCalculation = (int)((item.damage * 0.8) / 2) * Main.rand.Next(3);
int armorIncrement = (int)(player.statDefense * 1.33);
float spread = 45f * 0.0174f;
double startAngle = Math.Atan2(speedX, speedY)- spread/2;
double deltaAngle = spread/8f;
double offsetAngle;
Vector2 pos = GetPos(player);
for (int i = 0; i < 4; i++ )
{
offsetAngle = (startAngle + deltaAngle * (i + i*i) / 2f) + 32f * i;
Projectile.NewProjectile((int)(pos.X), (int)(pos.Y), (float)(Math.Sin(offsetAngle) * 2f), (float)(Math.Cos(offsetAngle) * 2f), 45, damageCalculation + armorIncrement, knockBack, item.owner);
Projectile.NewProjectile((int)(pos.X), (int)(pos.Y), (float)(-Math.Sin(offsetAngle) * 2f), (float)(-Math.Cos(offsetAngle) * 3f), 45, damageCalculation + armorIncrement, knockBack, item.owner);
//Projectile.NewProjectile(position.X, position.Y, (float)(Math.Sin(offsetAngle) * 5f), (float)(Math.Cos(offsetAngle) * 5f), 263, damage, knockBack, item.owner);
//Projectile.NewProjectile(position.X, position.Y, (float)(-Math.Sin(offsetAngle) * 5f), (float)(-Math.Cos(offsetAngle) * 5f), 263, damage, knockBack, item.owner);
}
return false;
}
static float NextFloat(Random random)
{
double mantissa = (random.NextDouble() * 2.0) - 1.0;
double exponent = Math.Pow(2.0, random.Next(-126, 128));
return (float)(mantissa * exponent);
}
public override void Update(ref float gravity, ref float maxFallSpeed)
{
Lighting.AddLight(item.position, 1f, 0.25f, 1f);
}
private Vector2 GetPos(Player player)
{
Vector2 position = Main.screenPosition;
position.X += Main.mouseX;
position.Y += player.gravDir == 1 ? Main.mouseY : Main.screenHeight - Main.mouseY;
return position;
}
}
}
For the range problem, first you could try calculating the offset between the mouse and the player as a Vector2. Vector2 structs have a Length method to help you decide whether the mouse is out of range; if it is then you could use the Vector2.Normalize method to turn the offset into a unit vector, then multiply that by the max range, and add it back to the player's center.@bluemagic123 @JABofNeurospine
(code below)
I need your help over here. My weapon is getting there, but not just quite yet.
It shoots demon scythes where you point your cursor, which is really cool. But for now it is really OP. I want the range of where you can click to be decreased so you can't just use the weapon all over your screen. And on top of that, would it be possible to add a little internal cooldown before the demon scythes can be created again? (to prevent op spam?
Code:using System; using Microsoft.Xna.Framework; using Terraria; using Terraria.ModLoader; namespace Cyclogenesis.Items { public class Scythe : ModItem { public override void SetDefaults() { item.name = "Cyclogenesis Scythe"; item.damage = 100; item.magic = true; item.width = 60; item.height = 56; item.toolTip = "Shoots scythes, may deal inaccurate damage."; item.toolTip2 = "Increases damage the more armor you have."; item.useTime = 45; item.useAnimation = 45; item.useStyle = 1; item.knockBack = 2; item.value = 0; item.rare = 10; item.useSound = 1; item.autoReuse = true; item.mana = 14; item.useSound = 8; item.shoot = 45; item.shootSpeed = 1f; } public override void MeleeEffects(Player player, Rectangle hitbox) { int dust = Dust.NewDust(new Vector2((float)hitbox.X, (float)hitbox.Y), hitbox.Width, hitbox.Height, 27, player.velocity.X * 0.2f + (float)(player.direction * 3), player.velocity.Y * 0.2f, 100, default(Color), 1.75f); Main.dust[dust].noGravity = true; Main.dust[dust].velocity *= 1.66f; var FrontLightPos = new Vector2((float)player.position.X + 55, (float)player.position.Y); var BackLightPos = new Vector2((float)player.position.X - 55, (float)player.position.Y); Lighting.AddLight(FrontLightPos, 0.75f, 0f, 0f); Lighting.AddLight(BackLightPos, 0f, 0f, 0.75f); } 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 damageCalculation = (int)((item.damage * 0.8) / 2) * Main.rand.Next(3); int armorIncrement = (int)(player.statDefense * 1.33); float spread = 45f * 0.0174f; double startAngle = Math.Atan2(speedX, speedY)- spread/2; double deltaAngle = spread/8f; double offsetAngle; Vector2 pos = GetPos(player); for (int i = 0; i < 4; i++ ) { offsetAngle = (startAngle + deltaAngle * (i + i*i) / 2f) + 32f * i; Projectile.NewProjectile((int)(pos.X), (int)(pos.Y), (float)(Math.Sin(offsetAngle) * 2f), (float)(Math.Cos(offsetAngle) * 2f), 45, damageCalculation + armorIncrement, knockBack, item.owner); Projectile.NewProjectile((int)(pos.X), (int)(pos.Y), (float)(-Math.Sin(offsetAngle) * 2f), (float)(-Math.Cos(offsetAngle) * 3f), 45, damageCalculation + armorIncrement, knockBack, item.owner); //Projectile.NewProjectile(position.X, position.Y, (float)(Math.Sin(offsetAngle) * 5f), (float)(Math.Cos(offsetAngle) * 5f), 263, damage, knockBack, item.owner); //Projectile.NewProjectile(position.X, position.Y, (float)(-Math.Sin(offsetAngle) * 5f), (float)(-Math.Cos(offsetAngle) * 5f), 263, damage, knockBack, item.owner); } return false; } static float NextFloat(Random random) { double mantissa = (random.NextDouble() * 2.0) - 1.0; double exponent = Math.Pow(2.0, random.Next(-126, 128)); return (float)(mantissa * exponent); } public override void Update(ref float gravity, ref float maxFallSpeed) { Lighting.AddLight(item.position, 1f, 0.25f, 1f); } private Vector2 GetPos(Player player) { Vector2 position = Main.screenPosition; position.X += Main.mouseX; position.Y += player.gravDir == 1 ? Main.mouseY : Main.screenHeight - Main.mouseY; return position; } } }
For the range problem, first you could try calculating the offset between the mouse and the player as a Vector2. Vector2 structs have a Length method to help you decide whether the mouse is out of range; if it is then you could use the Vector2.Normalize method to turn the offset into a unit vector, then multiply that by the max range, and add it back to the player's center.
there is a reuseDelay field in the Item class
Does anyone know of a way to get chat messages when they are sent, in order to do things such as commands? I've looked around, can't seem to find it.
For the range problem, first you could try calculating the offset between the mouse and the player as a Vector2. Vector2 structs have a Length method to help you decide whether the mouse is out of range; if it is then you could use the Vector2.Normalize method to turn the offset into a unit vector, then multiply that by the max range, and add it back to the player's center.
private bool GetPlayerOffset(Player player)
{
Vector2 pos = GetPos(player);
Vector2 plr = player.position;
float diff = (pos - plr).Length();
if (diff < 500)
return true;
else
return false;
}
Yes, that gets whether or not it's in range. You'll want to keep the (pos - plr) Vector2 so you can adjust its length to be in range.Here's what I got out of your story XD
Code:private bool GetPlayerOffset(Player player) { Vector2 pos = GetPos(player); Vector2 plr = player.position; float diff = (pos - plr).Length(); if (diff < 500) return true; else return false; }
Yes, that gets whether or not it's in range. You'll want to keep the (pos - plr) Vector2 so you can adjust its length to be in range.
Where is it saying that?I tried but it says I cannot convert a float into vector2
The "Vector2 diff" part is supposed to be "float diff" like in your original code. (Maybe we should continue this in a private conversation )
No, I said that you need to save a Vector2 to use in order to get the shoot position into the range.I have that as a float, you told me to make it Vector 2.. right?
No, I said that you need to save a Vector2 to use in order to get the shoot position into the range.
public override void Update(ref float gravity, ref float maxFallSpeed)
{
float num = (float)Main.rand.Next(90, 111) * 0.01f;
num *= Main.essScale;
Lighting.AddLight((int)((item.position.X + (float)(item.width / 2)) / 16f), (int)((item.position.Y + (float)(item.height / 2)) / 16f), 0.5f * num, 0.3f * num, 0.05f * num);
}
public override void Update(ref float gravity, ref float maxFallSpeed)
{
float num = (float)Main.rand.Next(90, 111) * 0.01f;
num *= Main.essScale;
Lighting.AddLight((int)((item.position.X + (float)(item.width / 2)) / 16f), (int)((item.position.Y + (float)(item.height / 2)) / 16f), 0.1f * num, 0.5f * num, 0.2f * num);
}
For the first one, are you sure that either HuntersModItem is in the same namespace as your mod, or that your mod is using the namespace that contains HuntersModItem?I hate to be the clueless, but i cant figure out why when i use SetGlobalItem(new HuntersModItem()); i get an error and when i do anything to do with recipe.Addrecipe(); etc etc. in RecipeHelper i get another error. (dont know how else to upload the compile errors) thanks for helping.
There we go, progress. fixed the recipe errors, it was a simple spelling error. Now when i do using HuntersMod.Items it says the items type or namespace does not exist, where do i call/declare items, or am i going about this the wrong way. thank you again.For the first one, are you sure that either HuntersModItem is in the same namespace as your mod, or that your mod is using the namespace that contains HuntersModItem?
For the RecipeHelper errors, did you remember to declare a variable called recipe?