Nova Solarius
Terrarian
Does tModLoader allow modders to alter the spawning conditions of vanilla creatures?
using System.IO;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.World.Generation;
using Microsoft.Xna.Framework;
using Terraria.GameContent.Generation;
namespace ModOfRandomness
{
public class ModWord : ModWorld
{
private const int saveVersion = 0;
public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
{
int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies"));
if (ShiniesIndex == -1)
{
return;
}
tasks.Insert(ShiniesIndex + 1, new PassLegacy("Custom Mod Ores", delegate (GenerationProgress progress)
{
progress.Message = "Custom Mod Ores";
//Put your custom tile block name
for (int k = 0; k < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-05); k++) // |
{ // |
WorldGen.TileRunner(WorldGen.genRand.Next(0, Main.maxTilesX), WorldGen.genRand.Next((int)WorldGen.worldSurfaceLow, Main.maxTilesY), (double)WorldGen.genRand.Next(3, 6), WorldGen.genRand.Next(2, 6), mod.TileType("NoobiteFossilBlock"), false, 0f, 0f, false, true);
}
}));
}
}
}
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace ModOfRandomness.Items.Placeable
{
public class NoobiteFossil : ModItem
{
public override void SetDefaults()
{
item.name = "Noobite Fossil";
item.width = 16;
item.height = 16;
item.maxStack = 999;
AddTooltip("The remains of an extinct race.");
item.useTurn = true;
item.autoReuse = true;
item.useAnimation = 15;
item.useTime = 10;
item.useStyle = 1;
item.consumable = true;
item.createTile = mod.TileType("NoobiteFossilBlock"); //put your CustomBlock Tile name
}
}
}
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ModLoader;
namespace ModOfRandomness.Tiles
{
public class NoobiteFossilBlock : ModTile
{
public override void SetDefaults()
{
Main.tileSolid[Type] = true;
Main.tileMergeDirt[Type] = true;
drop = mod.ItemType("NoobiteFossil"); //put your CustomBlock name
minPick = 60;
mineResist = 3f;
}
}
}
float num4 = 1f;
bool flag2 = false;
if (velocity.X != vector2_2.X)
{
velocity.X = vector2_2.X * -num4;
flag2 = true;
}
if (velocity.Y != vector2_2.Y || velocity.Y == 0.0)
{
velocity.Y = (float)(vector2_2.Y * -num4 * 0.5);
flag2 = true;
}
if (flag2)
{
float num5 = vector2_2.Length() / velocity.Length();
if (num5 == 0.0)
num5 = 1f;
Projectile projectile = this;
Vector2 vector2_3 = projectile.velocity / num5;
projectile.velocity = vector2_3;
if (ai[0] == 7.0 && velocity.Y < -0.1)
velocity.Y += 0.1f;
if (ai[0] >= 6.0 && ai[0] < 9.0)
Collision.HitTiles(position, vector2_2, width, height);
}
Snippet: 'How does the velocity system work?'
Guide: How to use and the uses of the Terraria.ID namespace
Terraria.ID is a really nice namespace that contains virtually all vanilla ID's for you to use. You need an item id? Sure! You need a projectile id? Sure! All you need to do is add the following to the top of your file:
Next, you can use all of these:Code:using Terraria.ID;
Code:AchievementHelperID AnimationID BuffID ChainID Colors DustID ExtrasID GlowMaskID GoreID InvasionID ItemID MessageID MountID NPCID PlayerTextureID PlayerVariantID ProjectileID SetFactory StatusID TileEntityID TileID WallID
For example, to get the ID of a Cutlass: (672)
Code:ItemID.Cutlass
To get the ID of a Demon Scythe projectile: (45)
Code:ProjectileID.DemonScythe
If you've set up your mod environment using an IDE, such as MVS, (you can use my tutorial) then IntelliSense will help you a lot like this:
View attachment 100565
IntelliSense will show you what you can access, as well as what it is and does etc.
public class BowPrism : ModItem
{
public override void SetDefaults()
{
item.name = "Prism Bow";
item.damage = 25;
item.ranged = true;
item.width = 16;
item.height = 32;
item.useTime = 20;
item.useAnimation = 20;
item.useStyle = 5;
item.noMelee = true;
item.knockBack = 1;
item.value = 3000;
item.UseSound = SoundID.Item5;
item.autoReuse = true;
item.shootSpeed = 10;
item.shoot = 1;
item.useAmmo = ProjectileID.WoodenArrowFriendly;
item.crit = 50;
}
public override void AddRecipes()
{
ModRecipe recipe = new ModRecipe(mod);
recipe.AddIngredient(ItemID.Ruby, 2);
recipe.AddIngredient(ItemID.Amber, 2);
recipe.AddIngredient(ItemID.Topaz, 2);
recipe.AddIngredient(ItemID.Emerald, 2);
recipe.AddIngredient(ItemID.Sapphire, 2);
recipe.AddIngredient(ItemID.Amethyst, 2);
recipe.AddIngredient(ItemID.Diamond, 2);
recipe.AddIngredient(ItemID.IronBar, 2);
recipe.AddTile(TileID.Anvils);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
You need to use AmmoID.ArrowI'm having a problem where my bow says it doesn't have any ammo. I've tried setting useAmmo to ProjectileID.WoodenArrowFriendly and to 1, but neither work. What am I doing wrong?
Here's my code.
Code:public class BowPrism : ModItem { public override void SetDefaults() { item.name = "Prism Bow"; item.damage = 25; item.ranged = true; item.width = 16; item.height = 32; item.useTime = 20; item.useAnimation = 20; item.useStyle = 5; item.noMelee = true; item.knockBack = 1; item.value = 3000; item.UseSound = SoundID.Item5; item.autoReuse = true; item.shootSpeed = 10; item.shoot = 1; item.useAmmo = ProjectileID.WoodenArrowFriendly; item.crit = 50; } public override void AddRecipes() { ModRecipe recipe = new ModRecipe(mod); recipe.AddIngredient(ItemID.Ruby, 2); recipe.AddIngredient(ItemID.Amber, 2); recipe.AddIngredient(ItemID.Topaz, 2); recipe.AddIngredient(ItemID.Emerald, 2); recipe.AddIngredient(ItemID.Sapphire, 2); recipe.AddIngredient(ItemID.Amethyst, 2); recipe.AddIngredient(ItemID.Diamond, 2); recipe.AddIngredient(ItemID.IronBar, 2); recipe.AddTile(TileID.Anvils); recipe.SetResult(this); recipe.AddRecipe(); } }
Thanks, I actually just figured it out by looking at Example Mod. I was already using it as an example, but I somehow just missed it the 20 times that I read it over, as I was also looking at an online guide.You need to use AmmoID.Arrow
Download the example mod, simple problems like these can be avoided by looking at the code of the example mod.
How might one go about making an NPC attempt to always stay above the player's location?
I learned the hard way not to set the ai style to 11.
float horMoveSpeed = 0.07f;
float vertMoveSpeed = 0.15f;
float maxMoveSpeed = 10f;
// Going up.
if (npc.Center.Y > Main.player[npc.target].Center.Y - 200)
{
if (npc.velocity.Y > 0)
npc.velocity.Y *= 0.8f;
npc.velocity.Y -= vertMoveSpeed;
if (npc.velocity.Y < -maxMoveSpeed)
npc.velocity.Y = -maxMoveSpeed;
}
// Going down.
if (npc.Center.Y < Main.player[npc.target].Center.Y - 200)
{
if (npc.velocity.Y < 0)
npc.velocity.Y *= 0.8f;
npc.velocity.Y += vertMoveSpeed;
if (npc.velocity.Y > maxMoveSpeed)
npc.velocity.Y = maxMoveSpeed;
}
// Going left.
if (npc.Center.X > Main.player[npc.target].Center.X + 200)
{
if (npc.velocity.X > 0)
npc.velocity.X *= 0.98f;
npc.velocity.X -= horMoveSpeed;
if (npc.velocity.X < -maxMoveSpeed)
npc.velocity.X = -maxMoveSpeed;
}
// Going right.
if (npc.Center.X < Main.player[npc.target].Center.X + 200)
{
if (npc.velocity.X < 0)
npc.velocity.X *= 0.98f;
npc.velocity.X += horMoveSpeed;
if (npc.velocity.X > maxMoveSpeed)
npc.velocity.X = maxMoveSpeed;
}
// When velocities are too low, set them to zero (prevents jittery movement).
if (npc.velocity.X > -0.05f && npc.velocity.X < 0.05f)
npc.velocity.X = 0;
if (npc.velocity.Y > -0.05f && npc.velocity.Y < 0.05f)
npc.velocity.Y = 0;
npc.position = Main.player[npc.target].position;
npc.position.y -= 200;
Hey! Pretty basic question, but how does one make dusts spawn from wings whilst flying?
I actually needed to know this. Do you know how to put the dust on an arrow trail?Hey I'm pretty sure I know this. I haven't messed around with wings, but I have with dust. This is from the ExamplePickaxe:
public override void MeleeEffects(Player player, Rectangle hitbox)
{
if (Main.rand.Next(10) == 0)
{
int dust = Dust.NewDust(new Vector2(hitbox.X, hitbox.Y), hitbox.Width, hitbox.Height, mod.DustType("DustNameHere"));
}
}
Hope I helped!
public override void AI ()
{
if (Main.rand.Next(1) == 0)
{
int dust = Dust.NewDust(projectile.position, projectile.width, projectile.height, mod.DustType("DustPrism"));
Main.dust[dust].velocity /= 1f;
}
}
You should probably use the OnHitPlayer or ModifyHitPlayer hook to do this, for items you'll probably use the HoldItem hook.How do you make the player get a custom debuff when hit by a projectile and when hit by an NPC?
And, if possible, how do I make it so the player gets the debuff just by holding an item?
You can do this by calling Dust.NewDust in the WingUpdate hook from ModItem.Hey! Pretty basic question, but how does one make dusts spawn from wings whilst flying?
As you said you're not very good at this yet, I'd recommend looking into other things first. What you're asking is possible, heck I even fancied around it, but it's rather difficult compared to a lot of other things. You'll be messing around with custom AI and drawing code.Hi im new to modding. I know how to make weapons/npcs (not very gud at it though lul)but does anyone know if it is possible to make a custom animation and use it on a custom weapon, like a spin on a sword or something fancy. If anyone knows plz teach me senpai
You should probably use the OnHitPlayer or ModifyHitPlayer hook to do this, for items you'll probably use the HoldItem hook.
You can do this by calling Dust.NewDust in the WingUpdate hook from ModItem.
As you said you're not very good at this yet, I'd recommend looking into other things first. What you're asking is possible, heck I even fancied around it, but it's rather difficult compared to a lot of other things. You'll be messing around with custom AI and drawing code.