tModLoader [Tutorial] Projectile Guide and Implementation: tModLoader Edition

Edit: So what you need to do first is:

projectile.cloneDefaults(496) //496 is the ai for the hex doll
aiType = 496;

That will give you a straight line.
From there, add random velocity changes in the AI() block.

Also, I believe there are easy ways to change the color of the projectile (Technically dust), but I'm not good with the animation and sprite drawing stuff.

Another edit: When you change the velocity, make sure you do it briefly and in small numbers, otherwise will go flying out of control.

I would also recommend using some math to base the velocity changes on the initial velocity.
 
Last edited:
1. How do I make a 'tornado' projectile? (Like Duke Fishron's sharknado, how it 'grows' in size, etc.)

2. How do I make a 'vilethorn'-like projectile?

3. How to make 'projectile1' shoot 'projectile2' outwards in an even arc every now and then (Like the Lunatic Cultist's Ice Attack)?
 
Last edited:
1. How do I make a 'tornado' projectile? (Like Duke Fishron's sharknado, how it 'grows' in size, etc.)

2. How do I make a 'vilethorn'-like projectile?

3. How to make 'projectile1' shoot 'projectile2' outwards in an even arc every now and then (Like the Lunatic Cultist's Ice Attack)?


1. I haven't used this myself, but I have seen it closely in the Calamity mod.
I think you need to A. Move the projectile left and right periodically.
B. Have the main projectile spawn new ones after a few frames each at an increasing interval of hieght
C. Increase the projectile.scale each time
This is one you would have to play around with to get it to look right.


2. Vilethorn-like projectiles (as well as the rainbow gun) actually use two projectiles: the front and the trail.
Basically, have the gun shoot the front projectile, and have it spawn stationary projectiles as it travels. (Make sure you adjust the rotation to match the front)
Then adjust things like scale and alpha of the trail to make it look right.


3. Once again, you need two projectiles.
The first will slowly travel, and as it does, it spawns multiple projectiles at once the fly at a specific velocity.
use this:
for (int i = 0; i < NumberOfProjectiles; i++)
{
Spawn projectile using a vector2 relative to the variable i.
}
Or spawn them all with different code to get more precise velocities of you can't find a good equation. (You might need trigonometry)
You can also set the velocity to a random integer.

P.S. how did the hex doll turn out?
 
P.S. how did the hex doll turn out?
I don't even think I'm doing it right. o______________o I don't have any experience with changing vanilla AIs (I probably put the code in an entirely wrong place). -_-
Code:
c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(29,28) : error CS1002: ; expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(30,3) : error CS1519: Invalid token 'if' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(30,20) : error CS1519: Invalid token '==' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(33,4) : error CS1519: Invalid token 'this' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(33,15) : error CS1519: Invalid token '=' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(33,35) : error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(33,37) : error CS1519: Invalid token ';' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(34,15) : error CS1519: Invalid token '=' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(34,21) : error CS1519: Invalid token ')' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(34,39) : error CS1519: Invalid token ')' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(35,16) : error CS1519: Invalid token '=' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(35,28) : error CS1519: Invalid token ';' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(36,20) : error CS1519: Invalid token '=' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(36,33) : error CS1519: Invalid token '-' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(36,41) : error CS1519: Invalid token ')' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(36,54) : error CS1519: Invalid token '/' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(37,20) : error CS1519: Invalid token '=' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(37,33) : error CS1519: Invalid token '-' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(37,41) : error CS1519: Invalid token ')' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(37,55) : error CS1519: Invalid token '/' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(38,15) : error CS1519: Invalid token ')' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(38,29) : error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(38,32) : error CS1519: Invalid token '<' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(40,17) : error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(40,20) : error CS1519: Invalid token '+=' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(43,4) : error CS0116: A namespace cannot directly contain members such as fields or methods

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(45,17) : error CS1001: Identifier expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(47,4) : error CS0116: A namespace cannot directly contain members such as fields or methods

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(47,21) : error CS1001: Identifier expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(52,48) : error CS1001: Identifier expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(53,48) : error CS1001: Identifier expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(59,12) : error CS1001: Identifier expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(60,12) : error CS1001: Identifier expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(66,36) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(67,23) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(67,53) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(68,23) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(69,35) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(71,30) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(73,23) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(74,30) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(78,5) : error CS1022: Type or namespace definition, or end-of-file expected
Code:
        public override void AI()
        if (this.aiStyle == 91)
        {
            Vector2 center10 = base.Center;
            this.scale = 1f - this.localAI[0];
            this.width = (int)(20f * this.scale);
            this.height = this.width;
            this.position.X = center10.X - (float)(this.width / 2);
            this.position.Y = center10.Y - (float)(this.height / 2);
            if ((double)this.localAI[0] < 0.1)
            {
            this.localAI[0] += 0.01f;
            }
           
            else
            {
            this.localAI[0] += 0.025f;
            }
            if (this.localAI[0] >= 0.95f)
            {
            this.Kill();
            }
           
            this.velocity.X = this.velocity.X + this.ai[0] * 1.5f;
            this.velocity.Y = this.velocity.Y + this.ai[1] * 1.5f;
            if (this.velocity.Length() > 16f)
                {
                this.velocity.Normalize();
                this.velocity *= 16f;
                }
            this.ai[0] *= 1.05f;
            this.ai[1] *= 1.05f;
            if (this.scale < 1f)
            {
                int num892 = 0;
                while ((float)num892 < this.scale * 10f)
                {
                    //Dust "6" (OnFire Orange Color) is used.
                    int num893 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, this.velocity.X, this.velocity.Y, 100, default(Color), 1.1f);
                    Main.dust[num893].position = (Main.dust[num893].position + base.Center) / 2f;
                    Main.dust[num893].noGravity = true;
                    Dust dust = Main.dust[num893];
                    dust.velocity *= 0.1f;
                    dust = Main.dust[num893];
                    dust.velocity -= this.velocity * (1.3f - this.scale);
                    Main.dust[num893].fadeIn = (float)(100 + this.owner);
                    dust = Main.dust[num893];
                    dust.scale += this.scale * 0.75f;
                    int num3 = num892;
                    num892 = num3 + 1;
                }
                return;
            }
        }
 
I don't even think I'm doing it right. o______________o I don't have any experience with changing vanilla AIs (I probably put the code in an entirely wrong place). -_-
Code:
c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(29,28) : error CS1002: ; expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(30,3) : error CS1519: Invalid token 'if' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(30,20) : error CS1519: Invalid token '==' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(33,4) : error CS1519: Invalid token 'this' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(33,15) : error CS1519: Invalid token '=' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(33,35) : error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(33,37) : error CS1519: Invalid token ';' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(34,15) : error CS1519: Invalid token '=' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(34,21) : error CS1519: Invalid token ')' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(34,39) : error CS1519: Invalid token ')' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(35,16) : error CS1519: Invalid token '=' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(35,28) : error CS1519: Invalid token ';' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(36,20) : error CS1519: Invalid token '=' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(36,33) : error CS1519: Invalid token '-' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(36,41) : error CS1519: Invalid token ')' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(36,54) : error CS1519: Invalid token '/' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(37,20) : error CS1519: Invalid token '=' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(37,33) : error CS1519: Invalid token '-' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(37,41) : error CS1519: Invalid token ')' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(37,55) : error CS1519: Invalid token '/' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(38,15) : error CS1519: Invalid token ')' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(38,29) : error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(38,32) : error CS1519: Invalid token '<' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(40,17) : error CS0270: Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(40,20) : error CS1519: Invalid token '+=' in class, struct, or interface member declaration

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(43,4) : error CS0116: A namespace cannot directly contain members such as fields or methods

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(45,17) : error CS1001: Identifier expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(47,4) : error CS0116: A namespace cannot directly contain members such as fields or methods

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(47,21) : error CS1001: Identifier expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(52,48) : error CS1001: Identifier expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(53,48) : error CS1001: Identifier expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(59,12) : error CS1001: Identifier expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(60,12) : error CS1001: Identifier expected

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(66,36) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(67,23) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(67,53) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(68,23) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(69,35) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(71,30) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(73,23) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(74,30) : error CS1518: Expected class, delegate, enum, interface, or struct

c:\Users\Joshua\Documents\My Games\Terraria\ModLoader\Mod Sources\JoshuasMod\Projectiles\BladesOfSolstice\SearingRageProj.cs(78,5) : error CS1022: Type or namespace definition, or end-of-file expected
Code:
        public override void AI()
        if (this.aiStyle == 91)
        {
            Vector2 center10 = base.Center;
            this.scale = 1f - this.localAI[0];
            this.width = (int)(20f * this.scale);
            this.height = this.width;
            this.position.X = center10.X - (float)(this.width / 2);
            this.position.Y = center10.Y - (float)(this.height / 2);
            if ((double)this.localAI[0] < 0.1)
            {
            this.localAI[0] += 0.01f;
            }
         
            else
            {
            this.localAI[0] += 0.025f;
            }
            if (this.localAI[0] >= 0.95f)
            {
            this.Kill();
            }
         
            this.velocity.X = this.velocity.X + this.ai[0] * 1.5f;
            this.velocity.Y = this.velocity.Y + this.ai[1] * 1.5f;
            if (this.velocity.Length() > 16f)
                {
                this.velocity.Normalize();
                this.velocity *= 16f;
                }
            this.ai[0] *= 1.05f;
            this.ai[1] *= 1.05f;
            if (this.scale < 1f)
            {
                int num892 = 0;
                while ((float)num892 < this.scale * 10f)
                {
                    //Dust "6" (OnFire Orange Color) is used.
                    int num893 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, this.velocity.X, this.velocity.Y, 100, default(Color), 1.1f);
                    Main.dust[num893].position = (Main.dust[num893].position + base.Center) / 2f;
                    Main.dust[num893].noGravity = true;
                    Dust dust = Main.dust[num893];
                    dust.velocity *= 0.1f;
                    dust = Main.dust[num893];
                    dust.velocity -= this.velocity * (1.3f - this.scale);
                    Main.dust[num893].fadeIn = (float)(100 + this.owner);
                    dust = Main.dust[num893];
                    dust.scale += this.scale * 0.75f;
                    int num3 = num892;
                    num892 = num3 + 1;
                }
                return;
            }
        }
Replace "this" with "projectile". Since you're copying from the projectile file, it uses this because the methods are in the cs file the projectile is in (in the vanilla code). However, since you're using a seperate .cs file, you need to call the projectile file instead of using this, and therefore need to replace all instances of "this." with "projectile."
 
When editing a projectile or npc AI, use later AI blocks, because otherwise it may already use it, and you mess up the natural properties of the AI.

Btw, there is a separate method for generating dust. If you are not using it, you should.

Try and minimize the complaints and I will look at the exact problem. (In particular, get rid of the careless mistakes like forgetting the ';'.

Also AI doesn't return a value. Look at the top of the method, if it says 'void,' don't return a value. If it says 'bool' return true, false, or a bool variable. And so on.
 
Last edited:
If i wanted to shoot two types of projectiles from a gun (bullet and an exploding thing like the onyx blaster or the vortex gun does it) how would i do that?
 
If i wanted to shoot two types of projectiles from a gun (bullet and an exploding thing like the onyx blaster or the vortex gun does it) how would i do that?
Add this:
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) //put this AFTER SetDefaults
        {
            Projectile.NewProjectile(position.X, position.Y, speedX, speedY, 668, damage, knockBack, player.whoAmI); //shoot an additional projectile, in this case 668 or Flameburst Fireball
            return true; //shoot the bullet afterwards
        }
 
How would I make a Star Wrath-style projectile that goes through blocks above it, then becomes solid when it gets close to its target? I can't find anything online and I don't seem to have a good enough computer to decompile the source code for reference...

EDIT: Never mind, I figured it out:
if (Math.Sqrt((Main.player[projectile.owner].Center.Y - projectile.Center.Y) * (Main.player[projectile.owner].Center.Y - projectile.Center.Y)) < 150)
{
projectile.tileCollide = true;
}
 
Last edited:
If Flying Piggy Bank is a projectile, doing right click open a chest (inventory).

How to do things happen when right click a projectile?
 
If Flying Piggy Bank is a projectile, doing right click open a chest (inventory).

How to do things happen when right click a projectile?
I don't believe there is a hook in ModProjectile, sorry.

ModProjectile.cs: https://github.com/blushiemagic/tMo...ModLoader/Terraria.ModLoader/ModProjectile.cs

You can hit CTRL+F to search keywords, but they don't come up, and I looked through it all, but it's just not there.

You could make a mount or tile that does what you want, but that's as far as you could go.
 
That's why I'm looking for, I already search in ModProjectile even in projectile from source code, but Flying Piggy projectile code don't show nothing about it.
The lack of a hook means it's quite literally impossible with a projectile. There is nothing in TModLoader that would allow you to do what you want. Sorry.

You weren't finding it because it's a hook in Terraria that would probably be hard to find without knowing exactly what you're looking for.

You can make a mod that changes source code, but that's not with TModLoader, and is vastly more difficult.
 
You can make a mod that changes source code, but that's not with TModLoader, and is vastly more difficult.

I got help, I will test it soon.
(Change npc to projectile)

IMG_201806167_122700.jpg


Thanks to Heather Shadelight

EDIT: Tested in SP, it works, you need using Terraria.GameInput;

@AwesomePerson159
 
Last edited:
Can someone help me with this strange problem I'm having? Basically, I am working on a mod, and I just added the 'Water Whip', a early game magic missile-like wand (mouse controlled projectiles). After polishing it up and fixing some errors, everything worked, except when I used it, it didn't shoot a projectile, instead giving me the following error in the chat: 'Index was outside the bounds of the array. at LootBoxes.Projectiles.WaterMissile.AI() (see logs.txt for full trace)'.
20180623161323_1.jpg

The code for the wand is:
Code:
usingSystem;
usingMicrosoft.Xna.Framework;
usingLootBoxes.Projectiles;
usingTerraria;
usingTerraria.ID;
usingTerraria.ModLoader;

namespaceLootBoxes.Items
{
publicclassWaterWhip : ModItem
{
publicoverridevoidSetStaticDefaults()
{
DisplayName.SetDefault("Water Whip");
Tooltip.SetDefault("Casts a controllable water blast");
}

publicoverridevoidSetDefaults()
{
item.damage=14;
item.magic=true;
item.mana=9;
item.width=40;
item.height=40;
item.useTime=20;
item.useAnimation=20;
item.useStyle=1;
item.noMelee=true;
item.knockBack=5;
item.value=10000;
item.rare=1;
item.UseSound=SoundID.Item21;
item.autoReuse=false;
item.shoot=mod.ProjectileType("WaterMissile");
item.shootSpeed=11f;
}

publicoverrideboolShoot(Player player, refVector2 position, reffloat speedX, reffloat speedY, refint type, refint damage, reffloat knockBack)
{
player.channel=true;
returntrue;
}

publicoverridevoidAddRecipes()
{
ModRecipe recipe =newModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
The code for the projectile is:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace LootBoxes.Projectiles
{
    public class WaterMissile : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.width = 16;
            projectile.height = 16;
            projectile.friendly = true;
            projectile.magic = true;
            projectile.penetrate = 2;
            projectile.timeLeft = -1;
        }

        public override void AI()
        {
            projectile.velocity.Y += projectile.ai[9];
            if (Main.rand.Next(3) == 0)
            {
                Dust.NewDust(projectile.position, projectile.width, projectile.height, 41, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f);
            }
        }

        public override bool OnTileCollide(Vector2 oldVelocity)
        {
            projectile.penetrate--;
            if (projectile.penetrate <= 0)
            {
                projectile.Kill();
            }
            else
            {
                projectile.ai[0] += 0.1f;
                if (projectile.velocity.X != oldVelocity.X)
                {
                    projectile.velocity.X = -oldVelocity.X;
                }
                if (projectile.velocity.Y != oldVelocity.Y)
                {
                    projectile.velocity.Y = -oldVelocity.Y;
                }
                projectile.velocity *= 0.75f;
                Main.PlaySound(SoundID.Item10, projectile.position);
            }
            return false;
        }

        public override void Kill(int timeLeft)
        {
            for (int k = 0; k < 5; k++)
            {
                Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 24, projectile.oldVelocity.X * 0.5f, projectile.oldVelocity.Y * 0.5f);
            }
            Main.PlaySound(SoundID.Item25, projectile.position);
        }

        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            projectile.ai[0] += 0.1f;
            projectile.velocity *= 0.75f;
        }
    }
}
If anyone could help me, that would be appreciated. Thx.
 

Attachments

  • 20180623161323_1.jpg
    20180623161323_1.jpg
    159.4 KB · Views: 475
Can someone help me with this strange problem I'm having? Basically, I am working on a mod, and I just added the 'Water Whip', a early game magic missile-like wand (mouse controlled projectiles). After polishing it up and fixing some errors, everything worked, except when I used it, it didn't shoot a projectile, instead giving me the following error in the chat: 'Index was outside the bounds of the array. at LootBoxes.Projectiles.WaterMissile.AI() (see logs.txt for full trace)'.
View attachment 203241
The code for the wand is:
Code:
usingSystem;
usingMicrosoft.Xna.Framework;
usingLootBoxes.Projectiles;
usingTerraria;
usingTerraria.ID;
usingTerraria.ModLoader;

namespaceLootBoxes.Items
{
publicclassWaterWhip : ModItem
{
publicoverridevoidSetStaticDefaults()
{
DisplayName.SetDefault("Water Whip");
Tooltip.SetDefault("Casts a controllable water blast");
}

publicoverridevoidSetDefaults()
{
item.damage=14;
item.magic=true;
item.mana=9;
item.width=40;
item.height=40;
item.useTime=20;
item.useAnimation=20;
item.useStyle=1;
item.noMelee=true;
item.knockBack=5;
item.value=10000;
item.rare=1;
item.UseSound=SoundID.Item21;
item.autoReuse=false;
item.shoot=mod.ProjectileType("WaterMissile");
item.shootSpeed=11f;
}

publicoverrideboolShoot(Player player, refVector2 position, reffloat speedX, reffloat speedY, refint type, refint damage, reffloat knockBack)
{
player.channel=true;
returntrue;
}

publicoverridevoidAddRecipes()
{
ModRecipe recipe =newModRecipe(mod);
recipe.AddIngredient(ItemID.DirtBlock);
recipe.SetResult(this);
recipe.AddRecipe();
}
}
}
The code for the projectile is:
Code:
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace LootBoxes.Projectiles
{
    public class WaterMissile : ModProjectile
    {
        public override void SetDefaults()
        {
            projectile.width = 16;
            projectile.height = 16;
            projectile.friendly = true;
            projectile.magic = true;
            projectile.penetrate = 2;
            projectile.timeLeft = -1;
        }

        public override void AI()
        {
            projectile.velocity.Y += projectile.ai[9];
            if (Main.rand.Next(3) == 0)
            {
                Dust.NewDust(projectile.position, projectile.width, projectile.height, 41, projectile.velocity.X * 0.5f, projectile.velocity.Y * 0.5f);
            }
        }

        public override bool OnTileCollide(Vector2 oldVelocity)
        {
            projectile.penetrate--;
            if (projectile.penetrate <= 0)
            {
                projectile.Kill();
            }
            else
            {
                projectile.ai[0] += 0.1f;
                if (projectile.velocity.X != oldVelocity.X)
                {
                    projectile.velocity.X = -oldVelocity.X;
                }
                if (projectile.velocity.Y != oldVelocity.Y)
                {
                    projectile.velocity.Y = -oldVelocity.Y;
                }
                projectile.velocity *= 0.75f;
                Main.PlaySound(SoundID.Item10, projectile.position);
            }
            return false;
        }

        public override void Kill(int timeLeft)
        {
            for (int k = 0; k < 5; k++)
            {
                Dust.NewDust(projectile.position + projectile.velocity, projectile.width, projectile.height, 24, projectile.oldVelocity.X * 0.5f, projectile.oldVelocity.Y * 0.5f);
            }
            Main.PlaySound(SoundID.Item25, projectile.position);
        }

        public override void OnHitNPC(NPC target, int damage, float knockback, bool crit)
        {
            projectile.ai[0] += 0.1f;
            projectile.velocity *= 0.75f;
        }
    }
}
If anyone could help me, that would be appreciated. Thx.


projectile.velocity.Y += projectile.ai[9];

Projectiles only have ai0 and ai1.
 
It no longer gives me an error on use, but it still doesn't shoot a projectile (or the projectile immediately despawns). It makes some dust, but no projectile that I can see.
[doublepost=1529809076,1529808946][/doublepost]Never mind I fixed it. Just a stupid error. Thanks for the help.
 
Hello everyone!

I'm new in modding so will try to be quite shortly. I had some problems with walkthroughts on expert hardcore due to explosions traps death. They got 3 full 400 hp chars one shotted without armor or items damage negotiations. So i looked for a mod that reduces their damage. But... there is no such a mod. I looked into source of vanilla projectiles and found that dmg of explosives is not just a rought number. It's calculated by some functions which i currently dont know how to change correctly.
So i decided to disable their influence on player (yep, quite lame decision, but idk what to do else).

Wrote some code and got this:

asdf.png


Code: MPT.cs
Code:
using System;
using Microsoft.Xna.Framework;

using Terraria;
using Terraria.ModLoader;

namespace MPT //Our mod folder name
{
public class MPT : Mod //Making our class of MPT extending Mod
{
public override void SetModInfo(out string name, ref ModProperties properties) //Setting up the mod
{
name = "MPT"; //Set it to the name of your namespace so all of your things can be read
properties.Autoload = true; //This loads all of your items and textures automatically
properties.AutoloadGores = true; //Automatically load gore images
properties.AutoloadSounds = true; //Automatically load custom sounds
}
}
}

Code: ExplosivesMod.cs
Code:
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Terraria;
using Terraria.ModLoader;
using Terraria.ID;

namespace MPT.Projectiles //We need this to basically indicate the folder where it is to be read from, so you the texture will load correctly

{

public class ExplosivesMod : ModProjectile
{
public override void SetDefaults()
{
projectile.CloneDefaults(ProjectileID.Explosives);
projectile.name = "ExplosivesModded";
projectile.hostile = false;
aiType = ProjectileID.Explosives;
}

public override bool Autoload(ref string name, ref string texture)
{
texture = "Terraria/Projectile_" + ProjectileID.Explosives;
return true;
}

}
}

What's wrong with
public override void SetModInfo(out string name, ref ModProperties properties) //Setting up the mod
line?
 
Last edited:
Just analyzed some examples from ExampleMod and have understood that creating a new projectile type is not only way to solve the problem. Also we need to make this type as new projectile behaviour for explosives. And this step as i read for a last few days is way harder. Because modes mostly adds new stuff and don't change vanilla items. Am I right?
And if so is there any way to make explosives traps no one shotting player?
 
Back
Top Bottom