npc.velocity.Y = 20f;
npc.velocity.X = 0f;
if (Math.Abs(npc.position.Y - player.position.Y) < 5) {
AI_RestTimer = 0;
AI_State = State_Charging;
}
I'm no expert, but I did something similar on a projectile with the Collision class. Give Collision.SolidCollision(vector2, int, int) your NPC's position, width and height and it will return a bool based on weather or not it's hitting something.Hi,
I'm on this thread to ask a question, how do you detect if an NPC is touching a block/on the ground? I'm currently making an enemy that only jumps if it is not in the air.
This code I'm using currently detects if the Y position of the NPC is near the Y position of the player. While the current method is efficient in stopping the enemy from continuously jumping in the air, it creates a whole new problem where if the player is a few blocks below or on top of the enemy, the NPC will freeze and never go into the "Charging" state. If you are willing to help, thank you.C#:npc.velocity.Y = 20f; npc.velocity.X = 0f; if (Math.Abs(npc.position.Y - player.position.Y) < 5) { AI_RestTimer = 0; AI_State = State_Charging; }
From what I saw, this is apparently a function/method, or a hook, right? If it is not a difficult task, how could I get a variable from one method and use it in another? And thanks for trying to help, I appreciate that.I'm no expert, but I did something similar on a projectile with the Collision class. Give Collision.SolidCollision(vector2, int, int) your NPC's position, width and height and it will return a bool based on weather or not it's hitting something.
Hope that works.
if (npc.wet) {
//insert code here
}
if (npc.wet) {
npc.velocity.Y -= 0.15; //gravity is -0.1, so this should counteract gravity
}
if (npc.wet) {
npc.velocity.Y = 0;
npc.position.Y -= 5;
}
using System;
using Terraria;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.ID;
using Terraria.ModLoader;
namespace MySword.Projectiles
{
public class ExProcyonBlast : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Ex Procyon Blast");
}
public override void SetDefaults()
{
projectile.width = 500;
projectile.height = 500;
projectile.scale = 1f;
projectile.timeLeft = 30;
projectile.penetrate = 10;
projectile.friendly = true;
projectile.magic = true;
projectile.tileCollide = false;
projectile.alpha = 55;
projectile.light = 1f;
projectile.aiStyle = 4;
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
target.AddBuff(mod.BuffType("OnFire!"), 180, false);
}
}
}
using Terraria;
using Microsoft.Xna.Framework;
using Terraria.ID;
using Terraria.ModLoader;
namespace MySword.Items
{
public class TrueLizaverde : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("True Lizaverde");
Tooltip.SetDefault("3000% Water DMG (Magic). Increases own CRI DMG by 30% for 8s. Water units get an extra 30%");
}
public override void SetDefaults()
{
item.melee = true;
item.damage = 250;
item.useStyle = 1;
item.useTime = 10;
item.useAnimation = 10;
item.knockBack = 5;
item.value = 30000;
item.rare = -12;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
item.width = 175;
item.height = 175;
item.scale = 0.35f;
item.mana = 10;
item.crit = 97;
item.shoot = mod.ProjectileType("FrostWaveLizaverde");
item.shootSpeed = 30f;
}
public override void HoldItem(Player player)
{
player.itemLocation.Y = player.Center.Y;
player.itemLocation.X = player.Center.X - 18 * player.direction;
}
public override void AddRecipes()
{
ModRecipe TrueLizaverderecipe = new ModRecipe(mod);
TrueLizaverderecipe.AddIngredient(173, 10);
TrueLizaverderecipe.AddIngredient(381, 10);
TrueLizaverderecipe.AddIngredient(19, 10);
TrueLizaverderecipe.AddIngredient(177, 1);
TrueLizaverderecipe.AddTile(17);
TrueLizaverderecipe.SetResult(this);
TrueLizaverderecipe.AddRecipe();
}
}
}
You would add inI'm having this problem where the projectile spawns like this, when in reality I want it to appear a little bit in front of the character for example like the Lazer from the Prism in which the lazer spawns in the prism itself?
View attachment 329442
I basically want it to look like this:
View attachment 329447
This is the code of the projectile:
C#:using System; using Terraria; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria.ID; using Terraria.ModLoader; namespace MySword.Projectiles { public class ExProcyonBlast : ModProjectile { public override void SetStaticDefaults() { DisplayName.SetDefault("Ex Procyon Blast"); } public override void SetDefaults() { projectile.width = 500; projectile.height = 500; projectile.scale = 1f; projectile.timeLeft = 30; projectile.penetrate = 10; projectile.friendly = true; projectile.magic = true; projectile.tileCollide = false; projectile.alpha = 55; projectile.light = 1f; projectile.aiStyle = 4; } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { target.AddBuff(mod.BuffType("OnFire!"), 180, false); } } }
I also have another question... can i make it so a melee weapon like a sword shoot a projectile that requires mana only when mana is availible?
Ima rephrase it just in case. Can i make a "sword" shoot projectiles when the mana needed is availible but when mana is not availible still be able to be swong/used.
This is the code of the "sword"
C#:using Terraria; using Microsoft.Xna.Framework; using Terraria.ID; using Terraria.ModLoader; namespace MySword.Items { public class TrueLizaverde : ModItem { public override void SetStaticDefaults() { DisplayName.SetDefault("True Lizaverde"); Tooltip.SetDefault("3000% Water DMG (Magic). Increases own CRI DMG by 30% for 8s. Water units get an extra 30%"); } public override void SetDefaults() { item.melee = true; item.damage = 250; item.useStyle = 1; item.useTime = 10; item.useAnimation = 10; item.knockBack = 5; item.value = 30000; item.rare = -12; item.UseSound = SoundID.Item1; item.autoReuse = true; item.width = 175; item.height = 175; item.scale = 0.35f; item.mana = 10; item.crit = 97; item.shoot = mod.ProjectileType("FrostWaveLizaverde"); item.shootSpeed = 30f; } public override void HoldItem(Player player) { player.itemLocation.Y = player.Center.Y; player.itemLocation.X = player.Center.X - 18 * player.direction; } public override void AddRecipes() { ModRecipe TrueLizaverderecipe = new ModRecipe(mod); TrueLizaverderecipe.AddIngredient(173, 10); TrueLizaverderecipe.AddIngredient(381, 10); TrueLizaverderecipe.AddIngredient(19, 10); TrueLizaverderecipe.AddIngredient(177, 1); TrueLizaverderecipe.AddTile(17); TrueLizaverderecipe.SetResult(this); TrueLizaverderecipe.AddRecipe(); } } }
Sword is like "sword" bcs its a scythe but i wanted to be as clear as posible so anyone who reads can uderstand.
View attachment 329445
that is the sprite in question.
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) {
Projectile.NewProjectile(position.x + velocity.x * multiplier, position.y + velocity.y * multiplier, speedX, speedY, type, damage, knockBack, player.whoAmI);
return false;
}
Collision.SolidCollision is a function. I don't know exactly what you mean by get a variable from one method and use it in another, but what I was suggesting you do is something like the following.From what I saw, this is apparently a function/method, or a hook, right? If it is not a difficult task, how could I get a variable from one method and use it in another? And thanks for trying to help, I appreciate that.
if (Collision.SolidCollision(npc.position, npc.width, npc.height))
{
//do the thing
}
idk wut i did to mess it up(im new to programming) but it didnt workYou would add in
.C#:public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { Projectile.NewProjectile(position.x + velocity.x * multiplier, position.y + velocity.y * multiplier, speedX, speedY, type, damage, knockBack, player.whoAmI); return false; }
What this does, is it overrides the vanilla projectile shooting AI (by calling "return false;" at the end) and makes a new AI, where it moves the projectile forwards by the velocity vector times a multiplier value (Which you can set to be whatever you want, just make sure they are both the same number)
using System;
using Terraria;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.ID;
using Terraria.ModLoader;
namespace MySword.Projectiles
{
public class ExProcyonBlast : ModProjectile
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Ex Procyon Blast");
}
public override void SetDefaults()
{
projectile.width = 500;
projectile.height = 500;
projectile.scale = 1f;
projectile.timeLeft = 30;
projectile.penetrate = 10;
projectile.friendly = true;
projectile.magic = true;
projectile.tileCollide = false;
projectile.alpha = 55;
projectile.light = 1f;
projectile.aiStyle = 4;
}
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
Projectile.NewProjectile(position.x + velocity.x * multiplier, position.y + velocity.y * multiplier, speedX, speedY, type, damage, knockBack, player.whoAmI);
return false;
}
public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
{
//The debuff inflicted is the modded debuff Ethereal Flames. 180 is the duration in frames: Terraria runs at 60 FPS, so that's 3 seconds (180/60=3). To change the modded debuff, change EtherealFlames to whatever the buff is called; to add a vanilla debuff, change mod.BuffType("EtherealFlames") to a number based on the terraria buff IDs. Some useful ones are 20 for poison, 24 for On Fire!, 39 for Cursed Flames, 69 for Ichor, and 70 for Venom.
target.AddBuff(mod.BuffType("OnFire!"), 180, false);
}
}
}
You put it in the weapon code, not the projectile code.idk wut i did to mess it up(im new to programming) but it didnt work
View attachment 329456
this is the code:
C#:using System; using Terraria; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria.ID; using Terraria.ModLoader; namespace MySword.Projectiles { public class ExProcyonBlast : ModProjectile { public override void SetStaticDefaults() { DisplayName.SetDefault("Ex Procyon Blast"); } public override void SetDefaults() { projectile.width = 500; projectile.height = 500; projectile.scale = 1f; projectile.timeLeft = 30; projectile.penetrate = 10; projectile.friendly = true; projectile.magic = true; projectile.tileCollide = false; projectile.alpha = 55; projectile.light = 1f; projectile.aiStyle = 4; } public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack) { Projectile.NewProjectile(position.x + velocity.x * multiplier, position.y + velocity.y * multiplier, speedX, speedY, type, damage, knockBack, player.whoAmI); return false; } public override void OnHitNPC(NPC target, int damage, float knockback, bool crit) { //The debuff inflicted is the modded debuff Ethereal Flames. 180 is the duration in frames: Terraria runs at 60 FPS, so that's 3 seconds (180/60=3). To change the modded debuff, change EtherealFlames to whatever the buff is called; to add a vanilla debuff, change mod.BuffType("EtherealFlames") to a number based on the terraria buff IDs. Some useful ones are 20 for poison, 24 for On Fire!, 39 for Cursed Flames, 69 for Ichor, and 70 for Venom. target.AddBuff(mod.BuffType("OnFire!"), 180, false); } } }
Now there is another problem after i added it to the weapon(i eliminated it from the projectile)You put it in the weapon code, not the projectile code.
Sorry, probably should have specified that
using System;
using Terraria;
using Microsoft.Xna.Framework;
using Terraria.ID;
using Terraria.ModLoader;
namespace MySword.Items
{
public class TrueFomalhautEx : ModItem
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("True Fomalhaut");
Tooltip.SetDefault("7200% Fire DMG (Magic). Increases own DMG by 50% for 2s.");
}
public override void SetDefaults()
{
item.buffType = 159;
item.buffTime = 120;
item.magic = true;
item.noMelee = true;
item.damage = 250;
item.useStyle = 5;
item.useTime = 5;
item.useAnimation = 5;
item.knockBack = 2;
item.value = 5000;
item.rare = -12;
item.UseSound = SoundID.Item1;
item.autoReuse = true;
item.width = 64;
item.height = 64;
item.mana = 15;
item.scale = 0.33f;
item.shoot = item.shoot = mod.ProjectileType("ExProcyonBlast");
item.shootSpeed = 1f;
}
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
Projectile.NewProjectile(position.x + velocity.x * multiplier, position.y + velocity.y * multiplier, speedX, speedY, type, damage, knockBack, player.whoAmI);
return false;
}
public override void AddRecipes()
{
ModRecipe TrueFomalhautExrecipe = new ModRecipe(mod);
TrueFomalhautExrecipe.AddIngredient(2, 1);
TrueFomalhautExrecipe.AddIngredient(29, 1);
TrueFomalhautExrecipe.AddIngredient(22, 10);
TrueFomalhautExrecipe.AddIngredient(65, 3);
TrueFomalhautExrecipe.AddIngredient(19, 5);
TrueFomalhautExrecipe.AddTile(17);
TrueFomalhautExrecipe.SetResult(this);
TrueFomalhautExrecipe.AddRecipe();
}
}
}[/CODE=csharp]