TheTinyDiamond
Official Terrarian
How can you make an NPC be able to be affected by a debuff? And can I make the debuff spawn a new NPC in place of the old one? (Like what if I want to make a debuff that 'zombifies' mobs?)
Files that if accessed could break things. Logs.I've been using that to see how other mods are doing compared to mine. Also, it lets me check my download count away from my home PC.
What really annoys me is this bit:
http://javid.ddns.net/tModLoader/private/
What is in it that is so private?
Start with:jopojelly
so far i can only use banners to make recipes show or not
how can i use like buffs on player
biome around player
or a item in the players inv
public class clyablock : ModRecipe
{
int GreenSlime = Item.NPCtoBanner(NPCID.GreenSlime);
public clyablock(Mod mod) : base(mod)
{
}
public override bool RecipeAvailable()
{
return NPC.killCount[GreenSlime] >= 10;
}
You mean files that if edited could break things.Files that if accessed could break things. Logs.
[/QUOTE]You mean files that if edited could break things.
Is it stuff like the online code behind the Mod Browser?
Also, my mod browser has been taking a long time to reload mods, much longer than usual, even though I recently got a better wifi connection for my PC. Just wondering if there was a problem causing that.
Files that if accessed could break things. Logs.
Start with:
Player player = Main.player[Main.myPlayer];
Followed by:
// has a buff?
if(player.HasBuff(BuffID.TwinEyesMinion) > -1){return true}
// in a Zone/Biome?
if(player.ZoneCorrupt){return true}
// Has a particular item?
if(player.HasItem(mod.ItemType("SpectreGun"))){return true}
You could do it on one line or 2, doesn't matter.so where do i put the line
Player player = Main.player[Main.myPlayer];
as the one in wisp looks like this
return Main.player[Main.myPlayer].HasItem(mod.ItemType("SpectreGun"));
You could do it on one line or 2, doesn't matter.
return Main.player[Main.myPlayer].HasItem(mod.ItemType("SpectreGun")));
or
Player player = Main.player[Main.myPlayer];
return player.HasItem(mod.ItemType("SpectreGun")));
Player player = Main.player[Main.myPlayer];so how can i use && with 2 of em when they look like this?
Player player = Main.player[Main.myPlayer];
if(player.HasBuff(BuffID.TwinEyesMinion) > -1){return true}
Player player = Main.player[Main.myPlayer];
if(player.ZoneCorrupt){return true}
Do you mean that you want to give it a max speed, or have it move at a consistent speed?
If you want to give it a max speed, look at this example which is an extension of an earlier example. Note, I'm still using the code that makes it follow the mouse.
If you simply want it to move at a fixed rate, the following will do, but the movement will be very abrupt.Code:int maxSpeed = 8; //best keep this below 16 public override void AI() { Vector2 acceleration = Vector2.Normalize(Main.MouseWorld - projectile.Center); //convert the distance from this projectile to the mouse to a unit-vector projectile.velocity += acceleration * 1.5f; //add one and a half of my acceleration to my velocity projectile.velocity *= 0.95f; //slow down slightly, i.e. apply drag if (projectile.velocity.Length() > maxSpeed)//if going too fast { projectile.velocity.Normalize();//normalise projectile.velocity *= maxSpeed;//and multiply by my max speed } projectile.rotation = projectile.velocity.ToRotation(); //calculate the direction that this projectile is going and rotate to face that way. }
Also, I think my findNearest function could be more efficient. Replace the first three 'if' statements inside the 'for' loop with the following:Code:int maxSpeed = 8; //best keep this below 16 public override void AI() { projectile.velocity = Vector2.Normalize(Main.MouseWorld - projectile.Center) * maxSpeed; //normalise the difference between my position and multiply by my desired speed. projectile.rotation = projectile.velocity.ToRotation(); //calculate the direction that this projectile is going and rotate to face that way. }
Code:if (!Terraria.Main.npc[i].CanBeChasedBy(projectile))//Don't target anything it shouldn't continue;
using System;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Microsoft.Xna.Framework;
namespace Pack.Projectiles
{
public class TS : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "Templite Spell";
projectile.width = 8;
projectile.height = 8;
projectile.friendly = true;
projectile.penetrate = 10;
projectile.aiStyle = 0;
projectile.magic = true;
projectile.tileCollide = true;
projectile.timeLeft = 60000;
projectile.light = 10f;
}
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++)
{
if (!Collision.CanHit(pos, 1, 1, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height))
continue;
if (!Terraria.Main.npc[i].CanBeChasedBy(projectile))
continue;
if (nearest == null)
nearest = Terraria.Main.npc[i];
else
{
oldDist = Vector2.Distance(pos, nearest.position);
newDist = Vector2.Distance(pos, Terraria.Main.npc[i].position);
if (newDist < oldDist)
nearest = Terraria.Main.npc[i];
}
}
return nearest;
}
int maxSpeed = 10;
public override void AI()
{
NPC nearest = this.FindNearest(projectile.Center);
Vector2 acceleration = Vector2.Zero;
projectile.velocity += acceleration * 1.5f;
projectile.velocity *= 0.95f;
if (projectile.velocity.Length() > maxSpeed)
{
projectile.velocity.Normalize();
projectile.velocity *= maxSpeed;
}
projectile.rotation = projectile.velocity.ToRotation();
}
}
}
I have, I have the animations there, arms, body and female.You haven't put the movement animation sprite for your chestplate.
[doublepost=1466754750,1466754576][/doublepost]Look at the ExampleMod, if you want to create a piece of armour you have to create additional .png with the animation (in this case the body)
Terraria has a built in craft group for iron or lead. Just do the following.How can I make an Item to be either crafted with an iron bar or a lead bar, like the craftinggroup method?
I don't want to add two recipes, and since crafting group method was removed, I am confused what to do.
public override void AddRecipeGroups()
{
//Add the silver ranked group
RecipeGroup group = new RecipeGroup(() => Lang.misc[37] + " Silver", new int[]
{
ItemID.SilverBar,
ItemID.TungstenBar
});
RecipeGroup.RegisterGroup("rankSilver", group); //creates a group called "rankSilver". Use recipe.AddRecipeGroup("rankSilver", 1); to use this group in a recipe
}
Well first, I found the problem that was causing the slow down. You need to swap the two if conditions inside the findNearest function so that your projectile isn't checking collision with all 200 non-existent NPC's in the world. And your projectile wasn't homing because you had removed the position of its target from the equation, so that it never knew where to home to. Also, you forgot to check if your 'nearest' NPC was null, which would cause the projectile to disappear. I've fixed your AI for you.I have a big problem now
the projectile just goes out a little distance and then stops until there is something to home in on.then it homes.
EDIT: Then it just sits there and never homes
Code:using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; using Microsoft.Xna.Framework; namespace Pack.Projectiles { public class TS : ModProjectile { public override void SetDefaults() { projectile.name = "Templite Spell"; projectile.width = 8; projectile.height = 8; projectile.friendly = true; projectile.penetrate = 10; projectile.aiStyle = 0; projectile.magic = true; projectile.tileCollide = true; projectile.timeLeft = 60000; projectile.light = 10f; } 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++) { if (!Collision.CanHit(pos, 1, 1, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height)) continue; if (!Terraria.Main.npc[i].CanBeChasedBy(projectile)) continue; if (nearest == null) nearest = Terraria.Main.npc[i]; else { oldDist = Vector2.Distance(pos, nearest.position); newDist = Vector2.Distance(pos, Terraria.Main.npc[i].position); if (newDist < oldDist) nearest = Terraria.Main.npc[i]; } } return nearest; } int maxSpeed = 10; public override void AI() { NPC nearest = this.FindNearest(projectile.Center); Vector2 acceleration = Vector2.Zero; projectile.velocity += acceleration * 1.5f; projectile.velocity *= 0.95f; if (projectile.velocity.Length() > maxSpeed) { projectile.velocity.Normalize(); projectile.velocity *= maxSpeed; } projectile.rotation = projectile.velocity.ToRotation(); } } }
where's the mistake in my code?
please help
public override void AI()
{
NPC nearest = this.FindNearest(projectile.Center);
Vector2 acceleration;
if (nearest != null) //this is really important
{
acceleration = (nearest.position - projectile.position);
} else
{
acceleration = Vector2.Zero; //maintain speed -- or whatever else you want to do here
}
projectile.velocity += acceleration * 1.5f;
projectile.velocity *= 0.99f;
if (projectile.velocity.Length() > maxSpeed)
{
projectile.velocity.Normalize();
projectile.velocity *= maxSpeed;
}
projectile.rotation = projectile.velocity.ToRotation();
}
public override void LoadCustomData(BinaryReader reader)
{
int loadVersion = reader.ReadInt32();
item.pick = reader.ReadInt32();
item.damage = reader.ReadInt32();
item.useTime = reader.ReadInt32();
}
Ok, thanks I got it to work now.Terraria has a built in craft group for iron or lead. Just do the following.
recipe1.AddRecipeGroup("IronBar", 3); //vanilla recipe group - adds 3
A custom craft group looks like the following.
Code:public override void AddRecipeGroups() { //Add the silver ranked group RecipeGroup group = new RecipeGroup(() => Lang.misc[37] + " Silver", new int[] { ItemID.SilverBar, ItemID.TungstenBar }); RecipeGroup.RegisterGroup("rankSilver", group); //creates a group called "rankSilver". Use recipe.AddRecipeGroup("rankSilver", 1); to use this group in a recipe }
Well first, I found the problem that was causing the slow down. You need to swap the two if conditions inside the findNearest function so that your projectile isn't checking collision with all 200 non-existent NPC's in the world. And your projectile wasn't homing because you had removed the position of its target from the equation, so that it never knew where to home to. Also, you forgot to check if your 'nearest' NPC was null, which would cause the projectile to disappear. I've fixed your AI for you.
Also, it looks like you've been removing my comments from the code. It's a good idea to leave those there so that the code is easier to interpret.Code:public override void AI() { NPC nearest = this.FindNearest(projectile.Center); Vector2 acceleration; if (nearest != null) //this is really important { acceleration = (nearest.position - projectile.position); } else { acceleration = Vector2.Zero; //maintain speed -- or whatever else you want to do here } projectile.velocity += acceleration * 1.5f; projectile.velocity *= 0.99f; if (projectile.velocity.Length() > maxSpeed) { projectile.velocity.Normalize(); projectile.velocity *= maxSpeed; } projectile.rotation = projectile.velocity.ToRotation(); }
In the class where is your block just add this line of code in the SetDefultsOk, thanks I got it to work now.
I was even able to make two custom crafting groups.
But how can I give a tile the Ability to work like a Mythril Anvil or an Adamantite Forge?
adjTiles = new int[] { TileID.Anvils };
Well first, I found the problem that was causing the slow down. You need to swap the two if conditions inside the findNearest function so that your projectile isn't checking collision with all 200 non-existent NPC's in the world. And your projectile wasn't homing because you had removed the position of its target from the equation, so that it never knew where to home to. Also, you forgot to check if your 'nearest' NPC was null, which would cause the projectile to disappear. I've fixed your AI for you.
Also, it looks like you've been removing my comments from the code. It's a good idea to leave those there so that the code is easier to interpret.Code:public override void AI() { NPC nearest = this.FindNearest(projectile.Center); Vector2 acceleration; if (nearest != null) //this is really important { acceleration = (nearest.position - projectile.position); } else { acceleration = Vector2.Zero; //maintain speed -- or whatever else you want to do here } projectile.velocity += acceleration * 1.5f; projectile.velocity *= 0.99f; if (projectile.velocity.Length() > maxSpeed) { projectile.velocity.Normalize(); projectile.velocity *= maxSpeed; } projectile.rotation = projectile.velocity.ToRotation(); }
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++)
{
if (!Collision.CanHit(pos, 1, 1, Main.npc[i].position, Main.npc[i].width, Main.npc[i].height))
continue;
if (!Terraria.Main.npc[i].CanBeChasedBy(projectile))
continue;
if (nearest == null)
nearest = Terraria.Main.npc[i];
else
{
oldDist = Vector2.Distance(pos, nearest.position);
newDist = Vector2.Distance(pos, Terraria.Main.npc[i].position);
if (newDist < oldDist)
nearest = Terraria.Main.npc[i];
}
}
return nearest;
}
int maxSpeed = 10;
public override void AI()
{
NPC nearest = this.FindNearest(projectile.Center);
Vector2 acceleration;
if (nearest != null) // extremely important
{
acceleration = (nearest.position - projectile.position);
} else
{
acceleration = Vector2.Zero; // maintain speed -- or whatever else you want to do here
}
projectile.velocity += acceleration * 1.5f;
projectile.velocity *= 0.95f;
if (projectile.velocity.Length() > maxSpeed)
{
projectile.velocity.Normalize();
projectile.velocity *= maxSpeed;
}
projectile.rotation = projectile.velocity.ToRotation();
}
public override void SetDefaults()
{
item.name = "Solarius";
item.damage = 75;
item.melee = true;
item.width = 48;
item.height = 48;
item.useTime = 1;
item.useAnimation = 1;
item.useStyle = 1;
item.noMelee = true;
item.knockBack = 2;
item.noUseGraphic = true;
item.channel = true;
item.value = 100000;
item.rare = 9;
item.useSound = 1;
item.autoReuse = true;
item.shoot = mod.ProjectileType("SolarisP");
item.shootSpeed = 20;
}
public class SolarisP : ModProjectile
{
public override void SetDefaults()
{
projectile.name = "Solarius";
projectile.width = 36;
projectile.height = 20;
projectile.friendly = true;
projectile.penetrate = -1;
projectile.aiStyle = 20;
projectile.melee = true;
projectile.tileCollide = false;
projectile.light = 2f;
}