Standalone [1.3] tModLoader - A Modding API

Allright, then we're going to try something completely different... Getting the direction from the rotation.
Try the following:
Code:
Vector2 dir = new Vector2((float)Math.Cos(projectile.rotation), (float)Math.Sin(projectile.rotation));
dir = Vector2.Normalize(dir) * 7;
And see what that gives...

P.S. This is untested, so there might be a small coding error.. somewhere(?).
Not sure I put the code in right:
Code:
Vector2 pos = projectile.Center;
Vector2 dir = new Vector2((float)Math.Cos(projectile.rotation), (float)Math.Sin(projectile.rotation));
dir = Vector2.Normalize(dir) * 7;
Projectile.NewProjectile(pos.X, pos.Y, dir.X, dir.Y, mod.ProjectileType("PowerBeamShot"), projectile.damage, projectile.knockBack, projectile.owner);

If I did, then I think the problem is the held projectile rotates constantly, probably as a result of this: P.rotation += 0.5f * P.direction;
And so what ends up happening is the direction the projectile shoots in depends on how long it takes the player to release it.
 
Not sure I put the code in right:
Code:
Vector2 pos = projectile.Center;
Vector2 dir = new Vector2((float)Math.Cos(projectile.rotation), (float)Math.Sin(projectile.rotation));
dir = Vector2.Normalize(dir) * 7;
Projectile.NewProjectile(pos.X, pos.Y, dir.X, dir.Y, mod.ProjectileType("PowerBeamShot"), projectile.damage, projectile.knockBack, projectile.owner);

If I did, then I think the problem is the held projectile rotates constantly, probably as a result of this: P.rotation += 0.5f * P.direction;
And so what ends up happening is the direction the projectile shoots in depends on how long it takes the player to release it.
Allright, may I ask why you do P.rotation += 0.5f * P.direction? This is the handle we're talking about, right? Do you want that to rotate over time..?
 
Allright, may I ask why you do P.rotation += 0.5f * P.direction? This is the handle we're talking about, right? Do you want that to rotate over time..?
Well, I guess I handled this a bit strangely. The way I did it was by making the weapon's holdStyle = 3, so when the player is idle, it is always there, facing straight forward, kinda like Samus's weapon. So I figured I didn't need the weapon to shoot a projectile that looks just like it, instead, it shoots a little ball from the tip of the weapon that rotates and (not yet implemented) grows in size as it charges up, just for visual impact.

I may have missed something important about handling it the way the CBC does.
 
I've found some functionality to do that, but I prefer the following the most (since it's simple and easy on the eyes):
Code:
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)
{
    Vector2 direction = new Vector2(speedX, speedY);
    direction.Normalize();
    position += direction * item.width;
    return true;
}
Just note that this takes the item.width to get the distance to the tip, you might want to hardcode this value (like 20 or 30, etc).


I'm sorry, but I do not own a MAC myself, so I'm afraid I can't help you there! :/
Thanks, I really appreciate your help!
 
You'll need to set 'projectile.timeLeft' based on the speed it travels with.
Could you maybe explain me how this speed parameters work?
In reality we have km/h or m/s (depends on where you live), and let say a projectile is shot in terraria, you could say (depends on shootspeed) it travels with 4blocks/s, but how do I determine, which speed my projectile has around 15 blocks away of the source where it was shot out?
 
Could you maybe explain me how this speed parameters work?
In reality we have km/h or m/s (depends on where you live), and let say a projectile is shot in terraria, you could say (depends on shootspeed) it travels with 4blocks/s, but how do I determine, which speed my projectile has around 15 blocks away of the source where it was shot out?
Well, we know that Terraria's tiles are 16x16, so for 15 tiles, your projectile will have to travel 240 pixels. The velocity of a projectile is applied to the position every second (if I read the code correctly, correct me if I'm wrong) which means that if your projectiles' velocity.X = 12, it'll take your projectile 1/3 of a second to travel that distance (240 / 12 = 20 = 1/3 of a second, since there are 60 ticks in a second). Taking this into account, you'll just have to set projectile.timeLeft to 20.
 
1. How to add the dropping fire particles to projectiles/dusts, like the flamethrower?
2. How to change the color of the light, instead of white, into orange like the flamethrower?
See gif

EDIT: Is there a hook for tile collide for dusts?
sdkqWSO.gif
 
Last edited:
What code I should add to a item to can be used after defeat moon lord?
You can use the following code for that:
Code:
public override bool CanUseItem(Player player)
{
    if (!NPC.downedMoonlord)
        return false;
}
This will do exactly what you want it to do.

1. How to add the dropping fire particles to projectiles/dusts, like the flamethrower?
2. How to change the color of the light, instead of white, into orange like the flamethrower?
See gif

EDIT: Is there a hook for tile collide for dusts?
sdkqWSO.gif
The only code I can find regarding the flamethrower and Dusts is the following:
Code:
if (num297 == 6 || Main.rand.Next(2) == 0)
                        {
                            for (int num298 = 0; num298 < 1; num298++)
                            {
                                int num299 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, num297, this.velocity.X * 0.2f, this.velocity.Y * 0.2f, 100, default(Color), 1f);
                                if (Main.rand.Next(3) != 0 || (num297 == 75 && Main.rand.Next(3) == 0))
                                {
                                    Main.dust[num299].noGravity = true;
                                    Main.dust[num299].scale *= 3f;
                                    Dust dust50 = Main.dust[num299];
                                    dust50.velocity.X = dust50.velocity.X * 2f;
                                    Dust dust51 = Main.dust[num299];
                                    dust51.velocity.Y = dust51.velocity.Y * 2f;
                                }
                                if (this.type == 188)
                                {
                                    Main.dust[num299].scale *= 1.25f;
                                }
                                else
                                {
                                    Main.dust[num299].scale *= 1.5f;
                                }
                                Dust dust52 = Main.dust[num299];
                                dust52.velocity.X = dust52.velocity.X * 1.2f;
                                Dust dust53 = Main.dust[num299];
                                dust53.velocity.Y = dust53.velocity.Y * 1.2f;
                                Main.dust[num299].scale *= num296;
                                if (num297 == 75)
                                {
                                    Main.dust[num299].velocity += this.velocity;
                                    if (!Main.dust[num299].noGravity)
                                    {
                                        Main.dust[num299].velocity *= 0.5f;
                                    }
                                }
                            }
                        }
You'll have to spit through that yourself, though. Note that 'num297 = 6' in this case.
As for your second question: Where are you applying the light? On your projectile or on your Dust?
 
I'd like to know how to do it on a projectile.
You'll want to do:
Code:
Lighting.AddLight((int)((projectile.position.X + (projectile.width / 2)) / 16f),
    (int)((projectile.position.Y + (projectile.height / 2)) / 16f), 1, 1, 1);
In an AI/Update function of your projectile. The '1, 1, 1' at the end represent the colors/intensity. If you want (for example) red, you'd do '1, 0, 0' for a VERY vibrant red. You could also do '0.5f, 0, 0' for a little bit less intense red.

Hope this makes sense/works for you ;)
 
Sorry to bother, but I get some silly questions to ask. I'm not familiar with programming. I wonder how tModloader can help me to increase the max hp of Terraria? And, although I downloaded and installed tModloader successfully, I yet don't know even how to add a block for myself:). Is there any tutorial available for noobs like me, or I just need to start from the basis of C#?
 
Is it possible to put Glowmasks? Or should I just use sprite draws to do so? Same with holograms/after images. :/
At the moment you need to use sprite draws for glowmasks. However, I've been thinking of adding some sort of glowmask system for items. I'll probably have it so that in the next update ModItems will have a Texture2D field that you can set.

What do you mean by holograms/after images?
 
Back
Top Bottom