tModLoader Official tModLoader Help Thread

After, you can go classic loop:

Code:
public override void FindFrame(int frameHeight)
{
int height =  51;  //(height of the sprite for me, rarely equals to hitbox)
npc.frameCounter --;
if(npc.frameCounter < 0){
npc.frameCounter=60;
npc.frame.Y = (npc.frame.Y+height) % height* 3; //3 or Main.npcFrameCount[npc.type]
npc.spriteDirection = npc.direction;
}
if(npc.velocity == Vector2.Zero) npc.frame.Y=height*2
}

After, i am not sure.
I see a thing, also, you need maybe add others things if your ninja have velocity == Vector2.Zero where always you take the 3th frame.
Sorry if i have mistake.
But when I do that, the ninja stays in 1 animation only now. Foot-up.
 
But when I do that, the ninja stays in 1 animation only now. Foot-up.
Hum, strange, can he do not move, he go frame n°3 and when he move, he walk normally...

I have fix thing and change also, normally, this thing is functionnal: Else, this is maybe you have forgot a thing in setdefault... or maybe a other guy for help me.
Code:
        public override void FindFrame(int frameHeight)
        {
            if (npc.velocity.X == 0) npc.frame.Y = frameHeight * 2;
            else
            {
npc.spriteDirection = npc.direction;
                npc.frameCounter--;
                if (npc.frameCounter < 0)
                {
                    npc.frameCounter = 30;

                    if(npc.frame.Y == 0 ) npc.frame.Y = frameHeight;
                    else npc.frame.Y = 0;
                  
                }
            }
        }
If npc do not move: frame n°3 else if move : he go frame n°1 then n°2 then loop. I have put npc.spritedirection when he move because i think, this is maybe less ugly.
 
Last edited:
public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
float spread = 45f * 0.0174f;
float baseSpeed = (float)Math.Sqrt(speedX * speedX + speedY * speedY);
double startAngle = Math.Atan2(speedX, speedY)- spread/2;
double deltaAngle = spread/8f;
double offsetAngle;
int i;
for (i = 0; i < 8;i++ )
{
offsetAngle = startAngle + deltaAngle * i;
Terraria.Projectile.NewProjectile(position.X, position.Y, baseSpeed*(float)Math.Sin(offsetAngle), baseSpeed*(float)Math.Cos(offsetAngle), item.shoot, damage, knockBack, item.owner);
}
return false;
}
How to make it shoot 2 things and not far from eachother?
[doublepost=1467309917,1467309895][/doublepost]3 things*
 
You want a Clockwork Assault Rifle ? So?

This is very simple, i link with my weapon:
Code:
            item.useTime = 3;
            item.useAnimation = 60;
            item.autoReuse = true;
useTime for distance between two shoots.
useAnimation , just for animation, you take useTime* cooldown (ths is 20 here for my weapon).
autoReuse = true, or false, but prefer true.

Then:
Code:
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
       
            if (time <= 3)  // Number of waves of shoot  (3, so 3 waves)
            {
                      // YOUR SHOOT
            }
            else if (time >= 20)    // "Cooldown"
            {
                time = 0;  // reset to 0
            }
            time++;
            return false;
        }

This is very simple ^^.


EDIT: You can put false for AutoReuse.
 
Last edited:
And wth is this error:
c:\Users\Rocket\Documents\My Games\Terraria\ModLoader\Mod Sources\TacticalMod\Items\HighVoltageArrow.cs(29,30) : error CS0115: 'TacticalMod.Items.HighVoltageArrow.AddRecipes()': no suitable method found to override
Code:
using Terraria;
using System;
using Terraria.ID;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Terraria.ModLoader;

namespace TacticalMod.Items.Weapons
{
  public class ElectroBolt : ModItem
  {

  public override void SetDefaults()
  {
  item.name = "Electro Bolt";
  item.damage = 41;
  item.noMelee = true;
  item.ranged = true;
  item.width = 24;
  item.height = 42;
  item.toolTip = "'How shocking!!'";
  item.useTime = 16;
  item.useAnimation = 16;
  item.useStyle = 5;
  item.shoot = 3;
  item.useAmmo = 1;
  item.knockBack = 1;
  item.value = 100000;
  item.rare = 6;
  item.useSound = 5;
  item.autoReuse = true;
  item.shootSpeed = 21f;

  }
  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, position.Y, speedX, speedY, mod.ProjectileType("HighVoltageArrow"), damage, knockBack, player.whoAmI, 0f, 0f); //This is spawning a projectile of type FrostburnArrow using the original stats
       return false;
  }
  public override void AddRecipes()
  {
  ModRecipe recipe = new ModRecipe(mod);
  recipe.AddIngredient(null, "IntegratedCircuit", 10);
       recipe.AddIngredient(ItemID.Wire, 25);
       recipe.AddTile(TileID.MythilAnvil);
  recipe.SetResult(this);
  recipe.AddRecipe();
  }
  }
}
 
And wth is this error:
c:\Users\Rocket\Documents\My Games\Terraria\ModLoader\Mod Sources\TacticalMod\Items\HighVoltageArrow.cs(29,30) : error CS0115: 'TacticalMod.Items.HighVoltageArrow.AddRecipes()': no suitable method found to override
Code:
using Terraria;
using System;
using Terraria.ID;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Terraria.ModLoader;

namespace TacticalMod.Items.Weapons
{
  public class ElectroBolt : ModItem
  {

  public override void SetDefaults()
  {
  item.name = "Electro Bolt";
  item.damage = 41;
  item.noMelee = true;
  item.ranged = true;
  item.width = 24;
  item.height = 42;
  item.toolTip = "'How shocking!!'";
  item.useTime = 16;
  item.useAnimation = 16;
  item.useStyle = 5;
  item.shoot = 3;
  item.useAmmo = 1;
  item.knockBack = 1;
  item.value = 100000;
  item.rare = 6;
  item.useSound = 5;
  item.autoReuse = true;
  item.shootSpeed = 21f;

  }
  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, position.Y, speedX, speedY, mod.ProjectileType("HighVoltageArrow"), damage, knockBack, player.whoAmI, 0f, 0f); //This is spawning a projectile of type FrostburnArrow using the original stats
       return false;
  }
  public override void AddRecipes()
  {
  ModRecipe recipe = new ModRecipe(mod);
  recipe.AddIngredient(null, "IntegratedCircuit", 10);
       recipe.AddIngredient(ItemID.Wire, 25);
       recipe.AddTile(TileID.MythilAnvil);
  recipe.SetResult(this);
  recipe.AddRecipe();
  }
  }
}

You're looking at the wrong class, your error is in HighVoltageArrow, not ElectroBolt.

Either way, you probably forgot to make HighVoltageArrow a child of ModItem.
 
I fixed that problem, thanks. Anyways can you please help me make my projectile inflict the vanilla debuff "Electrified" to enemies?
 
And I want to be able to spawn more than 1 type of modded ore, but I don't know how, here's my code:
Code:
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 TacticalMod
{
  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("Growing Sulfur", delegate (GenerationProgress progress)
  {
  progress.Message = "Growing Sulfur";
   
  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("Sulfur"), false, 0f, 0f, false, true);
  }
  }));
  }

  }
}
 
I fixed that problem, thanks. Anyways can you please help me make my projectile inflict the vanilla debuff "Electrified" to enemies?

For that, you go in your modplayer:
And add:
Code:
        public override void OnHitNPCWithProj(Projectile proj, NPC target, int damage, float knockback, bool crit){
            if(mod.ProjectileType("HighVoltageArrow") == proj.type) target.AddBuff(buffid, time, true);
        }
Like, this is a modded projectile, this is more simple ^^.

For your second problem, i have never create ore, so i cannot help. But:

Code:
public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)
{
int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies"));
if (ShiniesIndex == -1)
{

} else{
tasks.Insert(ShiniesIndex + 1, new PassLegacy("Growing Sulfur", delegate (GenerationProgress progress)
{
progress.Message = "Growing Sulfur";

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("Sulfur"), false, 0f, 0f, false, true);
}
}));
}
int ShiniesIndex2 = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies2"));
if (ShiniesIndex2 == -1)
{
return;
} 
tasks.Insert(ShiniesIndex2 + 1, new PassLegacy("Growing Sulfur2", delegate (GenerationProgress progress)
{
progress.Message = "Growing Sulfur2";

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("Sulfur2"), false, 0f, 0f, false, true);
}
}));

}

This thing is not functionnal?
 
just gives me this stupid error:


c:\Users\Rocket\Documents\My Games\Terraria\ModLoader\Mod Sources\TacticalMod\ModWorld.cs(47,2) : error CS1513: } expected

here's the code:
Code:
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 TacticalMod
{
  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)
{

} else{
tasks.Insert(ShiniesIndex + 1, new PassLegacy("Growing Sulfur", delegate (GenerationProgress progress)
{
progress.Message = "Growing Sulfur";

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("Sulfur"), false, 0f, 0f, false, true);
}
}));
}
int ShiniesIndex2 = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies2"));
if (ShiniesIndex2 == -1)
{
return;
}
tasks.Insert(ShiniesIndex2 + 1, new PassLegacy("Planting Lilakite", delegate (GenerationProgress progress)
{
progress.Message = "Planting Lilakite";

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("Lilakite"), false, 0f, 0f, false, true);
}
}));

}
 
If you just copy/paste my code, you have not see ? x) I have just give code for
public override void ModifyWorldGenTasks(List<GenPass> tasks, ref float totalWeight)

Not for your class/modworld ^^'


If you do not found, you know than you need close a { after open? You have not close many thing, here x)
 
You want a Clockwork Assault Rifle ? So?

This is very simple, i link with my weapon:
Code:
            item.useTime = 3;
            item.useAnimation = 60;
            item.autoReuse = true;
useTime for distance between two shoots.
useAnimation , just for animation, you take useTime* cooldown (ths is 20 here for my weapon).
autoReuse = true, or false, but prefer true.

Then:
Code:
public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
      
            if (time <= 3)  // Number of waves of shoot  (3, so 3 waves)
            {
                      // YOUR SHOOT
            }
            else if (time >= 20)    // "Cooldown"
            {
                time = 0;  // reset to 0
            }
            time++;
            return false;
        }

This is very simple ^^.


EDIT: You can put false for AutoReuse.
Just so you know, that can be done easier:
Code:
item.useTime = 5;
item.useAnimation = 20;
// So 20 / 5 = 4 = will shoot 4 times in 20 ticks.
item.reuseDelay = 20; // Will take 20 ticks after the animation has ended to be reused.
 
what is "modplayer" and I get the
no suitable method found to override error. please help

ExampleMod, dude. ExamplePlayer is the modplayer. (Without, you cannot have custom minion or buff add per a armor ^^')

After, if your projectile is a custom projectile, you can change in the projectile:
Example(never forgot for player versus player!):
Code:
        public override void ModifyHitNPC(NPC target, ref int damage, ref float knockback, ref bool crit)
        {
            if(Main.rand.Next(10) == 0) target.AddBuff(39, 120);
            base.ModifyHitNPC(target, ref damage, ref knockback, ref crit);
        }

        public override void ModifyHitPvp(Player target, ref int damage, ref bool crit)
        {
            if (Main.rand.Next(10) == 0) target.AddBuff(39, 120);
            base.ModifyHitPvp(target, ref damage, ref crit);
        }
 
Code:
using System;
using Terraria.ID;
using Terraria.ModLoader;

namespace Items_Extended.Items.Weapons
{
    public class GoldenEye : ModItem
    {
        public override void SetDefaults()
        {
            item.name = "Golden Eye"; 
            item.damage = 60; 
            item.ranged = true;  
            item.width = 44;    
            item.height = 14;  
            item.toolTip = "Fires Golden Coins.";  
            item.useTime = 8; 
            item.useAnimation = 8;
            item.useStyle = 5;   
            item.noMelee = true;
            item.knockBack = 10;
            item.value = 10000;
            item.rare = 7;
            item.useSound = 11;
            item.autoReuse = true;
            item.shoot = 10;
            item.shootSpeed = 10f;
            item.useAmmo = ProjectileID.GoldenCoin;
            item.Buff = BuffID.Spelunker;
            item.BuffTime = 60;
        }
       
        public override void AddRecipes() 
        {
            ModRecipe recipe = new ModRecipe(mod);
            recipe.AddIngredient(ItemID.GoldBar, 30);
            recipe.AddIngredient(ItemID.IllegalGunParts, 1);
            recipe.AddIngredient(ItemID.GoldenCoin, 1000);
            recipe.AddIngredient(ItemID.HallowedBar, 14);
            recipe.AddIngredient(null "Bronze Eye", 1);
            recipe.AddTile(TileID.Furnaces);  
            recipe.SetResult(this);
            recipe.AddRecipe();
       
        }
       
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
        {
            Vector2 perturbedSpeed = new Vector2(speedX, speedY).RotatedByRandom(MathHelper.ToRadians(30));
            speedX = perturbedSpeed.X;
            speedY = perturbedSpeed.Y;
            return true;
        }
    }
}

Please help! When I try to compile this code I get error cs0246 and says that 'Player' could not be found. I have looked over the code but can't seem to find anything wrong with it. Thank you for reading this.
 
Back
Top Bottom