Coding Weapon Glow

Discussion in 'Released Mods' started by tregolani, Nov 11, 2012.

  1. tregolani Green Slime

    Hey guys!

    So, I'm new to the modding scene, and wanted to work on making a few weapons as practice. However....I am struggling at the moment to get the weapons to glow.

    I've been adding in Item Attributes (Lighted, light, Shine, Shine2) to the .ini files, but none of those seem to cause the weapon to emit a glow when used. I'd like to be able to reproduce both phaseblade-style glows (weapon color-based light, no particles) as well as particle glows (Hallowed weapons, Night's Edge, etc.)

    Could someone give me a quick rundown of how to code that into a weapon/armor set/projectile?

    Thanks!
  2. Surfpup Wandering Eye

    Yea, here's a quick example:
    Code:
    public void UseItemEffect(Player player, Rectangle rectangle) {
        Color color = new Color();
        //This is the same general effect done with the Fiery Greatsword
        int type=6;
        int alpha=100;
        float scale=1.9f;
        int dust = Dust.NewDust(new Vector2((float) rectangle.X, (float) rectangle.Y), rectangle.Width, rectangle.Height, type, (player.velocity.X * 0.2f) + (player.direction * 3), player.velocity.Y * 0.2f, alpha, color, scale);
        Main.dust[dust].noGravity = true;
        Main.dust[dust].noLight = true;
    }
    This goes into the .cs file corresponding to the weapon. For instance, if the weapon is called "Nightmare" the code goes into "Nightmare.cs". You can customize various aspects of this; the wiki is a good resource to look at.
  3. tregolani Green Slime

    Surfpup, do you think you could give me line-by-line comments for that code snippet so that I could understand what most of the code is actually saying?

    Also, would this code work for an armor glow and/or tile glow as well, or are those different?

    I saw the same thing over at the wiki before posting here, but didn't fully understand it, as I'm not really a code junkie...just a Terraria-enthusiast wanting to learn some simple modding skills.
  4. FatObeseBird Snatcher

    As far as i know i am not the best at C#, but i been doing this since tconfig for 1.0.6 terraria lol... ill give it a shot at explaining
    Code:
    public void UseItemEffect(Player player, Rectangle rectangle) { //method
        Color color = new Color();
        //This is the same general effect done with the Fiery Greatsword
        int type=6; //introduce variable type of dust refer to http://tconfig.wikia.com/wiki/List_of_Dusts
        int alpha=100; // introduce transparency variable
        float scale=1.9f; //introduce scale variable, original size of dust*scale = size in game
        int dust = Dust.NewDust(new Vector2((float) rectangle.X, (float) rectangle.Y), rectangle.Width, rectangle.Height, type, (player.velocity.X * 0.2f) + (player.direction * 3), player.velocity.Y * 0.2f, alpha, color, scale); //variable of dust using NewDust
    //Vector2 is X and Y axis, think graphing coordinates. the rectangle is the retangular hit box of your item, type is the
    //variable previously introduced. the velocity*direction is to make dust move with player a bit to look more natural.
    //alpha, color and scale are introduced variables above
        Main.dust[dust].noGravity = true; //changing the variable inside the dust class, makes it become not affected by gravity
        Main.dust[dust].noLight = true; //same as above but just another variable within the dust class
    }
    EDIT:wow, that was messy, guess i still suck at these things XD

Share This Page