tModLoader Need help at some Modding things

Lukas04

Official Terrarian
I have some Qeestions and i post theme here C:
it whould be nice if you make an Code Example for the Part where the Question is C:
Questions with an * are Currently important for me C:

Shuriken Effect *

How do i add an Dust Particle and an Sound if an Projectile Hits an Wall?
An Code Example for a Shuriken Like Effect whould be cool!

Dust Effect on Buff *

How do i make an Dust Effect if an Player/Enemie haves these Buff?
I mean like its at On Fire or Frostburn

Shoting More than One Bullet

I found these Code in an Video

Code:
public static Vector2[] randomSpread(float speedX, float speedY, int angle, int num)
  {
  var posArray = new Vector2[num];
  float spread = (float)(angle * 0.0174532925);
  float baseSpeed = (float)System.Math.Sqrt(speedX * speedX + speedY * speedY);
  double baseAngle = System.Math.Atan2(speedX, speedY);
  double randomAngle;
  for (int i = 0; i < num; ++i)
  {
  randomAngle = baseAngle + (Main.rand.NextFloat() - 0.5f) * spread;
  posArray[i] = new Vector2(baseSpeed * (float)System.Math.Sin(randomAngle), baseSpeed * (float)System.Math.Cos(randomAngle));
  }
  return (Vector2[])posArray;
  }

  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[] speeds = randomSpread(speedX, speedY, 8, 6);
  for (int i = 0; i < 5; ++i)
  {
  Projectile.NewProjectile(position.X, position.Y, speeds[i].X, speeds[i].Y, type, damage, knockBack, player.whoAmI);
  }
  return false;
  }

Is the Code for an Shotgun,i just want to know what on these Code changes the Amount of Projectile its shoots at one click

Shooting Different Projectile with 1 Weapon *


How do i make an Weapon shoting an Extra Projectile with an Chance?
Example:I have an Gun that shoots Normal Bullets,but haves an Chance to Shots an Star with an Chance

How do i Add an "On Hit" Effect to Armor Effects? *

I want to make as Set Bonus for an Armor,that Enemies Are getting Inflict with "Shadowflame" on Hit with an Sword or Projectile
But i Currently only know how to do these for Weapons and Projectiles,but not as Armor Set

How do i let Spawn an Mod ore in Caverns after An Boss is Killed?

How do i Spawn Ore in Caverns after an Enemie is killed? I know to Spawn it,but it Spawn then OVerall in the World,its Replacing Trees too!
An Example whould be nice Again




Thats Enough Things first
It whould be Nice if the Important Questions get Answered
 
Dust and sound should be placed in the projectile file under Kill() or OnTileCollide(). Here's an example:
Code:
        public override void Kill(int timeLeft)
        {
            for(int i=0; i<5; i++)
            {
                int dust = Dust.NewDust(projectile.position, projectile.width, projectile.height, 1);
            }
            Main.PlaySound(0, (int)projectile.position.X, (int)projectile.position.Y);
        }
To change the dust type, you'll want to change the last number in the NewDust() call. To change the sound, you change the first number in the PlaySound() call. I suggest looking at this page for more specific instructions and a list of types for each.

In the Update() hook in the buff file, you can add a Dust.NewDust() call just like in the previous example. You probably want to add a conditional to limit this so it doesn't get called every frame.

Vector2[] speeds = randomSpread(speedX, speedY, 8, 6); for (int i = 0; i < 5; ++i)
The only parts you need modify are in here. You'll need to change the last number in the randomSpread() call and the 5 in the for loop (i < 5).
 
I need the
How do i Add an "On Hit" Effect to Armor Effects? *
so if anyone knows it,it whould be cool to have a bit help :p
 
Last edited:
I need the
How do i Add an "On Hit" Effect to Armor Effects? *
so if anyone knows it,it whould be cool to have a bit help :p
For this one, you'll want to have the armor set bonus either give you a buff or set a boolean in your ModPlayer file. Then, in the same ModPlayer file, in the OnHitAnything() hook, use a conditional to check whether the player has the buff/the boolean you created is true, and if true, add the shadowflame debuff to the enemy. If you want to use a boolean in ModPlayer, be sure to set it to false in ResetEffects() so that it doesn't remain true even after the armor is taken off.

To get a variable with which you can check or set ModPlayer values outside of that file itself, you'll need to declare it this way:
Code:
ExamplePlayer modPlayer = (ExamplePlayer)player.GetModPlayer(mod, "ExamplePlayer");
Where ExamplePlayer should be replaced with the name of your ModPlayer file, and player refers to the Player you are editing variables for.
 
Back
Top Bottom